Skip to main content

Preface — The Marriage of Logic and Gradient Descent

📍 Where we are: At the door of Volume 4 — Neuro-Symbolic Integration. Volume 3 closed with a matched pair of failures: geometry ranks every unwritten fact but can guarantee nothing, and Volume 2's logic guarantees everything it says but cannot learn. This volume is where the two pillars stop trading and start composing: the same academic world, read a fourth time, as a place where a proof has a derivative.

Welcome back, one last time before the frontier. Volume 2 built a reasoner whose every answer is a theorem; Volume 3 built an embedding whose every answer is a rank. Each ended by measuring its own wound: the reasoner, asked about a fact nobody wrote down, says "not shown" and stops; the embedding, asked for a guarantee, has none to give, and nothing in its training even represents the constraint it is violating. Complementary failures are a design brief, and this volume executes it. Its single technical move, repeated in seven costumes, is to take the discrete machinery of Volumes 1 and 2 (truth values, conjunctions, proofs, model counts, rules, queries) and re-express each piece as something differentiable: a small change in a neural network's output must produce a small, computable change in the truth of a logical conclusion, so that gradient descent can flow through the logic itself.

The simple version

Imagine the librarian of Volume 2 and the bookseller of Volume 3 finally going into business together. She has the catalog: every card exact, every unknown a polite "not shown". He has the floor sense: no cards, but hand him anything and he will walk to the right shelf, probably. Their shop runs on contracts, and each part of this volume is one. Sometimes she writes the rules and he pays a fine whenever his shelving violates them (a loss for breaking logic). Sometimes he staffs a desk inside her library, reading smudged labels she cannot parse, while she does the filing (a neural predicate inside a prover). Sometimes they grade claims by degree instead of stamping true or false (fuzzy truth), and sometimes she prices every possible state of the shop at once (probability over worlds). The volume is the fine print: what each contract costs, what it guarantees, and how the fines are computed so that he can actually learn from them.

What this volume covers

Volume 4 is one continuous climb in seven parts, from redefining truth as a number to judging the whole enterprise. Each part answers one question:

PartThemeThe question it answers
I · Fuzzy and Many-Valued LogicK3 and Ł3; t-norms and t-conorms; softmin and gradientsWhat happens to logic when truth becomes a number in [0, 1], and what do its gradients look like?
II · Probabilistic Logic and Circuitsthe distribution semantics; weighted model counting; d-DNNF circuits; DeepProbLogHow do you put a correct probability on a derived fact, and how do you afford it?
III · Differentiable Frameworkssemantic loss; Scallop's provenance; Logic Tensor Networks; KLay and LobsterHow do the two paths industrialize into layers, engines, and GPU kernels?
IV · Differentiable Rule LearningNeural-LP and DRUM; NTP and CTP; RNNLogic and AnyBURLCan gradient descent discover the rules themselves, not just apply them?
V · Complex Logical Query Answeringthe computation DAG; GQE, Query2Box, BetaE; CQD, GNN-QE, QTO; LMPNN, ULTRACan an embedding answer a whole logical query, with quantifiers, conjunction, and negation?
VI · Natural-Language ReasoningRuleTaker and ProofWriter; Logic-LM and LINC; FOLIO, LogicBench, PrOntoQAWhen the logic arrives written in English, who should do the reasoning?
VII · The Verdictthe ledgerWhen does integration actually pay, and when is one pillar alone the honest choice?

Who this volume is for

This is written for a reader one notch past Volume 3, a senior ramping toward graduate work. It assumes the forward chainer and unification of Volume 1, the EL++ TBox and annotated facts of Volume 2, and the embeddings and filtered-ranking protocol of Volume 3, and it re-derives everything else. Nothing arrives as a black box. Every mechanism is implemented in the companion suite examples/integration/ in plain NumPy, every gradient is derived by hand on the page and in a comment above the exact line that computes it, and the optional oracle torch_check.py recomputes three of those hand-derived gradients with torch.autograd, agreeing to at worst 1.3e-15. The suite is sealed by validate.py, an acceptance harness whose 21 competency checks pass 21 of 21 on the committed code, and every number quoted in every chapter reproduces byte-identically with python3 <module>.py.

The thesis: two roads to a differentiable logic

