Intuition Why a whole page of examples?
The parent note told you the machinery : semantic loss, neural module networks, differentiable logic. But machinery only sticks when you crank it by hand across every case it can face — every sign of a constraint violation, the "everything is fine" degenerate case, the "logic blows up" limiting case, a real word problem, and one exam trap. This page is that crank. Work each with pencil first.
Before we compute anything, we must be sure every symbol is earned. Several live here.
μ (and why p ( ⋅ ) is the same thing)
A truth degree μ is just a number between 0 and 1 that says "how true is this statement?" — 0 means "definitely false", 1 means "definitely true", 0.7 means "probably true". It replaces the hard TRUE/FALSE of ordinary logic with a dimmer switch, so gradients can flow. Picture a light on a slider, not a light switch.
Notation link — read this once and never be confused again: in the classification examples we write p ( cat ) , p ( awake ) , etc. Every such probability is a truth degree : p ( cat ) ≡ μ cat . Both are the same [ 0 , 1 ] slider — p ( ⋅ ) is just the name we use when the number came out of a softmax/classifier, and μ is the name we use when it lives inside the logic engine. Wherever you see one, you may read the other.
A violation is a single non-negative number measuring how badly a logical rule is broken by the network's current guesses. 0 = rule respected. The bigger the number, the worse the break. It is the fuel the training loss burns to correct the network.
L data and the symbol ℓ
L data is the ordinary supervised loss — the number that measures how far the network's predictions f θ ( x i ) sit from the true labels y i on your training set. It comes straight from the parent note's L data = N 1 ∑ i ℓ ( f θ ( x i ) , y i ) .
What is ℓ ? ℓ ( prediction , label ) is the per-example mismatch score — one number per training sample saying "how wrong was this single guess?" For classification it is usually cross-entropy (big when the network is confidently wrong), for regression usually mean squared error ( pred − label ) 2 . L data just averages ℓ over all N examples.
On this page we never recompute L data ; we only add a symbolic penalty to it, forming
L total = L data + L symbolic .
Think of L data as "fit the examples" and L symbolic as "obey the rules"; training minimises their sum.
Now the machine. A handful of continuous operators do all the work; we define them on the light-slider μ .
Every worked example below is tagged with the matrix cell it fills. The matrix is organised by the sign / magnitude of the violation the rule produces, plus the special inputs a logic engine can hit.
Cell
What makes it special
Where it bites
Example
A Violation > 0
rule broken, gradient nonzero
constraint pushes network
Ex 1
B Violation = 0 (satisfied)
floor active, gradient dies
why training goes quiet
Ex 2
C Violation = 0 (over-satisfied)
b > a , floor masks the slack
subtle no-op case
Ex 2
D Chained soft-AND, many terms
products shrink toward 0
vanishing-confidence trap
Ex 3
E Mutual-exclusivity (two-sided)
both classes fight for mass
one-hot enforcement
Ex 4
F Degenerate fact μ = 0
premise unknown/false
inference produces nothing
Ex 5
G Certain fact μ = 1
premise fully true
rule fires cleanly
Ex 5
H Fixed-point / limiting behaviour
forward chaining converges
when to stop iterating
Ex 6
I Real-world word problem
end-to-end pipeline
loan-approval story
Ex 7
J Exam twist
sign trap + weighting λ
the "gotcha"
Ex 8
Prerequisites this page leans on: 6.1.03-Neural-Network-Architectures (what f θ and backprop are), 6.2.04-Knowledge-Graphs (predicates like parent ( X , Y ) ), and 6.4.02-Explainable-AI (why interpretable outputs matter). Related frontiers: 6.5.10-Causal-Inference , 6.5.01-Few-Shot-Learning .
Worked example Ex 1 — Cell A: a live violation (positive penalty)
Statement. A chest-X-ray network outputs p ( pneumonia L ) = 0.80 and p ( opacity L ) = 0.30 (recall p ≡ μ ). The anatomical rule is "pneumonia in the left lung ⇒ high left-lung opacity". Constraint weight λ = 2.0 . Find the symbolic penalty added to the loss, and say which way each probability is pushed.
Forecast: guess — is the penalty positive or zero? Which number moves down, which moves up?
Identify a and b . Here a = p ( pneumonia L ) = 0.80 (the "if" part), b = p ( opacity L ) = 0.30 (the "then" part).
Why this step? Implication violation is always measured as (premise) minus (conclusion); we must name which is which before subtracting.
Compute raw gap. a − b = 0.80 − 0.30 = 0.50 .
Why this step? The gap is how much the "if" outruns the "then" — the raw evidence of a broken rule.
Apply the floor [ ⋅ ] + . violation = [ 0.50 ] + = 0.50 . Positive, so we are in Cell A .
Why this step? The floor lets us skip penalising already-obeyed rules; here it does nothing because the gap is positive.
Weight and add. L symbolic = λ ⋅ 0.50 = 2.0 × 0.50 = 1.00 , so L total = L data + 1.00 .
Why this step? λ says how loudly this rule shouts versus the raw data fit.
Read the gradient direction. In Cell A the whole symbolic penalty is L symbolic = λ [ a − b ] + = λ ( a − b ) (because a > b , the floor is inactive). Differentiating that expression: ∂ L symbolic / ∂ a = + λ = + 2 (push a down ) and ∂ L symbolic / ∂ b = − λ = − 2 (push b up ). The factor λ = 2 comes from the weight , not from the subtraction.
Why this step? Backprop moves parameters opposite the gradient, so pneumonia-confidence falls and opacity-confidence rises until they agree; naming λ explicitly shows why the slope is ± λ and not ± 1 .
Verify: units — probabilities are dimensionless, so the penalty is a pure number, addable to L data . Sanity: if the network later reports p ( opacity L ) = 0.85 ≥ 0.80 , gap becomes negative, floor fires, penalty → 0 — exactly Cell B/C below.
The figure above shows Ex 1 geometrically: the two sliders a (pneumonia) and b (opacity) on a bar. The blue gap between them is the violation; the arrows show backprop pulling a down and b up until the bars meet and the gap closes.
Worked example Ex 2 — Cells B & C: satisfied and over-satisfied (penalty
= 0 , dead gradient)
Statement. Same rule as Ex 1. Case (i): a = 0.40 , b = 0.40 . Case (ii): a = 0.30 , b = 0.90 . Compute the violation in each and explain what the gradient does.
Forecast: both give penalty 0 — but are they the same kind of zero?
Case (i) gap. a − b = 0.40 − 0.40 = 0.00 ; [ 0 ] + = 0 . This is Cell B — exactly satisfied, sitting on the boundary.
Why this step? The rule is just barely obeyed; we want to see whether training still pushes here.
Case (ii) gap. a − b = 0.30 − 0.90 = − 0.60 ; [ − 0.60 ] + = 0 . This is Cell C — over-satisfied (b far exceeds a ).
Why this step? The conclusion is more true than the premise demands; logically fine, so no penalty.
Gradient in both. For any point with a < b (Cell C) or a = b from below, the derivative of [ a − b ] + w.r.t. both a , b is 0 .
Why this step? A zero gradient means the symbolic loss is silent here — the network is only shaped by L data .
Interpret the danger. In Cell C the floor masks a large slack (0.60 ). If your data later drifts and pushes a up past b , the rule can silently break — you only notice when it re-enters Cell A.
Why this step? This is the practical reason to log violations, not just the loss.
Verify: plug back. Cell B: λ ⋅ 0 = 0 added, L total = L data . Cell C: same. Both correct — the two zeros are numerically equal but Cell C hides a 0.60 buffer.
The figure above is the whole story of Cells A–C: the floor [ a − b ] + against the gap a − b . Look at the pink flat floor on the left — that is where Cells B and C live (gradient dead). The blue rising ramp on the right is Cell A (gradient = 1 before weighting, rule actively corrected). The kink at 0 is where a rule flips from "shouting" to "silent".
Worked example Ex 3 — Cell D: chained soft-AND, confidence shrinks
Statement. A rule needs three premises all true: μ P = 0.9 , μ Q = 0.8 , μ R = 0.7 . Using soft-AND (product), what is the joint truth degree? Then compare to hard-AND (min ).
Forecast: will the product be near the smallest input (0.7 ) or noticeably below it?
Multiply the sliders. 0.9 × 0.8 × 0.7 = 0.504 .
Why this step? Soft-AND is repeated multiplication; three factors below 1 compound.
Compare hard-AND. min ( 0.9 , 0.8 , 0.7 ) = 0.70 .
Why this step? The classical operator only tracks the weakest link; the product punishes every uncertainty.
Read the gap. 0.70 − 0.504 = 0.196 — the product is ≈ 0.2 lower.
Why this step? This is the "vanishing confidence" trap: chain 10 premises of 0.9 each and you get 0. 9 10 ≈ 0.349 , so a long rule looks nearly false even when each part is strong.
Why the product anyway? It is smooth everywhere, so gradients flow to all premises, whereas min only passes gradient to the single smallest term.
Why this step? Trainability beats calibration here; practitioners rescale or use temperature to fight the shrink.
Verify: 0.9 ⋅ 0.8 = 0.72 ; 0.72 ⋅ 0.7 = 0.504 ✓. And 0. 9 10 = 0.34867844 … ✓ (checked in VERIFY).
The figure above plots how fast 0. 9 k decays as the chain length k grows: even strong-but-uncertain premises collapse toward 0 , contrasted with the flat min line that ignores chain length.
Worked example Ex 4 — Cell E: two-sided mutual exclusivity
Statement. A sleep monitor must never call someone both "awake" and "asleep". Network gives p ( awake ) = 0.7 , p ( asleep ) = 0.6 . The rule "exactly one of two exclusive classes" gives violation [ p ( c 1 ) + p ( c 2 ) − 1 ] + . Compute it, and the corrected minimal-move probabilities.
Forecast: the two probabilities sum to 1.3 > 1 — how much mass is illegal?
Sum the mass. 0.7 + 0.6 = 1.3 .
Why this step? Mutually exclusive true probabilities can sum to at most 1 ; the excess is the contradiction.
Violation. [ 1.3 − 1 ] + = 0.30 . Nonzero — active Cell E.
Why this step? This is a two-sided push: gradient + 1 on both classes, so both get pulled down.
State the optimisation criterion, then correct. We seek the least-norm fix: the smallest change ( δ 1 , δ 2 ) (minimising δ 1 2 + δ 2 2 ) that restores p 1 + p 2 ≤ 1 . Minimising a sum of squares subject to δ 1 + δ 2 = 0.30 has its solution at δ 1 = δ 2 = 0.15 (equal split), so each probability drops 0.15 → p ( awake ) = 0.55 , p ( asleep ) = 0.45 , sum = 1.00 .
Why this step? "Split evenly" is not arbitrary — it is exactly what minimising the squared adjustment forces, since the constraint is symmetric in both variables. That is also why the raw gradient (equal + 1 on both) points that way.
Contrast with Ex 1. Implication (Ex 1) is one-sided (down on a , up on b ); exclusivity is two-sided (down on both). Same floor [ ⋅ ] + , opposite geometry.
Why this step? Recognising the direction pattern is the exam-relevant skill.
Verify: 0.55 + 0.45 = 1.00 ✓, violation now [ 0 ] + = 0 ✓ (Cell B reached). Least-norm check: 0.1 5 2 + 0.1 5 2 = 0.045 is smaller than any unequal split summing to 0.30 (e.g. 0.3 0 2 + 0 = 0.09 ) ✓.
The figure above shows the two stacked probability bars overshooting the 1.0 ceiling by 0.30 (pink excess), then the equal 0.15 trims that bring the stack exactly to the line.
Worked example Ex 5 — Cells F & G: degenerate facts
μ = 0 and μ = 1
Statement. Rule: parent ( X , Y ) ∧ parent ( Y , Z ) ⇒ grandparent ( X , Z ) . Facts: μ parent(Alice,Bob) = 1.0 , μ parent(Bob,Cara) = 1.0 , but μ parent(Bob,Dan) = 0.0 (unknown/false). Derive μ grandparent(Alice,Cara) and μ grandparent(Alice,Dan) . Use the merge operator ∨ (the OR-aggregator defined above) to fold a newly derived degree into the current fact base.
Forecast: one grandparent link should fire fully, the other should stay dead — which is which?
Cara path (Cell G). Soft-AND: 1.0 × 1.0 = 1.0 .
Why this step? Both premises certain → product certain; the rule fires cleanly.
Merge into the fact base. The prior belief was μ grandparent(Alice,Cara) ( 0 ) = 0 ; merge with the new evidence: 0 ∨ 1.0 = 1.0 .
Why this step? This is the merge ∨ (best evidence so far), not the floor [ ⋅ ] + — both arguments are truth degrees, and it promotes the fact from "unknown" to "true".
Dan path (Cell F). Soft-AND: 1.0 × 0.0 = 0.0 .
Why this step? A single μ = 0 premise annihilates the product — "both must hold" fails when one is unknown.
Merge into the fact base. 0 ∨ 0.0 = 0.0 — nothing is inferred.
Why this step? The merge keeps the strongest evidence, which is still 0 ; degenerate zero input correctly produces zero output, no phantom knowledge.
Verify: 1 ⋅ 1 = 1 ✓, 1 ⋅ 0 = 0 ✓. Multiplication by 0 is the differentiable analogue of "false AND anything = false", exactly matching hard logic. Merge with prior 0 leaves each result unchanged, as expected.
Worked example Ex 6 — Cell H: forward chaining to a fixed point (limiting behaviour)
Statement. Rule: parent ( X , Y ) ⇒ ancestor ( X , Y ) and parent ( X , Y ) ∧ ancestor ( Y , Z ) ⇒ ancestor ( X , Z ) . Facts: parent(A,B) = 1 , parent(B,C) = 1 . At every round we merge (∨ ) newly derived degrees into the fact base. Iterate until no fact changes; how many rounds?
Forecast: guess the number of iterations before the fact set stops growing.
Round 0. Only the two parent facts, all ancestor degrees 0 .
Why this step? Establish the initial fixed-point candidate.
Round 1. Base rule: ancestor(A,B) = 0 ∨ 1 = 1 , ancestor(B,C) = 0 ∨ 1 = 1 .
Why this step? Every parent becomes an ancestor first (shortest chains); the merge ∨ promotes both from 0 to 1 .
Round 2. Transitive rule: parent(A,B) ∧ ancestor(B,C) = 1 ⋅ 1 = 1 , so ancestor(A,C) = 0 ∨ 1 = 1 .
Why this step? Now longer chains close; A reaches C .
Round 3. Re-apply all rules: every merge returns the value already stored (e.g. 1 ∨ 1 = 1 ), so no membership degree changes. Fixed point reached.
Why this step? Convergence is defined as a round where F ( t + 1 ) = F ( t ) — you stop when the merge produces no change, giving 3 rounds (the last one confirms).
Verify: derived facts { ancestor(A,B) , ancestor(B,C) , ancestor(A,C) } , sizes per round 2 , 4 , 5 , 5 ; growth halts at round 3 ✓. The limiting number of ancestor facts for a chain of 3 people is ( 2 3 ) = 3 ✓.
Worked example Ex 7 — Cell I: real-world word problem (end-to-end loan pipeline)
Statement. A loan model must satisfy: "IF applicant is flagged high-risk THEN loan must be rejected." Neural scorer gives p ( high-risk ) = 0.85 , p ( approve ) = 0.70 . Encode the rule as a violation, compute it with λ = 3.0 , and state the interpretable explanation the XAI layer prints.
Forecast: high-risk and likely-approve — the rule is broken; how big is the penalty?
Rewrite rule. "high-risk ⇒ reject" is the same as "high-risk ⇒ NOT approve", so b = ¬ p ( approve ) = 1 − 0.70 = 0.30 .
Why this step? Implication needs a "then" truth degree; the conclusion is the negation of approval, using soft-NOT.
Gap. a − b = 0.85 − 0.30 = 0.55 .
Why this step? Premise (high-risk) outruns the reject-degree by 0.55 .
Violation & loss. [ 0.55 ] + = 0.55 ; λ ⋅ 0.55 = 3.0 × 0.55 = 1.65 added to L data .
Why this step? Heavy λ because a compliance rule must dominate raw score-fitting.
Explanation string. XAI prints: "Rejected: high-risk=0.85 triggers the reject rule; approval was suppressed by symbolic constraint (violation 0.55)."
Why this step? The symbolic side gives a human-readable reason , which "neuron 4738 fired" never could.
Verify: 1 − 0.70 = 0.30 ✓, 0.85 − 0.30 = 0.55 ✓, 3.0 ⋅ 0.55 = 1.65 ✓. Once the network lowers p ( approve ) to ≤ 0.15 , b ≥ 0.85 , gap ≤ 0 , penalty → 0 — compliant.
The figure above traces the loan pipeline left-to-right: raw features → neural scorer → two probabilities → symbolic rule box → floored violation 0.55 → weighted penalty 1.65 → human-readable reject reason.
Worked example Ex 8 — Cell J: the exam twist (sign trap + which
λ wins)
Statement. Two rules apply at once. Rule 1 (implication): a 1 = 0.4 , b 1 = 0.9 , weight λ 1 = 5 . Rule 2 (exclusivity): p ( c 1 ) = 0.55 , p ( c 2 ) = 0.60 , weight λ 2 = 1 . Which rule contributes to the loss, and what is the total symbolic loss? (Trap: don't assume the big λ dominates.)
Forecast: the heavier rule has λ = 5 — but does it actually fire?
Rule 1 violation. [ 0.4 − 0.9 ] + = [ − 0.5 ] + = 0 .
Why this step? Conclusion exceeds premise → Cell C → the floor [ ⋅ ] + returns zero , no matter how large λ 1 is.
Rule 1 contribution. λ 1 ⋅ 0 = 5 × 0 = 0 .
Why this step? This is the trap: a huge weight on a satisfied rule contributes nothing.
Rule 2 violation. [ 0.55 + 0.60 − 1 ] + = [ 0.15 ] + = 0.15 .
Why this step? Exclusivity mass exceeds 1 → Cell E fires.
Total. L symbolic = 0 + λ 2 ⋅ 0.15 = 1 × 0.15 = 0.15 .
Why this step? Only the small-λ rule matters, because it is the only one violated. Weight scales an active penalty; it cannot resurrect a dead one.
Verify: 0.4 − 0.9 = − 0.5 ⇒ 0 ✓; 0.55 + 0.60 − 1 = 0.15 ✓; total = 0.15 ✓. Lesson: always compute the floor [ ⋅ ] + before multiplying by λ .
Recall Self-test — cover the answers
Ex 1 penalty at λ = 2 , gap 0.5 ? ::: 1.00 , and a is pushed down / b up; slope is ± λ = ± 2 .
The two zeros in Ex 2 — same value, different meaning? ::: Yes: Cell B sits on the boundary, Cell C hides a 0.60 slack; both give gradient 0 .
Soft-AND of 0.9 , 0.8 , 0.7 ? ::: 0.504 (vs min = 0.70 ).
Exclusivity violation for 0.7 + 0.6 ? ::: 0.30 , push both down by 0.15 (least-norm split).
The floor [ ⋅ ] + vs the merge ∨ — same thing? ::: No: [ ⋅ ] + is a one-sided penalty floor (one input is 0 ); ∨ is the two-input best-evidence OR over truth degrees.
Is p ( cat ) different from μ cat ? ::: No — identical [ 0 , 1 ] slider; p names a classifier output, μ names a logic truth degree.
Grandparent link with a μ = 0 premise? ::: 0 — nothing inferred (Cell F).
Forward-chaining rounds for a 3-person chain? ::: 3 (last round confirms fixed point).
Loan penalty at λ = 3 ? ::: 1.65 .
Ex 8 total symbolic loss? ::: 0.15 — the big-λ rule was satisfied, so contributed 0 .
Mnemonic Floor before you multiply
"Floor before you multiply." Compute [ gap ] + first ; only then weight by λ . A giant λ on a satisfied rule is a giant times zero.
Related deep dives to visit next: 4.3.05-Attention-Mechanisms (how NMN modules route attention), 6.5.07-Reinforcement-Learning-Advanced (symbolic reward shaping), 6.5.10-Causal-Inference (rules as interventions). Back to the parent topic .