Part 2Math for LLMs

Sets and Logic: Part 2 - Propositional Logic To 12 Advanced Topics

Mathematical Foundations / Sets and Logic

Private notes
0/8000

Notes stay private to your browser until account sync is configured.

Part 2
28 min read18 headingsSplit lesson page

Lesson overview | Previous part | Next part

Sets and Logic: Part 5: Propositional Logic to 12. Advanced Topics

5. Propositional Logic

Propositional logic is the simplest complete system of logical reasoning. It studies how the truth of compound statements depends on the truth of their components, without looking inside those components. It is the foundation for Boolean circuits, attention mask logic, SAT solvers, and the systematic reasoning that predicate logic (6) and proof techniques (7) build upon.

5.1 Propositions

A proposition is a declarative statement that is either true (TT, 1) or false (FF, 0). Never both, never neither.

Examples of propositions:

  • "The sky is blue" - true proposition
  • "2+2=52 + 2 = 5" - false proposition
  • "LLaMA-3 has 8B parameters" - true proposition
  • "Every even integer greater than 2 is the sum of two primes" - proposition (truth value unknown; Goldbach's conjecture)

Not propositions:

  • "What is your name?" - question, no truth value
  • "Close the door" - command, no truth value
  • "x>3x > 3" - depends on xx; becomes a proposition only when xx is specified (this is a predicate, see 6)

Propositional variables: Letters p,q,r,s,p, q, r, s, \ldots stand for unspecified propositions. Each has a truth value - either TT or FF.

5.2 Logical Connectives

Connectives combine propositions into compound statements. There are six standard connectives:

Negation (NOT): ¬p\neg p

"Not pp." Flips the truth value.

pp¬p\neg p
TTFF
FFTT

AI: Bitwise NOT in attention masks; complement of a token set.

Conjunction (AND): pqp \wedge q

"pp and qq." True only when both are true.

ppqqpqp \wedge q
TTTTTT
TTFFFF
FFTTFF
FFFFFF

AI: Combining attention masks (token must be unmasked AND within window); intersecting constraints in structured generation.

Disjunction (OR): pqp \vee q

"pp or qq." True when at least one is true (inclusive or).

ppqqpqp \vee q
TTTTTT
TTFFTT
FFTTTT
FFFFFF

AI: Union of token sets in structured generation; "match either pattern" in retrieval.

Exclusive Or (XOR): pqp \oplus q

"pp xor qq." True when exactly one is true.

ppqqpqp \oplus q
TTTTFF
TTFFTT
FFTTTT
FFFFFF

AI: Symmetric difference of sets; error detection (XOR of prediction and ground truth bits); XOR is the simplest function not linearly separable - a single perceptron cannot learn it (Minsky & Papert 1969).

Implication (IF...THEN): pqp \to q

"If pp then qq." Also read "pp implies qq." False only when pp is true and qq is false - a true hypothesis cannot lead to a false conclusion.

ppqqpqp \to q
TTTTTT
TTFFFF
FFTTTT
FFFFTT

Vacuous truth: When pp is false, pqp \to q is always true regardless of qq. This is often counterintuitive but essential:

  • "If pigs fly, then the moon is green" is true (vacuously)
  • The reason: pqp \to q promises "whenever pp holds, qq holds." If pp never holds, the promise is never violated, so it's true by default.

Vacuous truth in mathematics and AI:

  • "x\forall x \in \emptyset, property P(x)P(x) holds" - true, because there's nothing to check
  • "A\emptyset \subseteq A" - true, because every element of \emptyset (there are none) is in AA
  • "If the model reaches 100% accuracy, then it has generalised" - vacuously true if the model never reaches 100%

Biconditional (IF AND ONLY IF): pqp \leftrightarrow q

"pp if and only if qq" (abbreviated "iff"). True when pp and qq have the same truth value.

ppqqpqp \leftrightarrow q
TTTTTT
TTFFFF
FFTTFF
FFFFTT

Equivalently: pq(pq)(qp)p \leftrightarrow q \equiv (p \to q) \wedge (q \to p).

AI: Set equality (A=B    ABBAA = B \iff A \subseteq B \wedge B \subseteq A); defining exactly when a condition holds.

5.3 Operator Precedence

When multiple connectives appear without parentheses, the standard precedence (highest first) is:

¬>>>>\neg \quad > \quad \wedge \quad > \quad \vee \quad > \quad \to \quad > \quad \leftrightarrow

Examples:

  • ¬pq\neg p \wedge q means (¬p)q(\neg p) \wedge q, not ¬(pq)\neg(p \wedge q)
  • pqrp \vee q \to r means (pq)r(p \vee q) \to r, not p(qr)p \vee (q \to r)
  • pqrp \wedge q \vee r means (pq)r(p \wedge q) \vee r, not p(qr)p \wedge (q \vee r)

Best practice: Always use parentheses when there's any ambiguity. Clarity is more important than brevity.

5.4 Tautologies, Contradictions, and Contingencies

Tautology: A formula that is true for all possible truth value assignments to its variables. Logically necessary - cannot possibly be false.

TautologyName
p¬pp \vee \neg pLaw of excluded middle
ppp \to pSelf-implication
(pq)p(p \wedge q) \to pSimplification
(pq)(¬pq)(p \to q) \leftrightarrow (\neg p \vee q)Implication equivalence

Contradiction (Unsatisfiable): A formula that is false for all truth value assignments.

ContradictionWhy
p¬pp \wedge \neg pCannot be both true and false
(pq)p¬q(p \to q) \wedge p \wedge \neg qModus ponens violated

Contingency: A formula that is true for some assignments and false for others.

  • pqp \wedge q - true when both true, false otherwise
  • pqp \to q - false only when TFT \to F

Satisfiability: A formula is satisfiable if at least one truth assignment makes it true. Tautologies and contingencies are satisfiable; contradictions are not.

The SAT problem: Given a propositional formula ϕ\phi, is ϕ\phi satisfiable? This is the canonical NP-complete problem (Cook-Levin theorem, 1971). Despite worst-case intractability, modern SAT solvers handle millions of variables - they are critical for AI constraint solving, formal verification, and automated planning.

5.5 Logical Equivalence

Two formulas ϕ\phi and ψ\psi are logically equivalent (written ϕψ\phi \equiv \psi) if they have the same truth value for every possible truth assignment. Equivalently: ϕψ\phi \leftrightarrow \psi is a tautology.

Here are the fundamental equivalences - the "algebra rules" of logic:

Double Negation:

¬¬pp\neg\neg p \equiv p

De Morgan's Laws:

¬(pq)¬p¬q\neg(p \wedge q) \equiv \neg p \vee \neg q ¬(pq)¬p¬q\neg(p \vee q) \equiv \neg p \wedge \neg q

These are the most used laws in practice. Notice they mirror the set-theoretic De Morgan's Laws (3.6) exactly - this is the Boolean algebra correspondence (5.7).

Implication Equivalences:

pq¬pqp \to q \equiv \neg p \vee q pq¬q¬p(contrapositive)p \to q \equiv \neg q \to \neg p \quad \text{(contrapositive)} ¬(pq)p¬q\neg(p \to q) \equiv p \wedge \neg q

The contrapositive equivalence is used constantly in proofs (see 7.3). It says "pp implies qq" is the same as "not qq implies not pp." Distinguish from the converse (qpq \to p), which is NOT equivalent to pqp \to q.

Distributive Laws:

p(qr)(pq)(pr)p \wedge (q \vee r) \equiv (p \wedge q) \vee (p \wedge r) p(qr)(pq)(pr)p \vee (q \wedge r) \equiv (p \vee q) \wedge (p \vee r)

Absorption Laws:

p(pq)pp \wedge (p \vee q) \equiv p p(pq)pp \vee (p \wedge q) \equiv p

Idempotent Laws:

pppp \wedge p \equiv p pppp \vee p \equiv p

Identity Laws:

pTpp \wedge T \equiv p pFpp \vee F \equiv p

Domination Laws:

pFFp \wedge F \equiv F pTTp \vee T \equiv T

Complement Laws:

p¬pFp \wedge \neg p \equiv F p¬pTp \vee \neg p \equiv T

5.6 Normal Forms

Literal: A variable or its negation (pp or ¬p\neg p).

Clause: A disjunction of literals (p¬qrp \vee \neg q \vee r).

Term: A conjunction of literals (p¬qrp \wedge \neg q \wedge r).

Conjunctive Normal Form (CNF)

A formula in CNF is a conjunction of clauses - an AND of ORs:

(pq¬r)(¬ps)(r¬s)(p \vee q \vee \neg r) \wedge (\neg p \vee s) \wedge (r \vee \neg s)

Every propositional formula can be converted to an equivalent CNF. SAT solvers require CNF input - the DPLL and CDCL algorithms operate exclusively on CNF.

Disjunctive Normal Form (DNF)

A formula in DNF is a disjunction of terms - an OR of ANDs:

(pq¬r)(¬ps)(r¬s)(p \wedge q \wedge \neg r) \vee (\neg p \wedge s) \vee (r \wedge \neg s)

Every formula can be converted to DNF. A DNF is satisfiable iff any single term is satisfiable (no complementary literals in a term), which is easy to check - but the conversion to DNF may be exponentially large.

Conversion to CNF (Algorithm)

Given an arbitrary formula ϕ\phi:

  1. Eliminate biconditionals: pq(pq)(qp)p \leftrightarrow q \longrightarrow (p \to q) \wedge (q \to p)
  2. Eliminate implications: pq¬pqp \to q \longrightarrow \neg p \vee q
  3. Push negations inward (De Morgan's + double negation):
    • ¬(pq)¬p¬q\neg(p \wedge q) \longrightarrow \neg p \vee \neg q
    • ¬(pq)¬p¬q\neg(p \vee q) \longrightarrow \neg p \wedge \neg q
    • ¬¬pp\neg\neg p \longrightarrow p
  4. Distribute \vee over \wedge: p(qr)(pq)(pr)p \vee (q \wedge r) \longrightarrow (p \vee q) \wedge (p \vee r)

Example: Convert p(qr)p \to (q \wedge r) to CNF:

  • Step 2: ¬p(qr)\neg p \vee (q \wedge r)
  • Step 4: (¬pq)(¬pr)(\neg p \vee q) \wedge (\neg p \vee r) - this is CNF OK

5.7 Boolean Algebra

The laws of propositional logic form an algebraic structure called a Boolean algebra: (B,,,¬,0,1)(B, \wedge, \vee, \neg, 0, 1) satisfying all the equivalences listed in 5.5.

The fundamental connection - Stone Representation Theorem: Every Boolean algebra is isomorphic to an algebra of sets:

LogicSetsPython
\wedge (AND)\cap (intersection)&
\vee (OR)\cup (union)|
¬\neg (NOT)complement~
FF (false)\emptysetset()
TT (true)UUuniversal set
\to (implies)\subseteq<=
\leftrightarrow (iff)====

This is why De Morgan's laws look the same for sets and for logic - they are the same, in the precise algebraic sense. Boolean algebra unifies propositional logic, set operations, and circuit design under a single framework.

AI connections:

  • Attention masks as Boolean matrices: An attention mask is a Boolean matrix M{0,1}n×nM \in \{0, 1\}^{n \times n} where Mij=1M_{ij} = 1 iff query ii attends to key jj. Combining masks (causal AND sliding window) is Boolean AND.
  • Structured generation FSMs: The transition function of a finite state machine operates on Boolean states. Valid token sets at each state are computed via Boolean operations.
  • Circuit complexity of neural networks: A ReLU network computes a piecewise linear function; each linear region corresponds to a Boolean pattern of active/inactive neurons - the network's behaviour is described by a Boolean function over activation patterns.

6. Predicate Logic (First-Order Logic)

Propositional logic treats statements as atomic units - it cannot look inside them. Predicate logic (FOL) opens them up, exposing the objects, properties, and quantifiers that make mathematical reasoning powerful. Every formal specification in AI - from type systems to knowledge bases to verification conditions - ultimately rests on predicate logic.

6.1 Predicates and Quantifiers - Motivation

The statement "every prime greater than 2 is odd" cannot be expressed in propositional logic. We need:

  1. A way to talk about individual objects (numbers, tokens, vectors)
  2. A way to express properties of objects ("is prime," "is odd")
  3. A way to say "for all" or "there exists"

Predicate logic provides all three.

6.2 Syntax of FOL

Terms: The objects we talk about.

  • Constants: Specific objects (00, 11, π\pi, [PAD], [CLS])
  • Variables: Placeholders for objects (xx, yy, zz)
  • Function symbols: Operations that produce objects (f(x)f(x), x+yx + y, embed(t)\text{embed}(t))

Predicates (relation symbols): Properties of or relationships between objects that evaluate to true or false.

  • Unary: Prime(x)\text{Prime}(x), IsToken(t)\text{IsToken}(t), Positive(x)\text{Positive}(x)
  • Binary: x<yx < y, SameCluster(a,b)\text{SameCluster}(a, b), Attends(i,j)\text{Attends}(i, j)
  • nn-ary: Between(x,y,z)\text{Between}(x, y, z) meaning yy is between xx and zz

Quantifiers: The two pillars of FOL.

Universal Quantifier: \forall ("for all")

xP(x)\forall x\, P(x)

"For every xx, P(x)P(x) holds." True when P(a)P(a) is true for every object aa in the domain.

Examples:

  • xR,x20\forall x \in \mathbb{R},\, x^2 \geq 0 - "every real number squared is non-negative"
  • tV,embed(t)Rd\forall t \in V,\, \text{embed}(t) \in \mathbb{R}^d - "every token maps to a dd-dimensional vector"
  • i,j[n],i>j    Mij=0\forall i, j \in [n],\, i > j \implies M_{ij} = 0 - causal mask definition

Existential Quantifier: \exists ("there exists")

xP(x)\exists x\, P(x)

"There exists an xx such that P(x)P(x) holds." True when P(a)P(a) is true for at least one object aa in the domain.

Examples:

  • xR,x2=2\exists x \in \mathbb{R},\, x^2 = 2 - "2\sqrt{2} exists (in R\mathbb{R})"
  • tV,P(next=tcontext)>0.5\exists t \in V,\, P(\text{next} = t \mid \text{context}) > 0.5 - "there's a token with probability above 0.5"
  • θ,L(θ)=0\exists \theta,\, \mathcal{L}(\theta) = 0 - "a global minimum exists" (not always true!)

Unique Existential: !\exists! ("there exists exactly one")

!xP(x)x[P(x)y(P(y)y=x)]\exists! x\, P(x) \equiv \exists x\, [P(x) \wedge \forall y\, (P(y) \to y = x)]

"There is exactly one xx satisfying P(x)P(x)." This is a defined symbol - it's syntactic sugar for the expression on the right.

6.3 Free and Bound Variables

A variable xx is bound in a formula if it appears within the scope of a quantifier x\forall x or x\exists x. Otherwise, it is free.

  • In x(x>y)\forall x\, (x > y): xx is bound, yy is free
  • In xP(x,y)Q(z)\exists x\, P(x, y) \wedge Q(z): xx is bound, yy and zz are free
  • In xy(x+y=0)\forall x\, \exists y\, (x + y = 0): both xx and yy are bound

A sentence (closed formula) has no free variables - it has a definite truth value. A formula with free variables is a predicate - it becomes a sentence only when specific values are substituted for the free variables or when they are quantified.

AI connection: In a loss function L(θ)=1Ni=1N(fθ(xi),yi)\mathcal{L}(\theta) = \frac{1}{N} \sum_{i=1}^N \ell(f_\theta(x_i), y_i), the index ii is bound (by the sum, a disguised \forall), while θ\theta is free - this is why we optimise over θ\theta.

6.4 Negating Quantifiers

Negation interacts with quantifiers via two fundamental rules:

¬xP(x)x¬P(x)\neg \forall x\, P(x) \equiv \exists x\, \neg P(x)

"Not everything satisfies PP" \equiv "Something fails to satisfy PP."

¬xP(x)x¬P(x)\neg \exists x\, P(x) \equiv \forall x\, \neg P(x)

"Nothing satisfies PP" \equiv "Everything fails to satisfy PP."

These are the quantifier analogues of De Morgan's laws. The pattern generalises:

  • Negation swaps \forall and \exists
  • Negation swaps \wedge and \vee
  • Negation swaps \cap and \cup

AI example: "Not all tokens are attended to" \equiv "There exists a token that is not attended to":

¬jAttends(i,j)j¬Attends(i,j)\neg \forall j\, \text{Attends}(i, j) \equiv \exists j\, \neg\text{Attends}(i, j)

6.5 Nested Quantifiers

Quantifiers can be nested. The order matters for mixed quantifiers:

xyP(x,y)yxP(x,y)\forall x\, \exists y\, P(x, y) \quad \neq \quad \exists y\, \forall x\, P(x, y)

The first says: "for every xx, there is (possibly different) yy such that P(x,y)P(x, y)." The second says: "there is a single yy that works for all xx."

Comparison with examples:

StatementFormalTrue?
"For every real, there's a larger one"xRyR(y>x)\forall x \in \mathbb{R}\, \exists y \in \mathbb{R}\, (y > x)True
"There's a real larger than all reals"yRxR(y>x)\exists y \in \mathbb{R}\, \forall x \in \mathbb{R}\, (y > x)False
"Every continuous function on [a,b][a,b] attains its max"fC[a,b]x[a,b]x[a,b]f(x)f(x)\forall f \in C[a,b]\, \exists x^* \in [a,b]\, \forall x \in [a,b]\, f(x^*) \geq f(x)True (EVT)
"For every ε>0\varepsilon > 0, there exists δ>0\delta > 0 ..."εδx\forall \varepsilon\, \exists \delta\, \forall x\, \ldotsContinuity def

Order rule: Swapping \forall and \exists is valid only if one direction of implication holds:

yxP(x,y)    xyP(x,y)\exists y\, \forall x\, P(x, y) \implies \forall x\, \exists y\, P(x, y)

The converse is NOT generally true. A single universal yy is a strictly stronger claim than an individual y(x)y(x) for each xx.

AI example - convergence of SGD:

  • ε>0Tt>TL(θt)L<ε\forall \varepsilon > 0\, \exists T\, \forall t > T\, |\mathcal{L}(\theta_t) - \mathcal{L}^*| < \varepsilon means "the loss converges to L\mathcal{L}^*"
  • Here TT depends on ε\varepsilon - this is the \forall\exists pattern

6.6 Translating Between English and FOL

Translating natural language to FOL is a critical skill for formal verification, knowledge representation, and understanding what mathematical theorems actually say.

Systematic approach:

  1. Identify the domain (what are the objects?)
  2. Identify the predicates (what properties/relations?)
  3. Identify the quantifier structure (\forall, \exists, their order)
  4. Write the formal expression
  5. Check by reading it back in English

Practice translations:

EnglishFOL
"All vectors in SS have unit norm"vS,v=1\forall v \in S,\, \|v\| = 1
"Some weight is negative"wW,w<0\exists w \in W,\, w < 0
"No gradient is zero"gG,g0\forall g \in G,\, g \neq 0 or ¬gG,g=0\neg\exists g \in G,\, g = 0
"If all gradients vanish, we're at a critical point"(i,if=0)CriticalPoint(θ)(\forall i,\, \nabla_i f = 0) \to \text{CriticalPoint}(\theta)
"For every layer, there exists a neuron that fires"nFires(,n)\forall \ell\, \exists n\, \text{Fires}(\ell, n)
"There's a learning rate that works for all tasks"ηtaskConverges(η,task)\exists \eta\, \forall \text{task}\, \text{Converges}(\eta, \text{task}) (probably false!)

6.7 FOL in AI Contexts

Knowledge graphs store facts as FOL ground atoms: LocatedIn(Paris,France)\text{LocatedIn}(\text{Paris}, \text{France}), InstanceOf(GPT-4,LLM)\text{InstanceOf}(\text{GPT-4}, \text{LLM}). Rules are FOL implications: x,y,z[LocatedIn(x,y)LocatedIn(y,z)LocatedIn(x,z)]\forall x, y, z\, [\text{LocatedIn}(x, y) \wedge \text{LocatedIn}(y, z) \to \text{LocatedIn}(x, z)].

Description logics (OWL, used in ontologies) are decidable fragments of FOL. They balance expressiveness with computational tractability - reasoning in full FOL is undecidable.

Program specification: Hoare logic uses FOL to specify pre/post-conditions: {P}program{Q}\{P\}\, \text{program}\, \{Q\} means "if PP holds before, QQ holds after."

LLM reasoning: When an LLM performs chain-of-thought reasoning, it is (approximately) performing FOL inference - applying modus ponens, instantiating universals, existential witnesses. The fidelity of this approximation is an active research question.


7. Proof Techniques

This chapter only needs a working preview of proof methods so later sections can state theorems precisely and you can follow the logic of an argument without being surprised by the structure. The full treatment lives in Proof Techniques, where each method is developed in much more depth.

For now, the right goal is recognition:

  • What kind of claim is being proved?
  • What assumptions are being used?
  • Why is a specific proof strategy a natural fit?

7.1 What is a Proof?

A proof is a finite chain of justified steps from assumptions, definitions, axioms, and previously established results to a conclusion. In this section, sets and logic give us the vocabulary; proofs tell us how that vocabulary is used to certify statements rather than merely suggest them.

That distinction matters in AI. A numerical experiment may suggest that an optimizer converges or that a masking rule preserves causality, but a proof tells you exactly under which assumptions the conclusion must hold.

7.2 Direct Proof

In a direct proof, you start from the hypothesis and push forward to the conclusion. This is the default style for statements of the form "PQP \to Q" when the path from premises to result is transparent.

Example: to show that the sum of two even integers is even, write them as 2a2a and 2b2b, add them, and observe the result is again divisible by 2. This style mirrors many derivations in ML, where you begin with model assumptions and algebraically derive a bound or identity.

7.3 Proof by Contrapositive

Sometimes the forward direction is awkward, but the logically equivalent statement ¬Q¬P\neg Q \to \neg P is easier. That is proof by contrapositive, and it is why the implication equivalence in 5.5 matters operationally, not just symbolically.

Classic example: to prove "if n2n^2 is even, then nn is even," it is simpler to show "if nn is odd, then n2n^2 is odd." In theory-heavy AI writing, contraposition shows up in impossibility and lower-bound arguments where failure of the conclusion exposes useful structure in the assumptions.

7.4 Proof by Contradiction

In proof by contradiction, you assume the statement is false and derive an impossibility. This is especially common when proving that some object cannot exist, that a property must hold universally, or that a certain finite description is impossible.

Famous examples include proving that 2\sqrt{2} is irrational and that there are infinitely many primes. In AI-flavored mathematics, contradiction often appears when ruling out pathological counterexamples or showing that a supposed optimum or invariant would violate earlier assumptions.

7.5 Proof by Cases

When a domain naturally splits into a few exhaustive possibilities, you can prove a statement separately in each branch. This is proof by cases.

For example, the claim x0|x| \geq 0 is easiest by splitting into x0x \geq 0 and x<0x < 0. The same structure appears in algorithms and model analysis whenever behavior differs across regimes such as active vs inactive ReLU units, interior vs boundary points, or short-context vs long-context cases.

7.6 Mathematical Induction

Induction proves statements indexed by the natural numbers. You establish a base case, then show that if the claim holds at step kk, it also holds at step k+1k+1. Once both parts are in place, the result propagates to all later indices.

This matters for AI because many objects are recursive or sequential: token prefixes, layers in a stack, rollout horizons, and sequence length arguments are all natural induction targets. We will use the full machinery in the dedicated proof section when sequence-model reasoning becomes more central.

7.7 Existence and Uniqueness Proofs

An existence proof shows that at least one object with the desired property exists. A uniqueness proof shows there can be at most one. Together, they establish that there is exactly one such object.

This distinction is everywhere in optimization and model theory. "A minimizer exists" and "the minimizer is unique" are very different statements, with different consequences for learning dynamics and interpretation.

7.8 Proof by Construction

A constructive proof does more than assert existence: it explicitly builds the object. This is especially valuable in computer science and AI because a constructive argument often doubles as an algorithm.

For instance, if a theorem says there exists a network, partition, mask, or encoding with certain properties, a constructive proof tells you how to produce one. That is why constructive arguments are often more actionable than purely existential ones.

7.9 Why This Is Only a Preview

At this stage, proof techniques should feel like a toolbox you can recognize, not yet one you have fully mastered. The important bridge is:

  • logic gives the form of valid inference
  • sets provide the objects and predicates we talk about
  • proofs combine both into reliable mathematical arguments

When you are ready to go deeper, continue with Proof Techniques, where these methods are expanded with full templates, worked examples, and more explicit AI applications.


8. Axiomatic Set Theory (ZFC)

Naive set theory (2) is intuitive but broken - Russell's Paradox (2.5) shows that unrestricted set formation leads to contradictions. ZFC (Zermelo-Fraenkel axioms with the Axiom of Choice) is the standard rigorous foundation for all of modern mathematics. Every mathematical object - numbers, functions, spaces, probability measures, neural networks - can be built from ZFC sets.

8.1 Why Axioms?

Axioms serve two purposes:

  1. Prevent paradoxes: By restricting which sets exist, ZFC avoids Russell's Paradox and similar contradictions.
  2. Ensure consistency: All mathematical reasoning ultimately reduces to statements provable from these axioms.

The axioms tell you exactly which sets you are allowed to construct and what operations you may perform on them. Nothing more, nothing less.

8.2 The ZFC Axioms

There are 9 axioms (some formulations give 8 or 10; the exact count depends on grouping). Here they are, with intuition and notation.

Axiom 1: Extensionality

AB[x(xAxB)A=B]\forall A\, \forall B\, [\forall x\, (x \in A \leftrightarrow x \in B) \to A = B]

Two sets are equal if and only if they have the same elements. A set is determined entirely by its membership - there is no "hidden structure."

Consequence: {1,2,3}={3,1,2}={1,1,2,3}\{1, 2, 3\} = \{3, 1, 2\} = \{1, 1, 2, 3\}. Order and repetition are irrelevant.

Axiom 2: Empty Set

x(x)\exists \emptyset\, \forall x\, (x \notin \emptyset)

There exists a set with no elements. By Extensionality, this set is unique - there is only one empty set.

Axiom 3: Pairing

abCx(xCx=ax=b)\forall a\, \forall b\, \exists C\, \forall x\, (x \in C \leftrightarrow x = a \vee x = b)

For any two objects aa and bb, the set {a,b}\{a, b\} exists. This lets us form pairs, which underpins ordered pairs and Cartesian products.

Axiom 4: Union

FUx(xUAF,xA)\forall \mathcal{F}\, \exists U\, \forall x\, (x \in U \leftrightarrow \exists A \in \mathcal{F},\, x \in A)

For any collection of sets F\mathcal{F}, there exists a set U=FU = \bigcup \mathcal{F} containing exactly the elements that belong to at least one set in F\mathcal{F}.

Axiom 5: Power Set

APB(BPBA)\forall A\, \exists P\, \forall B\, (B \in P \leftrightarrow B \subseteq A)

For any set AA, the power set P(A)\mathcal{P}(A) exists. This is the set of all subsets of AA, and P(A)=2A|\mathcal{P}(A)| = 2^{|A|} for finite AA.

Axiom 6: Separation (Specification / Comprehension)

ABx(xBxAϕ(x))\forall A\, \exists B\, \forall x\, (x \in B \leftrightarrow x \in A \wedge \phi(x))

For any set AA and any property ϕ\phi, the set {xAϕ(x)}\{x \in A \mid \phi(x)\} exists. Crucially, you can only separate out elements from an existing set - you cannot form {xϕ(x)}\{x \mid \phi(x)\} without a bounding set AA.

This is what blocks Russell's Paradox. The "set of all sets that don't contain themselves" would require {xxx}\{x \mid x \notin x\} - but without a bounding set AA, Separation doesn't let you form it.

Axiom 7: Infinity

I[Ix(xIx{x}I)]\exists I\, [\emptyset \in I \wedge \forall x\, (x \in I \to x \cup \{x\} \in I)]

There exists an infinite set - specifically, a set containing \emptyset, {}\{\emptyset\}, {,{}}\{\emptyset, \{\emptyset\}\}, and so on forever. This axiom guarantees the existence of the natural numbers (and prevents mathematics from being stuck in a finite world).

Axiom 8: Replacement

AF[(F is a function)BB={F(x)xA}]\forall A\, \forall F\, [\text{($F$ is a function)} \to \exists B\, B = \{F(x) \mid x \in A\}]

If FF is a definable function and AA is a set, then the image {F(x)xA}\{F(x) \mid x \in A\} is a set. This is like Separation but more powerful - it lets you apply a function to every element and collect the results.

AI analogy: Replacement is map. Given a set (dataset) and a function (model), the outputs form a set (predictions).

Axiom 9: Foundation (Regularity)

A[AxA(xA=)]\forall A\, [A \neq \emptyset \to \exists x \in A\, (x \cap A = \emptyset)]

Every non-empty set AA has an element disjoint from AA. This prevents circular membership chains (abaa \in b \in a) and self-containing sets (aaa \in a). Sets are "well-founded" - they are built from the bottom up (from \emptyset).

8.3 The Axiom of Choice (AC)

F[Ff:FFAF,f(A)A]\forall \mathcal{F}\, [\emptyset \notin \mathcal{F} \to \exists f: \mathcal{F} \to \bigcup \mathcal{F}\, \forall A \in \mathcal{F},\, f(A) \in A]

For any collection of non-empty sets, there exists a choice function ff that selects exactly one element from each set. This seems obvious but has deep consequences.

Why it's controversial:

  • It's non-constructive: it asserts the existence of a choice function without building one
  • It implies paradoxical results: Banach-Tarski paradox (decompose a sphere into 5 pieces and reassemble into two spheres of the same size)
  • It implies well-ordering theorem: every set can be well-ordered (including R\mathbb{R}, despite having no known explicit well-ordering)

Why it's accepted:

  • Without AC, many theorems fail (every vector space has a basis; Tychonoff's theorem; Hahn-Banach theorem)
  • ZFC (with AC) has not been shown inconsistent
  • AC is independent of ZF: both ZF+AC and ZF+\negAC are consistent (if ZF is consistent), by Godel (1938) and Cohen (1963)

AI applications of AC: Most machine learning theory implicitly uses AC:

  • "There exists a minimiser of the loss function" - may require AC for non-compact spaces
  • "Every vector space has a basis" - needs AC for infinite-dimensional spaces (function spaces in kernel methods)
  • In practice, everything is finite-dimensional, so AC is not needed for actual computations

8.4 Constructing Numbers from Sets

One of the most remarkable achievements of axiomatic set theory is building all number systems from pure sets:

Natural numbers (von Neumann construction):

0=,1={},2={,{}},3={,{},{,{}}},0 = \emptyset, \quad 1 = \{\emptyset\}, \quad 2 = \{\emptyset, \{\emptyset\}\}, \quad 3 = \{\emptyset, \{\emptyset\}, \{\emptyset, \{\emptyset\}\}\}, \quad \ldots

The rule: n+1=n{n}n + 1 = n \cup \{n\}. Each natural number is the set of all smaller natural numbers: n={0,1,,n1}n = \{0, 1, \ldots, n-1\}, so n=n|n| = n.

Integers: Z\mathbb{Z} is constructed as equivalence classes of pairs of natural numbers: [(a,b)][(a, b)] represents aba - b.

Rationals: Q\mathbb{Q} is constructed as equivalence classes of pairs of integers: [(p,q)][(p, q)] represents p/qp/q where q0q \neq 0.

Reals: R\mathbb{R} is constructed via Dedekind cuts or Cauchy sequences of rationals.

The takeaway: Every mathematical object - including the real numbers that neural network weights live in - is built from the empty set using ZFC axioms. This is why set theory is called the "foundation of mathematics."

8.5 Ordinals and Cardinals (Brief)

Ordinal numbers extend the natural numbers to describe the "length" of well-orderings:

0,1,2,,ω,ω+1,ω+2,,ω2,,ω2,,ωω,,ε0,0, 1, 2, \ldots, \omega, \omega + 1, \omega + 2, \ldots, \omega \cdot 2, \ldots, \omega^2, \ldots, \omega^\omega, \ldots, \varepsilon_0, \ldots

Here ω\omega is the first infinite ordinal (the "ordinal type" of N\mathbb{N}). Ordinals are used to measure the "height" of sets in the cumulative hierarchy.

Cardinal numbers measure the "size" of sets. For finite sets, the cardinal and ordinal notions coincide (S=n|S| = n means SS has nn elements). For infinite sets, cardinality is defined via bijections - two sets have the same cardinality iff a bijection exists between them. More on this in 10.


9. Logic in Computation and AI

This section bridges the pure theory of 5-8 to the concrete computational world. The key idea: logic is not just a tool for proofs - it is the foundation of computation itself.

9.1 Boolean Circuits

Every digital computer is built from logic gates - physical implementations of the logical connectives:

GateLogicSymbolOutput
ANDpqp \wedge q&1 iff both inputs are 1
ORpqp \vee q|1 iff at least one input is 1
NOT¬p\neg p~Flips the bit
NAND¬(pq)\neg(p \wedge q)-0 iff both inputs are 1
XORpqp \oplus q^1 iff inputs differ

Functional completeness: {AND,OR,NOT}\{AND, OR, NOT\} can compute any Boolean function. Even more remarkably, {NAND}\{NAND\} alone is functionally complete - every Boolean function can be built from NAND gates.

From gates to GPUs: GPU cores perform massively parallel Boolean and arithmetic operations. The floating-point units, comparison circuits, and memory addressing logic in a GPU are all Boolean circuits. When you run torch.matmul(A, B), underneath it is billions of transistors implementing Boolean functions.

9.2 SAT Solving

The Boolean satisfiability problem (SAT): given a propositional formula in CNF, is there a truth assignment that makes it true?

DPLL Algorithm (Davis-Putnam-Logemann-Loveland, 1962):

  1. Unit propagation: If a clause has one unset literal, it must be true
  2. Pure literal elimination: If a variable appears with only one polarity, set it to satisfy those clauses
  3. Branching: Pick an unset variable, try both truth values, recurse
  4. Backtracking: If a contradiction is found, undo the last choice

CDCL (Conflict-Driven Clause Learning): Modern SAT solvers extend DPLL with learned clauses - when a conflict occurs, they analyse why and add a clause preventing the same conflict pattern. This is a form of learning from mistakes.

SAT in AI:

  • Constraint satisfaction: Many combinatorial AI problems reduce to SAT
  • Planning: Classical AI planning (SATPLAN) encodes action sequences as SAT instances
  • Formal verification: Proving neural network properties (robustness, fairness) reduces to SAT/SMT
  • Hardware design: Chip verification uses SAT solvers extensively
  • Structured generation: Ensuring LLM output satisfies a grammar can be framed as constraint satisfaction

9.3 Resolution and Automated Reasoning

Resolution is a single inference rule that is complete for refuting CNF formulas:

(Ap)(¬pB)AB\frac{(A \vee p) \quad (\neg p \vee B)}{A \vee B}

If one clause contains pp and another contains ¬p\neg p, their resolvent combines the remaining literals.

Completeness (Robinson, 1965): A set of clauses is unsatisfiable if and only if the empty clause (\bot) can be derived by repeated resolution.

This is the backbone of Prolog and logic programming - computation as proof search.

9.4 Type Theory and Programming

Type systems are deductive systems closely related to logic. The Curry-Howard correspondence establishes a deep isomorphism:

LogicType TheoryProgramming
PropositionTypeSpecification
ProofTerm (program)Implementation
PQP \to Q (implication)Function type PQP \to QFunction from PP to QQ
PQP \wedge Q (conjunction)Product type P×QP \times QPair/tuple
PQP \vee Q (disjunction)Sum type P+QP + QTagged union / either
xP(x)\forall x\, P(x)Dependent function Πx:AP(x)\Pi_{x:A} P(x)Generic/polymorphic function
xP(x)\exists x\, P(x)Dependent pair Σx:AP(x)\Sigma_{x:A} P(x)Record with witness
\bot (false)Empty typeUnreachable code
Proof of PPValue of type PPRunning program

Consequence: A valid type-checked program is a proof of its type signature. Type errors are logical contradictions.

AI connection - type-safe tensors: Projects like jaxtyping and beartype enforce tensor shape constraints at the type level: Float[Array, "batch seq d_model"]. A shape mismatch is caught as a type error - i.e., a logical contradiction between what the function promises and what it receives.

9.5 Modal Logic (Brief)

Modal logic extends propositional logic with necessity (\square) and possibility (\diamond):

  • P\square P: "PP is necessarily true" (true in all possible worlds)
  • P\diamond P: "PP is possibly true" (true in some possible world)

In AI:

  • Epistemic logic: KaPK_a P means "agent aa knows PP." Used in multi-agent systems.
  • Temporal logic: P\square P means "PP always holds" (safety); P\diamond P means "PP eventually holds" (liveness). Used in model checking and formal verification.
  • Deontic logic: What an AI system "should" do - the logic of obligations and permissions, relevant to AI alignment.

9.6 Description Logics and Knowledge Representation

Description logics (DLs) are decidable fragments of FOL designed for knowledge representation:

  • Concepts (unary predicates): Person, Model, LargeLanguageModel
  • Roles (binary predicates): trainedBy, hasParameter, outputs
  • Constructors: CDC \sqcap D (intersection), CDC \sqcup D (union), ¬C\neg C (complement), R.C\forall R.C (all RR-successors are in CC), R.C\exists R.C (some RR-successor is in CC)

DLs underpin the Web Ontology Language (OWL), used in knowledge graphs, biomedical ontologies, and semantic web. The reasoning complexity depends on which constructors are included - a careful balance between expressiveness and decidability.

9.7 LLM Reasoning as Approximate Logic

When an LLM performs chain-of-thought (CoT) reasoning, it is (approximately) performing logical inference:

Logical stepLLM behaviourFidelity
Modus ponens (P,PQQP, P \to Q \vdash Q)"Since PP and PP implies QQ, therefore QQ"High for simple cases
Universal instantiation (xP(x)P(a)\forall x P(x) \vdash P(a))"Since all X are Y, this X is Y"Moderate
Contradiction detection"But this contradicts..."Fragile
Multi-step chainsChaining 5+ inference stepsDegrades rapidly

Open research questions:

  • Can LLMs perform reliable deductive reasoning, or only pattern-matched approximation?
  • Can we formally verify LLM reasoning chains against logical rules?
  • Can symbolic logic modules be integrated with neural networks (neuro-symbolic AI)?
  • How does the "chain-of-thought" prompt format affect logical correctness?

Current evidence suggests LLMs are surprisingly good at local logical steps but struggle with long chains and quantifier reasoning (especially nested \forall\exists patterns). This is precisely the gap that formal methods aim to fill.


10. Cardinality and Infinite Sets

Cardinality answers the question: how big is a set? For finite sets the answer is obvious - just count. For infinite sets, the answer is one of the most profound discoveries in mathematics: not all infinities are the same size.

10.1 Finite Cardinality

If AA is finite, A=n|A| = n means there exists a bijection f:A{1,2,,n}f: A \to \{1, 2, \ldots, n\}. Counting is bijection.

Key counting facts for AI:

FormulaNameAI Example
AB=A+BAB\vert A \cup B \vert = \vert A \vert + \vert B \vert - \vert A \cap B \vertInclusion-exclusionDeduplicating token sets
A×B=AB\vert A \times B \vert = \vert A \vert \cdot \vert B \vertProduct ruleSize of joint state space
P(A)=2A\vert \mathcal{P}(A) \vert = 2^{\vert A \vert}Power setNumber of feature subsets
AB=AB\vert A^B \vert = \vert A \vert^{\vert B \vert}ExponentialNumber of functions from BB to AA
n!=n(n1)1n! = n \cdot (n-1) \cdots 1FactorialPermutation count
(nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k!(n-k)!}BinomialWays to choose kk items from nn

10.2 Comparing Infinite Sets - Bijections

Definition: Two sets AA and BB have the same cardinality (A=B|A| = |B|) if and only if there exists a bijection f:ABf: A \to B.

This is the only sensible definition for infinite sets - we cannot "count" them, but we can pair their elements one-to-one.

Example - N=Z|\mathbb{N}| = |\mathbb{Z}|:

This seems wrong - Z\mathbb{Z} "has twice as many elements." But pair them:

00,11,21,32,42,53,0 \mapsto 0, \quad 1 \mapsto 1, \quad 2 \mapsto -1, \quad 3 \mapsto 2, \quad 4 \mapsto -2, \quad 5 \mapsto 3, \quad \ldots

Formally: f(n) = \begin{cases} n/2 & \text{if nis even} \\ -(n+1)/2 & \text{ifn is odd} \end{cases}

This is a bijection, so N=Z|\mathbb{N}| = |\mathbb{Z}|. Infinity doesn't work like finite numbers.

10.3 Countable Sets

A set AA is countably infinite if A=N|A| = |\mathbb{N}| - i.e., there exists a bijection ANA \to \mathbb{N}. A set is countable if it is finite or countably infinite.

Equivalently, AA is countable iff its elements can be listed as a sequence a1,a2,a3,a_1, a_2, a_3, \ldots (possibly terminating).

Countable sets include:

SetWhy countable
N\mathbb{N}By definition
Z\mathbb{Z}Bijection shown above
Q\mathbb{Q}Cantor's zig-zag (diagonalisation of pq\frac{p}{q} table)
N×N\mathbb{N} \times \mathbb{N}Cantor pairing function: (m,n)(m+n)(m+n+1)2+m(m, n) \mapsto \frac{(m+n)(m+n+1)}{2} + m
All finite strings over finite alphabet Σ\SigmaΣ=n=0Σn\Sigma^* = \bigcup_{n=0}^\infty \Sigma^n, countable union of finite sets
All programs (source code)Programs are finite strings
All rational polynomialsCountable coefficients, finite degree
Algebraic numbersRoots of polynomials with integer coefficients

Key theorem: A countable union of countable sets is countable:

A1,A2,A3, countable    i=1Ai countableA_1, A_2, A_3, \ldots \text{ countable} \implies \bigcup_{i=1}^\infty A_i \text{ countable}

AI consequence: The set of all possible tokenised prompts (finite strings over a finite vocabulary VV) is countable. There are 0\aleph_0 possible inputs to an LLM.

10.4 Uncountable Sets - Cantor's Diagonal Argument

Theorem (Cantor, 1891). R\mathbb{R} is uncountable - there is no bijection NR\mathbb{N} \to \mathbb{R}.

Proof (diagonal argument). We show that even the interval (0,1)(0, 1) is uncountable. Assume, for contradiction, that (0,1)(0, 1) is countable. Then we can list all real numbers in (0,1)(0, 1):

r1=0.d11d12d13d14r_1 = 0.d_{11}d_{12}d_{13}d_{14}\ldots r2=0.d21d22d23d24r_2 = 0.d_{21}d_{22}d_{23}d_{24}\ldots r3=0.d31d32d33d34r_3 = 0.d_{31}d_{32}d_{33}d_{34}\ldots \vdots

Construct r=0.d1d2d3r^* = 0.d_1^* d_2^* d_3^* \ldots where dnd_n^* is any digit dnn\neq d_{nn} (and 0,9\neq 0, 9 to avoid alternative decimal representations).

Then r(0,1)r^* \in (0, 1) but rrnr^* \neq r_n for every nn (they differ at the nn-th digit). This contradicts the assumption that all reals in (0,1)(0, 1) were listed. \square

The symbol N=0|\mathbb{N}| = \aleph_0 ("aleph-null") denotes the first infinite cardinal. The set R\mathbb{R} has cardinality R=20=c|\mathbb{R}| = 2^{\aleph_0} = \mathfrak{c} (the cardinality of the continuum), which is strictly larger.

10.5 Cantor's Theorem (Generalised)

Theorem. For any set AA: A<P(A)|A| < |\mathcal{P}(A)|.

No set is as large as its power set. This holds for every set, finite or infinite.

Proof sketch. The map a{a}a \mapsto \{a\} injects AA into P(A)\mathcal{P}(A), so AP(A)|A| \leq |\mathcal{P}(A)|. To show strict inequality, suppose f:AP(A)f: A \to \mathcal{P}(A) is a bijection. Let D={aAaf(a)}D = \{a \in A \mid a \notin f(a)\}. Then DP(A)D \in \mathcal{P}(A), so D=f(d)D = f(d) for some dd (by surjectivity). Is dDd \in D?

  • If dDd \in D, then df(d)=Dd \notin f(d) = D - contradiction.
  • If dDd \notin D, then df(d)=Dd \in f(d) = D - contradiction.

Either way, contradiction. So no such bijection exists. \square

Consequence - the infinite tower:

N<P(N)<P(P(N))<|\mathbb{N}| < |\mathcal{P}(\mathbb{N})| < |\mathcal{P}(\mathcal{P}(\mathbb{N}))| < \cdots

There is no largest infinity. The hierarchy of infinities is itself infinite (and larger than any infinity in the hierarchy).

10.6 The Continuum Hypothesis

Claim (Cantor, 1878): There is no set SS with N<S<R|\mathbb{N}| < |S| < |\mathbb{R}|.

In other words, there is no "intermediate" infinity between the countable and the continuum.

Resolution (Godel 1940, Cohen 1963): The Continuum Hypothesis is independent of ZFC - it can neither be proved nor disproved from the standard axioms. Both ZFC + CH and ZFC + \negCH are consistent (if ZFC is).

This is one of the most surprising results in mathematics: there are meaningful mathematical questions that our axioms simply cannot answer.

10.7 Cardinality and AI

ObjectCardinalityConsequence
Finite vocabulary VVV\vert V \vert (finite, e.g., 32,000)Discrete, tractable
All prompts VV^*0\aleph_0 (countable)Enumerable in principle
All real-valued weight vectors Rd\mathbb{R}^dc\mathfrak{c}Uncountable - can't enumerate models
All functions RdR\mathbb{R}^d \to \mathbb{R}cc>c\mathfrak{c}^{\mathfrak{c}} > \mathfrak{c}Vastly larger than the set of computable functions
All computable functions0\aleph_0Programs are countable strings

The gap: There are uncountably many functions but only countably many programs (and neural network architectures, at any fixed precision). Most functions are not computable - and most mathematical objects are not representable by any model. This is a fundamental limitation.


11. Logic and Set Theory in Machine Learning

This section shows how the abstract tools of 2-10 appear concretely in modern ML.

11.1 Formal Languages and Automata

Formal language theory is set theory applied to strings:

  • An alphabet Σ\Sigma is a finite set of symbols
  • A string over Σ\Sigma is a finite sequence of symbols from Σ\Sigma
  • A language LL is a set of strings: LΣL \subseteq \Sigma^*

Connection to AI:

ConceptML Instantiation
Alphabet Σ\SigmaVocabulary VV (set of tokens)
StringToken sequence (prompt or completion)
Language LLSet of valid outputs
GrammarRules defining valid outputs (JSON schema, Python syntax)
Automaton (DFA/NFA)Constrained decoding state machine
Regular languageLanguages recognisable by finite automata
Context-free languageLanguages parseable by pushdown automata

Structured generation constrains an LLM to produce only strings from a target language LL. At each decoding step, the valid next tokens form a set VvalidVV_{\text{valid}} \subseteq V, computed by the automaton/parser. Tokens outside VvalidV_{\text{valid}} are masked (logits set to -\infty). This is Boolean logic applied to decoding.

11.2 Sets in Probability

The entire framework of probability theory is built on set theory (Kolmogorov axioms):

Probability conceptSet-theoretic object
Sample space Ω\OmegaSet of all possible outcomes
Event AASubset of Ω\Omega (AΩA \subseteq \Omega)
P(AB)P(A \cup B)Probability of AA or BB
P(AB)P(A \cap B)Probability of AA and BB
P(Ac)P(A^c)Probability of not AA; equals 1P(A)1 - P(A)
σ\sigma-algebra F\mathcal{F}Collection of measurable subsets of Ω\Omega
Independence: P(AB)=P(A)P(B)P(A \cap B) = P(A)P(B)Multiplicativity under intersection

Measure theory (the rigorous foundation of probability) relies heavily on ZFC: σ\sigma-algebras are sets of sets, measures are set functions, and the Axiom of Choice is needed for results like the Vitali set (a non-measurable set).

11.3 Sets in Linear Algebra

Linear algebra conceptSet structure
Vector space VVSet with addition and scalar multiplication
Subspace WVW \leq VSubset that is itself a vector space
Spanspan(S)={\text{span}(S) = \{ all linear combinations of S}S\} - a set
BasisLinearly independent spanning set
EigenspaceEλ={vAv=λv}E_\lambda = \{v \mid Av = \lambda v\} - defined by set-builder notation
Column spaceCol(A)={AxxRn}\text{Col}(A) = \{Ax \mid x \in \mathbb{R}^n\} - image of AA (a set)
Null spaceNull(A)={xAx=0}\text{Null}(A) = \{x \mid Ax = 0\} - kernel of AA (a set)

11.4 Logic in Training

Loss functions encode logical conditions:

ConditionLogicLoss
Output == targetEqualityMSE: fθ(x)y2\|f_\theta(x) - y\|^2
Output matches distributionPθPdataP_\theta \approx P_{\text{data}}KL divergence, cross-entropy
Margin conditionyi(wxi)1y_i (\mathbf{w} \cdot \mathbf{x}_i) \geq 1Hinge loss: max(0,1yi(wxi))\max(0, 1 - y_i (\mathbf{w} \cdot \mathbf{x}_i))
Constraint satisfactiong(θ)0g(\theta) \leq 0Lagrangian: L+λg(θ)\mathcal{L} + \lambda g(\theta)

Training as logic: gradient descent searches for θ\theta satisfying L(θ)=0\nabla \mathcal{L}(\theta) = 0 - this is an existential claim: θL(θ)=0\exists \theta^*\, \nabla \mathcal{L}(\theta^*) = 0.

Early stopping as logic: "Stop when the validation loss has not decreased for kk epochs" is a quantified condition: t[T,T+k],Lval(t)Lval(T)\forall t \in [T, T+k],\, \mathcal{L}_{\text{val}}^{(t)} \geq \mathcal{L}_{\text{val}}^{(T)}.

11.5 Sets in Model Architecture

Transformer attention as set operations:

The key insight of attention is that it operates on a set of key-value pairs (modulo positional encoding). Self-attention is permutation-equivariant: it treats the input as a set, not a sequence.

  • Query: "What am I looking for?"
  • Key set: K={k1,k2,,kn}K = \{k_1, k_2, \ldots, k_n\} - the set of keys to match against
  • Value set: V={v1,v2,,vn}V = \{v_1, v_2, \ldots, v_n\} - the set of values to aggregate
  • Attention mask: M[n]×[n]M \subseteq [n] \times [n] - the set of allowed (query, key) pairs

Combining masks:

  • Causal AND local: McausalMlocalM_{\text{causal}} \cap M_{\text{local}} - intersection (Boolean AND)
  • Multi-head union: hMh\bigcup_h M_h - each head sees a different subset of positions
  • Padding mask: Mpad={(i,j)j is not a padding token}M_{\text{pad}} = \{(i, j) \mid j \text{ is not a padding token}\}

11.6 Formal Verification of ML Systems

Logic provides tools to prove properties of ML systems rather than merely test them:

PropertyFormal statementMethod
Robustnessx,xx<εclass(x)=class(x)\forall x',\, \|x' - x\| < \varepsilon \to \text{class}(x') = \text{class}(x)SMT solving, MILP
FairnessP(y^A=0)=P(y^A=1)P(\hat{y} \mid A=0) = P(\hat{y} \mid A=1)Statistical testing + formal constraints
Safetyinput,outputSafeSet\forall \text{input},\, \text{output} \in \text{SafeSet}Reachability analysis
Monotonicityxixif(x)f(x)x_i \leq x_i' \to f(x) \leq f(x')Lattice-based verification

Certified defences use logical proofs (often via abstract interpretation or interval arithmetic) to guarantee that no adversarial perturbation within an ε\varepsilon-ball can change the classification. This is the gold standard for ML safety - moving from empirical robustness to provable robustness.


12. Advanced Topics

12.1 Godel's Incompleteness Theorems

The most profound results in mathematical logic, with deep implications for AI.

First Incompleteness Theorem (Godel, 1931): Any consistent formal system FF capable of expressing basic arithmetic contains a statement GG such that:

  • GG is true (in the standard model of arithmetic)
  • GG is not provable in FF
  • ¬G\neg G is not provable in FF

In other words, there are true mathematical statements that cannot be proved. No axiom system - ZFC, or any extension - can be both consistent and complete for arithmetic.

Godel's self-referential trick: Godel constructs GG to say, essentially, "I am not provable in system FF." If GG were provable, it would be false (since it says it's unprovable), contradicting consistency. If ¬G\neg G were provable, GG would be provable (since GG says it's not), contradiction. So neither GG nor ¬G\neg G is provable.

Second Incompleteness Theorem: No consistent system FF capable of expressing arithmetic can prove its own consistency.

F consistent    F⊬Con(F)F \text{ consistent} \implies F \not\vdash \text{Con}(F)

AI implications:

  • No AI system (which is a formal system) can verify all true mathematical statements - there will always be truths beyond its reach
  • The claim "this AI is guaranteed safe" cannot be proved within the AI's own framework (a version of the second theorem)
  • Godel's theorems do NOT mean mathematics is broken - they mean it is inexhaustible

12.2 The Halting Problem

Theorem (Turing, 1936). There is no algorithm that can determine, for every program PP and input II, whether PP halts on II.

Proof (by contradiction). Suppose H(P,I)H(P, I) is a program that returns "halts" or "loops" for any P,IP, I. Define:

D(P)={loop foreverif H(P,P)="halts"haltif H(P,P)="loops"D(P) = \begin{cases} \text{loop forever} & \text{if } H(P, P) = \text{"halts"} \\ \text{halt} & \text{if } H(P, P) = \text{"loops"} \end{cases}

What does D(D)D(D) do?

  • If H(D,D)=H(D, D) = "halts" -> D(D)D(D) loops forever. But HH said it halts. Contradiction.
  • If H(D,D)=H(D, D) = "loops" -> D(D)D(D) halts. But HH said it loops. Contradiction.

So HH cannot exist. \square

Connections to AI:

  • This is the computation analogue of Russell's Paradox - self-reference plus negation creates paradox
  • You cannot write a "universal bug detector" that catches all infinite loops
  • Theorem provers and code verifiers must be incomplete (they may time out or return "unknown")
  • LLM code generation cannot guarantee termination of generated code

12.3 Zorn's Lemma

Zorn's Lemma (equivalent to the Axiom of Choice and the Well-Ordering Theorem):

If every chain in a partially ordered set (P,)(P, \leq) has an upper bound in PP, then PP has a maximal element.

A chain is a totally ordered subset; a maximal element mm is one with no element strictly above it (xP,x>m\nexists x \in P,\, x > m).

Applications in mathematics:

  • Every vector space has a basis (even infinite-dimensional ones)
  • Every ideal in a ring is contained in a maximal ideal
  • Every filter can be extended to an ultrafilter

AI relevance: Zorn's Lemma is used in the theoretical foundations of kernel methods (Hilbert space bases) and functional analysis (Hahn-Banach theorem), which underlies support vector machines and reproducing kernel Hilbert spaces.

12.4 Fuzzy Logic

Classical logic is crisp: TT or FF. Fuzzy logic (Zadeh, 1965) allows truth values in [0,1][0, 1]:

μA(x)[0,1]\mu_A(x) \in [0, 1]

where μA(x)\mu_A(x) is the degree of membership of xx in fuzzy set AA.

Fuzzy operations:

ClassicalFuzzy
ABA \cap BμAB(x)=min(μA(x),μB(x))\mu_{A \cap B}(x) = \min(\mu_A(x), \mu_B(x))
ABA \cup BμAB(x)=max(μA(x),μB(x))\mu_{A \cup B}(x) = \max(\mu_A(x), \mu_B(x))
¬A\neg Aμ¬A(x)=1μA(x)\mu_{\neg A}(x) = 1 - \mu_A(x)

AI connections:

  • Softmax outputs are like fuzzy membership values - a token has degree-of-membership in each class
  • Attention weights αij[0,1]\alpha_{ij} \in [0, 1] are fuzzy: not binary "attend or not" but "how much to attend"
  • Fuzzy control systems (early AI) used fuzzy rules: "IF temperature IS high THEN fan IS fast"
  • Modern neural networks have largely replaced fuzzy systems, but the conceptual framework persists in the soft/differentiable operations that make gradient descent possible

12.5 Second-Order Logic (Brief)

First-order logic quantifies over objects: x,y,\forall x, \exists y, \ldots

Second-order logic quantifies over properties (sets, predicates, functions): P,f,\forall P, \exists f, \ldots

Example - Completeness of R\mathbb{R}:

  • First-order: CANNOT express "every bounded set has a least upper bound" (needs quantification over sets)
  • Second-order: SR[SMxS(xM)supS]\forall S \subseteq \mathbb{R}\, [S \neq \emptyset \wedge \exists M\, \forall x \in S\, (x \leq M) \to \exists \sup S]

Trade-off:

  • First-order logic: semi-decidable (complete proof systems exist), but less expressive
  • Second-order logic: more expressive, but no complete proof system exists (incompleteness is "worse")

In AI, first-order logic is preferred because it has better computational properties. Description logics, Datalog, and Prolog all work within FOL or its fragments.


Skill Check

Test this lesson

Answer 4 quick questions to lock in the lesson and feed your adaptive practice queue.

--
Score
0/4
Answered
Not attempted
Status
1

Which module does this lesson belong to?

2

Which section is covered in this lesson content?

3

Which term is most central to this lesson?

4

What is the best way to use this lesson for real learning?

Your answers save locally first, then sync when account storage is available.
Practice queue