Here is the conviction the volume turns on. There are exactly two principled ways to make logic differentiable, and they price the same product differently. The first road relaxes truth: let a formula be true to degree 0.73, replace ∧ and ∨ by continuous operations on degrees, and gradients appear everywhere, cheaply. The cost is distortion: the three classical t-norm families assign our two-step citation chain three different confidences (Gödel 0.80, product 0.72, Łukasiewicz 0.70) from the same inputs, and which is "right" is a modeling decision, not a theorem. The second road keeps truth crisp and puts probability over worlds: each uncertain fact becomes an independent coin, a query's probability is the total weight of the worlds that entail it, and the semantics is provably exact. The difference is not cosmetic: naively summing the probabilities of a query's two proofs gives 1.5750, not even a probability, where the distribution semantics returns the exact 0.8865. The cost here is computational: exact inference is weighted model counting, a #P-hard problem, and the escape is compilation, turning the query into a circuit once so that every later evaluation and gradient is a cheap feed-forward pass. Cheap-but-distorted against exact-but-expensive: every framework in this volume is a position on that one axis, and the volume will always tell you which.

The running example, read a fourth time

We keep the world down to the last fact and change only the lens. Volume 1's kb.py still holds the facts and the Horn rules, including the one this volume will wear out: grandAdvisor is advises composed with advises. Volume 2's ontology still holds the EL++ TBox and the per-edge confidences; Volume 3's kg.py still holds the 15/3 train/test split and the filtered-ranking judge. The fourth reading, fixed in distsem.py, promotes 11 of the 23 facts to independent probabilistic coins (advising and authorship records between 0.85 and 0.95, Volume 2's confidences on the two citation edges, one shaky affiliation at 0.55) while the other 12 stay certain. That single move changes the status of every number in the series: the 0.90 on advises(alice, bob) stops being an annotation carried alongside a proof and becomes a parameter, one you can differentiate a query's probability with respect to, and therefore one a neural network can learn to produce. The world has 2^11 = 2048 possible states; the volume's business is computing, compiling, and differentiating sums over them without ever enumerating them again.

A wide diagram in three bands over one shared academic world. On the left, the symbolic pillar from Volume 2: a small proof tree deriving grandAdvisor of alice and carol from two advises facts, drawn in indigo, with an EL++ TBox card and a stamp reading proved. On the right, the neural pillar from Volume 3: entities as labelled points in a coordinate plane with a translation arrow and a ranking scoreboard, drawn in cyan, with a stamp reading ranked. In the center, the integration machinery joining them: the same proof redrawn as an arithmetic circuit whose leaves carry coin probabilities 0.90 and 0.90 and whose root reads P equals 0.81, with violet gradient arrows flowing backward from the root through the circuit into a small neural network icon feeding one leaf, and a two-position dial above the circuit labelled fuzzy degree and probability over worlds. Beneath the three bands a seven-rung ladder climbs left to right through Part I Fuzzy and Many-Valued Logic, Part II Probabilistic Logic and Circuits, Part III Differentiable Frameworks, Part IV Differentiable Rule Learning, Part V Complex Logical Query Answering, Part VI Natural-Language Reasoning, and Part VII The Verdict, with a dashed arrow off the right edge handing the surviving questions to Volume 5. One academic world read a fourth time: Volume 2's proof and Volume 3's geometry meet in the middle as a circuit with probabilities on its leaves and gradients flowing backward through it, with the seven-part climb of the volume laid out beneath. Original diagram by the authors, created with AI assistance.

Truth as a number: fuzzy semantics and their gradients

Part I starts where the damage is smallest: keep the formulas, change the truth values. Three-valued logic (K3 and Ł3) is the gateway, and it already draws blood: of the seven classical tautologies our world exercises, Ł3 preserves four and K3 preserves none. The continuum [0, 1] follows, and the t-norm families (Gödel, product, Łukasiewicz) are the three lawful ways to say AND about degrees, each with its t-conorm and residuum. The part ends at the property this volume actually cares about, the gradient: Gödel's min passes gradient to exactly one conjunct and starves the rest (sparsity 0.980 at fifty conjuncts), Łukasiewicz truncates into dead zones where the gradient is exactly zero, product shrinks gradients multiplicatively, and softmin buys smoothness at the price of bias. Fuzzy logic is the cheap road, and Part I is its honest price list.

Probability done right: worlds, counting, circuits

Part II takes the exact road. The distribution semantics defines the probability of a query as a sum over all 2048 total choices of the coins, and inclusion-exclusion over shared proofs is what separates the exact 0.8865 from the naive 1.5750. Weighted model counting is then the single interface: one number, the weighted count of satisfying assignments, delivers marginals, conditionals, and most-probable states, and it is #P-hard in general. Knowledge compilation breaks through for the queries that matter: compile once into a d-DNNF circuit, then answer in 238 operations what brute force pays 1,048,576 assignments for. And because the circuit is arithmetic, it is differentiable, so the same structure that answers the query also carries the gradient semiring, which is how DeepProbLog trains a neural predicate inside a prover: on our world, a softmax classifier learns paper topics purely from the downstream truth of logical queries, reaching accuracy 1.00 without ever seeing a topic label directly.

The frameworks: industrializing both roads

Part III is where the two roads become infrastructure. Semantic loss turns a hard constraint into a training signal by asking, via weighted model counting, how probable the constraint is under the network's own output distribution; on our topic-tagging task it cuts exactly-one violations from 20 to 6 while raising accuracy. Scallop puts a provenance dial on Volume 2's unchanged Datalog fixpoint engine: max-prob for speed, top-k proofs for a tightening ladder (0.7650 → 0.9344, exact at six proofs), dual numbers for gradients. Logic Tensor Networks take the fuzzy road all the way: Real Logic grounds constants, functions, and predicates in tensors and trains by maximizing satisfaction (0.5295 → 0.9933 on our axioms). And KLay and Lobster answer the systems question, flattening circuits into the batched, GPU-native tensor operations that tensor_ops.py proves equal to the loop semantics bit for bit.

Rules learned by gradient

Part IV turns the dial from applying rules to discovering them. Neural-LP and DRUM make the rule itself a differentiable object, a weighted composition of relation matrices, and attention over compositions decodes our gold rule advises∘advises at confidence 0.9990. Neural theorem provers go further and differentiate unification: symbols match by embedding similarity, proofs become soft scores, and the trained prover decodes grandAdvisor ← advises∘advises while scoring the held-out edge above every corruption by a margin of 0.7678. The part closes with the symbolic baselines that keep the neural methods honest: AnyBURL-style mining recovers the gold rule with confidence exactly 2/3 by counting, and RNNLogic's EM loop concentrates its rule distribution from 0.009 to 0.876 on the same rule. When a gradient and a counter agree, you can start to trust both.

Queries with shape: the computation DAG

Part V scales the target from one missing edge (Volume 3's whole game) to a full logical query: "who is advised by someone alice advises, but not advised by carol?" Every such query is a computation DAG over projections, intersections, unions, and negations, and the suite fixes 14 query types and 36 concrete queries with a symbolic executor as ground truth. Volume 3's embedding lineage reappears under load: GQE's points, Query2Box's boxes, and BetaE's distributions each support a different slice of the operator menu, and the coverage table's dashes are theorems, not engineering gaps. Then the twist that reorganized the field: CQD and QTO answer queries training-free, by beam search or fixpoint optimization over a pretrained link predictor's fuzzy scores (MRR 0.8000 where naive traversal of the incomplete graph manages 0.1465), and ULTRA-style structural scorers drop entity vocabularies entirely, transferring zero-shot to an unseen hospital world at MRR 0.8333 against a 0.2198 random floor.

When the logic is written in English

Part VI moves the interface from triples to sentences. Soft reasoners (the RuleTaker and ProofWriter line) train a language model to emulate deduction over natural-language rules, and the suite's stand-in reproduces the finding that matters: near-perfect accuracy at trained proof depths (1.000, 0.966) collapsing to coin-flip 0.500 one and two hops deeper, beside a symbolic prover that holds 100% at every depth. Translate-then-prove (the Logic-LM and LINC pattern) splits the labor instead: parse the English into formal logic, hand the logic to a prover, abstain when parsing fails; on our generated corpus its accuracy on parsed inputs is exactly 1.0000, and self-repair lifts coverage from 0.8080 to 0.9293 without ever converting an abstention into an error. The benchmark chapter then builds the instruments that separate label accuracy from proof accuracy: our greedy reasoner wins labels (0.817) and loses proofs (0.167), the measured shape of being right for the wrong reason.

The verdict, promised in advance

Part VII weighs it all on one ledger. The gains are measured, not asserted: exact probabilities where sums of proofs lied, constraints enforced through training, rules recovered by gradient and confirmed by counting, queries answered fourteen types wide, English parsed into proofs that never bluff. The costs are measured too: t-norm distortion chosen rather than derived, #P complexity paid in compilation, dead gradients, depth cliffs. Integration pays exactly where its structure matches the problem's structure; the verdict chapter says so with numbers, then hands Volume 5 the questions that survive: trust, calibration, faithfulness, and scale.

Where this leads

The climb starts with the smallest possible change to Volume 1's logic: adding a third truth value. The first chapter, Many-Valued Logic: Beyond True and False, rebuilds propositional semantics with truth that can be unknown or partial, works the K3 and Ł3 truth tables entry by entry on the academic world, and measures the first casualty of the whole enterprise: which classical laws survive when truth stops being binary, and which quietly die on the way to becoming differentiable.