Lecture 1 · Propositional Logic: Syntax, Semantics, Satisfiability and Validity

Introduction to Automated Reasoning · Lecture 01。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 1 · Tue 01/06/2026 · Propositional Logic: syntax, semantics, satisfiability and validity (Caroline Trippel). Reading: Bradley & Manna, The Calculus of Computation (CC) §1.1–1.5; Enderton, A Mathematical Introduction to Logic (MI) §1.0–1.2. Basis: The Stanford slides are on Canvas and not public. This lecture follows the official topic list and reading, and the public deck Propositional Logic Basics of the Iowa course CS:4980 (Cesare Tinelli, Spring 2024), which states that it is adapted from slides by Clark Barrett, Caroline Trippel and Andrew (Haoze) Wu at Stanford. “The slides” below means that deck. Its examples are reused here:

  • the formula α = (p ∧ q) ⇒ (p ∨ ¬q) and its truth table;
  • “1 + 1 = 10” read in decimal and in binary;
  • closed and generated sets;
  • the two semantic-argument proofs;
  • the Hilbert system H2.

The reading adds substitution (CC §1.5) and the induction principle (MI §1.2). These notes add the reasoning behind every definition, proofs of soundness, completeness and termination for the semantic-argument method, functional completeness via Post’s invariants, and five experiments that make each idea measurable. The experiments and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture01/ (5 scripts + 4 modules; Python standard library only, matplotlib optional; from under a second to about 15 seconds each) Reading time: 4–5 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Say what automated reasoning is, why it needs a formal language, and name a few places where it is used at industrial scale today.
  2. Define the syntax of propositional logic inductively, explain what precedence conventions abbreviate, and draw the parse tree of a formula.
  3. Prove properties of all formulas by structural induction, and define functions on formulas by structural recursion.
  4. Define the semantics of propositional logic (interpretations, compositional evaluation) and compute truth tables.
  5. Classify formulas as satisfiable, falsifiable, valid or unsatisfiable; decide entailment and equivalence; and explain why a single SAT procedure decides all of them (the duality theorems).
  6. Use substitution correctly: valid templates and substitution of equivalents (CC §1.5).
  7. Explain which sets of connectives are functionally complete, and prove that a set is not complete by finding an invariant.
  8. Run two decision procedures by hand — truth tables and semantic arguments — and argue why the latter is sound, complete and terminating.
  9. Translate English sentences, puzzles and small engineering questions (circuit equivalence) into formulas, and validate an encoding by counting its models.
  10. Explain, with measured numbers, why brute force hits an exponential wall — the motivation for the rest of the course.

0.2 Prerequisites and scope

The official prerequisite is CS154 (theory of computation), or CS103 + CS106B. This lecture needs much less:

AssumedIntroduced hereDeveloped later
sets, functions, proof by induction on natural numbersinductive definitions, structural induction and recursioninduction over derivations (Lecture 3)
“and”, “or”, “not” in everyday reasoningthe five connectives, truth tables, interpretationsfirst-order logic (Lectures 6–8)
a little Pythonformulas as trees, a parser, bit-parallel truth tablesCNF, DIMACS, SAT solvers (Lectures 2, 4, 5)
what “NP-complete” roughly means (helpful, not required)decision procedures, soundness, completenessproof systems in general (Lecture 3)

If you have never proved anything by induction, read §3 slowly; the rest of the course depends on it.

0.3 Map

§1  what automated reasoning is; why a formal language; history; applications
§2  syntax: alphabet, formula-building operators, inductive definitions, conventions, parse trees   ← code 01
§3  structural induction and recursion; infinitely many formulas, finitely many meanings          ← code 01
§4  semantics: interpretations, compositional evaluation, truth tables                            ← code 02
§5  satisfiability, validity, entailment, equivalence; duality                                    ← code 02
§6  substitution: valid templates, substitution of equivalents, useful tautologies                ← code 02
§7  how many connectives do we need? functional completeness and invariants                       ← code 03
§8  decision procedures: truth tables vs semantic arguments; soundness, completeness, cost         ← code 04
§9  a glimpse of deductive (Hilbert) systems
§10 modeling with propositional logic, and the exponential wall                                   ← code 05
§11 summary   §12 common pitfalls   §13 exercises   §14 further reading   §15 next lecture

Suggested order: §1 → §2 → run 01 (Parts 1–3) → §3 → run 01 (Parts 4–5) → §4–§6 → run 02 → §7 → run 03 → §8 → run 04 → §9 → §10 → run 05.

0.4 Notation (used throughout the course)

SymbolMeaning
p,q,r,p1,p2,…p, q, r, p_1, p_2, \dotspropositional variables (atoms)
⊤\top, ⊥\botthe constants true and false
¬,∧,∨,⇒,⇔\neg, \wedge, \vee, \Rightarrow, \Leftrightarrownot, and, or, implies, if and only if (connectives of the language)
α,β,γ,φ,ψ\alpha, \beta, \gamma, \varphi, \psi, also F,GF, Garbitrary formulas (metavariables: they are not symbols of the language)
II or vvan interpretation (variable assignment): variables → {true, false}
I⊨FI \models FII satisfies FF (FF is true under II); I⊭FI \not\models F: II falsifies FF
U⊨FU \models Fthe set of formulas UU entails FF; ⊨F\models F: FF is valid
F≡GF \equiv GFF and GG are logically equivalent
U⊢FU \vdash FFF is provable from UU in some proof system (§9)
FσF\sigmathe result of applying substitution σ\sigma to FF (§6)

In code and terminal output, the same symbols appear in Unicode (¬ ∧ ∨ ⇒ ⇔ ⊤ ⊥ ⊨ ⊭); the parser also accepts ASCII (~ & | -> <->).

0.5 About CS 257

  • Staff (Winter 2026): Caroline Trippel (faculty instructor), Hanna Lachnitt (student instructor), Rachel Cleaveland (TA).
  • Guest lectures: Clark Barrett, Leonardo de Moura, Mathias Preiner and Nina Narodytska.
  • Arc of the course: propositional logic and SAT; first-order logic and resolution; then first-order theories (arithmetic, arrays, bit-vectors, strings) and SMT solving; applications throughout (model checking, symbolic execution, proof assistants, SQL verification, program synthesis).
  • Coursework: three written homeworks (two with programming parts), a take-home midterm covering lectures 1–10, and a team project.
  • Learning objectives (from the course page): understand logical languages for encoding decision problems; understand and prove properties of the standard procedures (CDCL, DPLL(T), simplex, Nelson–Oppen); see their role in verification and synthesis; get hands-on experience with tools; get exposure to research.

0.6 The code of this course: build the reasoner yourself

Industrial solvers (MiniSat, CaDiCaL, Z3, cvc5) are large and fast. This course instead builds its own small reasoning stack, lecture by lecture, in plain Python, so that every algorithm can be read, traced and modified. Lecture 1 lays the foundation:

  • logic.py — formulas as immutable trees; a parser that accepts both Unicode and ASCII; printers (minimal parentheses, the official fully parenthesized syntax, ASCII, drawn trees); evaluation; and the truth-table method, implemented bit-parallel so that one Python integer holds a whole truth-table column (§8.3). Also substitution, random formulas and formula counting.
  • semantic_argument.py — the semantic-argument (tableau) method with printable, numbered proof trees, three strategies, an optional improvement, and a self-check that every counterexample really is one.

Every later lecture imports these instead of re-implementing them: CNF conversion in Lecture 2, DPLL in Lecture 4, CDCL in Lecture 5, bit-blasting in Lecture 16.


1. What is automated reasoning?

1.1 Inference, made mechanical

Reasoning means deriving consequences: from “if it rains, the street is wet” and “it rains”, conclude “the street is wet”. People do this informally and make mistakes; the goal of automated reasoning is to make a machine do it, reliably (never conclude something false) and fast.

The slides put it in one line: automated reasoning tries to automate the process of inference, deriving consequences of a given set of statements, where both the given and the derived knowledge are expressed in a formal language.

Three examples of the questions such a machine answers:

QuestionAs a reasoning problem
Does this 64-bit adder circuit compute a+ba + b for all inputs?Is “output ≠ a+ba+b” unsatisfiable? (§10.4)
Can these 7 regions be colored with 3 colors so that neighbours differ?Is the coloring formula satisfiable? (§10.3)
A says “B is a knave”, B says “A and C are of the same kind”. What is C?Does the knowledge base entail “C is a knave”? (§10.2)

All three have the same shape: is there an assignment of values that makes these constraints true? That question — satisfiability — is the backbone of this course.

1.2 Why a formal language?

English is ambiguous:

  • “You may have cake or ice cream” — one, or possibly both?
  • “I saw the man with the telescope” — who has the telescope?

A machine cannot reason reliably about sentences whose meaning is not fixed. A formal language has a precisely defined set of sentences (its syntax) and a precisely defined meaning for each one (its semantics). Its statements are also machine-processable: a program can read them, take them apart and compute with them.

The slides name the three ingredients of a formal logic:

IngredientWhat it fixesIn this lecture
syntaxa set of symbols and rules for combining them into formulas§2–3
semanticsa systematic, mathematical way of assigning meaning (truth) to formulas§4–6
proof systemformal rules of inference that derive formulas mechanically§8–9 (and Lecture 3)

Many logics exist, with different trade-offs between expressiveness (what can be said) and mechanizability (what can be decided automatically). The course starts with the simplest classical logic, propositional logic (PL): statements that are either true or false, combined with “not”, “and”, “or”, “if … then”, “if and only if”. Every other classical logic in the course extends it.

1.3 A short history

WhenWhoWhat
1670s–1680sLeibnizdreams of a calculus ratiocinator: settle disputes by calculation (“let us calculate”)
1847–1854Boolean algebra of logic: truth values as 0/1 with algebraic laws
1879Fregethe first formal logic with quantifiers (Begriffsschrift)
1921Post; Wittgensteintruth tables; Post proves propositional logic complete and studies which connectives suffice (§7)
1928Hilbert & Ackermannthe Entscheidungsproblem: is there an algorithm that decides validity in first-order logic?
1936Church; Turingno — first-order validity is undecidable (Lecture 8). Propositional validity is decidable (truth tables).
1960, 1962Davis & Putnam; Davis, Logemann & Lovelandthe DP and DPLL procedures for propositional satisfiability (Lectures 2, 4)
1965Robinsonresolution and unification for first-order logic (Lectures 2, 7, 8)
1971Cook (and Levin, 1973)SAT is NP-complete: probably no polynomial algorithm exists
1979Nelson & Oppencombining decision procedures for different theories (Lecture 18)
1996–2001Marques-Silva & Sakallah (GRASP); Moskewicz et al. (Chaff)conflict-driven clause learning (CDCL): SAT solving becomes industrially practical (Lecture 5)
2000s–nowmany groupsSMT solvers (Z3, cvc5, Yices, Bitwuzla, …) built on DPLL(T) (Lectures 10–18)

The striking point is the SAT paradox. SAT is NP-complete, so we expect worst cases that take exponential time; yet CDCL solvers routinely decide formulas from industry with millions of variables. Understanding why is one goal of the first five lectures.

1.4 Where it is used today (as reported by the people who use it)

  • Hardware verification. After the 1994 Pentium floating-point division bug, for which Intel reported a charge of about $475 million, formal verification became standard in processor design. Equivalence checking of circuits (§10.4, at toy scale) is routine.
  • Cloud security. Amazon Web Services reports that its SMT-based tools for reasoning about access policies issue on the order of a billion SMT queries a day (Rungta, CAV 2022).
  • Software. Symbolic execution and fuzzing tools ask solvers for inputs that reach buggy code (Lecture 14); bounded model checkers verify device drivers and protocols (Lecture 9).
  • Mathematics. SAT solvers settled open combinatorial problems, e.g. the Boolean Pythagorean triples problem (Heule, Kullmann & Marek, 2016), with a proof reported at about 200 terabytes. Proof assistants such as Lean use decision procedures to automate formal proofs (Lecture 15).
  • AI and programming. Synthesis tools generate code that provably meets a specification (Lecture 20); verification checks the output of language models, e.g. generated SQL (Lecture 19).

1.5 What “deciding” means, and the plan of this lecture

A decision procedure for a set UU of formulas is a procedure that, given any formula, always terminates and answers yes if the formula is in UU and no otherwise. This course builds decision procedures for UU = the valid formulas, or UU = the satisfiable formulas, in ever richer logics.

Before deciding anything we need the language (syntax, §2–3) and its meaning (semantics, §4–7). Then come the first two decision procedures (§8–9) and their limits (§10).


2. Syntax: what is a formula?

2.1 The alphabet

Atomic statements (atoms) are the smallest sentences. In ordinary language they might be “0 < 1”, “Iowa City is in Iowa” or “1 + 1 = 10”. Propositional logic does not look inside an atom: it only cares that an atom is either true or false. So atoms become plain names.

The alphabet of propositional logic consists of:

  1. atoms: the truth constants ⊤\top (true) and ⊥\bot (false), and propositional variables p,q,r,p1,p2,…p, q, r, p_1, p_2, \dots (a countably infinite supply);
  2. logical symbols: the connectives ¬,∧,∨,⇒,⇔\neg, \wedge, \vee, \Rightarrow, \Leftrightarrow and the parentheses ( and ).

The slides warn that parentheses live at three levels of discourse: inside formulas, as in (p⇒q)(p \Rightarrow q); in ordinary mathematical notation, as in f(x)f(x); and in English text (like this one). Keep them apart.

2.2 Formula-building operators and the inductive definition

A sentence is a finite sequence of symbols, but most sequences are nonsense: (p ∧ ∨ q), p q, )) ⇔) s. Syntax rules pick out the meaningful ones. The slides define five formula-building operators, for all formulas α,β\alpha, \beta:

E¬(α)=(¬α),E∧(α,β)=(α∧β),E∨(α,β)=(α∨β),E⇒(α,β)=(α⇒β),E⇔(α,β)=(α⇔β).\mathcal{E}_\neg(\alpha) = (\neg\alpha),\quad \mathcal{E}_\wedge(\alpha,\beta) = (\alpha \wedge \beta),\quad \mathcal{E}_\vee(\alpha,\beta) = (\alpha \vee \beta),\quad \mathcal{E}_\Rightarrow(\alpha,\beta) = (\alpha \Rightarrow \beta),\quad \mathcal{E}_\Leftrightarrow(\alpha,\beta) = (\alpha \Leftrightarrow \beta).

The set WW of well-formed formulas (wffs) is defined by three clauses:

  1. every atom is a wff;
  2. if α\alpha and β\beta are wffs, so are E¬(α)\mathcal{E}_\neg(\alpha), E∧(α,β)\mathcal{E}_\wedge(\alpha,\beta), …, E⇔(α,β)\mathcal{E}_\Leftrightarrow(\alpha,\beta);
  3. nothing else is a wff.

Why define formulas this way? Three reasons, each of which pays off later:

  • A finite description of an infinite set. There are infinitely many formulas; five operators and one base set describe all of them.
  • A built-in recipe for algorithms. Any function on formulas can be defined by one case for atoms and one case per operator (structural recursion, §3.4). The evaluator, the printer, the size function and every solver of the course are written that way.
  • A built-in recipe for proofs. Any property can be proved for all formulas by checking atoms and checking that each operator preserves it (structural induction, §3.1).

Clause 3 is what makes induction work: if anything else were allowed into WW, a property preserved by the operators might still fail for the intruders.

2.3 Closed sets and generated sets

The slides make “nothing else” precise with two notions:

  • A set SS is closed under a set FF of operators if applying any operator of FF to elements of SS gives an element of SS. For example, N\mathbb{N} is closed under ++ and ×\times but not under negation; the odd integers are closed under ×\times and negation but not ++.
  • A set CC is generated from a base set BB by FF if CC is the smallest set that contains BB and is closed under FF. For example, N\mathbb{N} is generated from {0,1}\{0, 1\} by {+}\{+\}; Z\mathbb{Z} is generated from {1}\{1\} by {+,−}\{+, -\}. The reals are generated from no countable base by such operators, because generated sets are always countable.

So WW is the set generated from the atoms by the five formula-building operators. “Smallest” is exactly clause 3.

2.4 Notational conventions

The official syntax is unreadable in bulk: ((p1∧p2)⇒((¬p3)∨p4))((p_1 \wedge p_2) \Rightarrow ((\neg p_3) \vee p_4)). The slides adopt conventions that drop parentheses:

  • outermost parentheses may be omitted;
  • precedence: ¬\neg binds most strongly (with smallest possible scope), then ∧\wedge, then ∨\vee, then ⇒\Rightarrow and ⇔\Leftrightarrow. We follow CC and also put ⇒\Rightarrow above ⇔\Leftrightarrow, so ⇔\Leftrightarrow binds most weakly;
  • binary connectives associate to the right: p1∧p2∧p3p_1 \wedge p_2 \wedge p_3 means p1∧(p2∧p3)p_1 \wedge (p_2 \wedge p_3).

These are abbreviations only: each conventional string stands for exactly one official formula. Script 01, Part 2 shows the parser’s reading of typical strings:

you writethe parser reads (official syntax)main connective
¬p ∧ q((¬p) ∧ q)∧
¬(p ∧ q)(¬(p ∧ q))¬
p1 ∧ p2 ∨ p3((p1 ∧ p2) ∨ p3)∨
p1 ∧ p2 ⇒ ¬p3 ∨ p4((p1 ∧ p2) ⇒ ((¬p3) ∨ p4))⇒
p ⇒ q ⇒ r(p ⇒ (q ⇒ r))⇒
p ⇔ q ⇒ r(p ⇔ (q ⇒ r))⇔

Our printer keeps the redundant parentheses in p⇒(q⇒r)p \Rightarrow (q \Rightarrow r) and p⇔(q⇔r)p \Leftrightarrow (q \Leftrightarrow r): people misread right-nested implications far more often than parsers do.

2.5 Parse trees: the meaning belongs to the tree

The main connective of a formula is the last operator applied when building it. Drawing a formula with its main connective at the root, and recursing into the operands, gives its parse tree. Script 01 prints the tree of p1∧p2⇒¬p3∨p4p_1 \wedge p_2 \Rightarrow \neg p_3 \vee p_4:

⇒
├── ∧
│   ├── p1
│   └── p2
└── ∨
    ├── ¬
    │   └── p3
    └── p4

Every algorithm in this course works on trees (or DAGs, §10.6), never on strings. The string is only a way to write the tree down.

Parentheses can change the tree, and with it the meaning. Script 01 compares three pairs, counting models (the rows of the truth table where the formula is true; §4):

formula A#modelsformula B#modelsa row where they differ
(p ⇒ q) ⇒ r5p ⇒ (q ⇒ r)7p=0, q=0, r=0
¬(p ∧ q)3¬p ∧ q1p=0, q=0
(p ∨ q) ∧ r3p ∨ q ∧ r5p=1, q=0, r=0

2.6 Unique readability: why the language must fix one tree per string

Imagine a language without parentheses or conventions. The flat string p ∧ q ∨ r ⇒ s could then be read as any of the 5 trees with those leaves and connectives in that order (script 01, Part 3). Each tree has a different number of models (7, 5, 13, 13, 11 of 16), and in fact 5 different truth tables. The conventions select ((p∧q)∨r)⇒s((p \wedge q) \vee r) \Rightarrow s.

With kk binary connectives a flat string has Catalan(k)\text{Catalan}(k) trees: 1, 2, 5, 14, 42, …, 208,012 for k=12k = 12. A sentence with several meanings has no single truth value, so a formal language must fix one tree per string. The official syntax does it with mandatory parentheses, the conventions with precedence and associativity.

That every wff of the official syntax is built in exactly one way is the unique readability theorem (MI §1.3). Its key lemma: every proper initial segment of a non-atomic wff has more left than right parentheses. So the parentheses balance only at the very end, and a parser always knows where the main operator’s operands stop. Script 01 checks this lemma on 5,000 random formulas (Part 4).

Run it. python3 01_syntax_and_parse_trees.py (about 2 seconds).

  • Part 1 shows the parser accepting (p ∧ q) and ((¬p) ⇒ r) and rejecting the slides’ non-formulas, with a caret under the offending symbol, e.g. expected a formula, found '∨'.
  • Part 2 prints the table of §2.4 and the parse tree above.
  • Part 3 lists the 5 trees of p ∧ q ∨ r ⇒ s and the Catalan numbers.

A detail of our concrete syntax: variable names may be longer than one letter, so pq (no space) is the single variable named pq. In the slides’ alphabet, pq is two symbols in a row, which no operator produces. Our parser rejects the spaced version p q with “unexpected ‘q’ after a complete formula”.


3. Structural induction and structural recursion

3.1 The principle

Let CC be generated from BB by the operators FF. Call a set SS inductive with respect to CC if S⊇BS \supseteq B and SS is closed under FF. Since CC is the smallest such set, C⊆SC \subseteq S.

To prove that every element of CC has a property PP:

  1. let SS be the set of things that have PP;
  2. show SS is inductive: (a) every element of BB has PP (base case); (b) if the inputs of an operator have PP, so does its output (inductive step, using the induction hypothesis for the inputs);
  3. conclude C⊆SC \subseteq S: everything in CC has PP.

For formulas this reads: prove PP for atoms; prove that ¬\neg and each binary connective preserve PP; conclude PP for all formulas. It is ordinary induction on natural numbers generalized from “+1” to the formula-building operators.

3.2 Example from the slides: parentheses balance

Claim. Every wff of the official syntax has as many left parentheses as right parentheses.

Proof. Let l(α)l(\alpha) and r(α)r(\alpha) count them, and let S={α:l(α)=r(α)}S = \{\alpha : l(\alpha) = r(\alpha)\}.

  • Base: an atom has no parentheses, l=r=0l = r = 0.
  • Step ¬\neg: l((¬α))=1+l(α)=1+r(α)=r((¬α))l((\neg\alpha)) = 1 + l(\alpha) = 1 + r(\alpha) = r((\neg\alpha)), using the induction hypothesis l(α)=r(α)l(\alpha) = r(\alpha).
  • Step ∧\wedge: l((α∧β))=1+l(α)+l(β)=1+r(α)+r(β)=r((α∧β))l((\alpha \wedge \beta)) = 1 + l(\alpha) + l(\beta) = 1 + r(\alpha) + r(\beta) = r((\alpha \wedge \beta)). The other binary connectives are identical.

So SS is inductive and contains every wff. ∎

3.3 A second example, used again in Lecture 2

Claim. In every formula (tree), the number of atom occurrences equals the number of binary connectives plus one.

Proof.

  • Base: an atom has 1 atom occurrence and 0 binary connectives: 1=0+11 = 0 + 1.
  • Step ¬α\neg\alpha: adds neither atoms nor binary connectives.
  • Step α∘β\alpha \circ \beta: atoms(α)+atoms(β)=(bin(α)+1)+(bin(β)+1)=(bin(α)+bin(β)+1)+1=bin(α∘β)+1\text{atoms}(\alpha) + \text{atoms}(\beta) = (\text{bin}(\alpha) + 1) + (\text{bin}(\beta) + 1) = (\text{bin}(\alpha) + \text{bin}(\beta) + 1) + 1 = \text{bin}(\alpha \circ \beta) + 1. ∎

Script 01, Part 4 checks seven such properties on 5,000 random formulas (sizes 1 to 60 nodes, mean 27.3): the two above, the prefix lemma of §2.6, the round trips parse(print(f)) == f in three notations, and size≤2depth+1−1\text{size} \le 2^{\text{depth}+1} - 1. Zero violations each.

Zero violations is evidence, not proof. Five thousand formulas are a vanishing fraction of infinitely many; structural induction covers all of them at once. Conversely, a single violation would have been a genuine counterexample — that asymmetry between proofs and tests runs through the whole course.

3.4 Structural recursion: induction’s twin

The same pattern defines functions. One case per atom kind, one case per connective, each allowed to use the function’s values on the children:

size(p)=1,size(¬α)=1+size(α),size(α∘β)=1+size(α)+size(β).\mathrm{size}(p) = 1,\qquad \mathrm{size}(\neg\alpha) = 1 + \mathrm{size}(\alpha),\qquad \mathrm{size}(\alpha \circ \beta) = 1 + \mathrm{size}(\alpha) + \mathrm{size}(\beta).

Unique readability guarantees such definitions are well defined: a formula is built in only one way, so only one case applies. In logic.py, size, depth, variables, subformulas, to_str, evaluate and table_bits are all structural recursions. So, in later lectures, are the CNF conversion, the Tseitin encoding and the bit-blaster.

3.5 Infinitely many formulas, finitely many meanings

How many formulas are there? A dynamic program over the inductive definition counts the trees of each size (script 01, Part 5). With two variables there are 312,501,026 formulas of size 13; with three, 3,707,218,155. The count grows without bound.

How many different meanings? Over nn variables a formula’s meaning is its truth table: one bit per row, 2n2^n rows, hence at most 22n2^{2^n} meanings — 16 for n=2n = 2, 256 for n=3n = 3. Running the same dynamic program on truth tables instead of formulas shows how fast the meanings are reached:

variablespossible meaningsall reached by sizeformulas of size 13
2164312,501,026
3256103,707,218,155

Number of formulas vs number of meanings

Most formulas are redundant rewrites of a few meanings. This finiteness is why propositional logic is decidable: a formula over nn variables can be judged by checking finitely many (2n2^n) rows (§8.3). In first-order logic (Lecture 6) the meaning of a formula can depend on infinitely many objects, and this argument breaks.


4. Semantics: when is a formula true?

4.1 Interpretations

An atom’s truth depends on what it stands for. The slides’ example: “1 + 1 = 10” is false if the numerals are read in decimal, true if they are read in binary. Propositional logic deliberately ignores why an atom is true. It only asks: given a truth value for each variable, what is the truth value of the formula?

An interpretation (variable assignment, truth assignment) is a function II from variables to {true,false}\{\text{true}, \text{false}\}. It extends to all formulas by structural recursion — the compositional semantics:

formulatrue under II iff
⊤\topalways
⊥\botnever
ppI(p)=trueI(p) = \text{true}
¬α\neg\alphaα\alpha is false under II
α∧β\alpha \wedge \betaboth α\alpha and β\beta are true
α∨β\alpha \vee \betaat least one of them is true (inclusive or)
α⇒β\alpha \Rightarrow \betaα\alpha is false, or β\beta is true
α⇔β\alpha \Leftrightarrow \betaα\alpha and β\beta have the same value

We write I⊨αI \models \alpha (”II satisfies α\alpha”, ”II is a model of α\alpha”) when α\alpha is true under II, and I⊭αI \not\models \alpha otherwise.

Why compositional? The value of a formula depends only on the connective and the values of its immediate subformulas. This single property is what makes truth tables possible, what lets solvers replace a subformula by an equivalent one (§6), and what lets SAT solvers reason locally, one clause at a time.

4.2 Seeing compositionality

Script 02, Part 1 evaluates the slides’ formula α=(p∧q)⇒(p∨¬q)\alpha = (p \wedge q) \Rightarrow (p \vee \neg q) under I={p↦true,q↦false}I = \{p \mapsto \text{true}, q \mapsto \text{false}\}, printing every subformula after its children:

subformulavaluerule
p1given by II
q0given by II
p ∧ q0true iff both sides are true
¬q1¬ flips the value of q
p ∨ ¬q1true iff at least one side is true
p ∧ q ⇒ p ∨ ¬q1false only if left is true and right is false

The same script evaluates a few formulas with the atom ee = “1 + 1 = 10” under the decimal reading (ee false) and the binary reading (ee true). e∨¬ee \vee \neg e is true under both; e∧de \wedge d flips. Some formulas are true because of their form alone, whatever their atoms mean. Those are the valid formulas, and recognizing them is the central task of the course.

4.3 The puzzle of material implication

Students often object to the row “false ⇒ anything is true”. Why define ⇒\Rightarrow that way?

  • It is the only choice that makes ⇒\Rightarrow a promise. Read α⇒β\alpha \Rightarrow \beta as “I promise that whenever α\alpha holds, β\beta holds”. The promise is broken only when α\alpha holds and β\beta does not. If α\alpha is false, nothing was promised, so nothing was broken.
  • It makes valid patterns valid. “For every number xx: if x>2x > 2 then x>1x > 1” should be true. For x=0x = 0 the instance reads "0>2⇒0>10 > 2 \Rightarrow 0 > 1", false ⇒ false, and it must come out true or the general statement would fail.
  • It is truth-functional. Everyday “if” often carries causation or relevance (“if you heat it, it melts”). Propositional logic cannot express those, because it only sees truth values. It keeps the truth-functional core, which is what the rest of mathematics uses.

Equivalently, α⇒β≡¬α∨β\alpha \Rightarrow \beta \equiv \neg\alpha \vee \beta — a law used constantly from Lecture 2 on (script 02, Part 6 verifies it).

4.4 Truth tables

With nn variables there are 2n2^n interpretations. Listing all of them with the value of every subformula gives the truth table. The slides’ example (script 02, Part 2):

p  q  p ∧ q  ¬q  p ∨ ¬q  p ∧ q ⇒ p ∨ ¬q
-  -  -----  --  ------  --------------
0  0    0    1     1           1
0  1    0    0     0           1
1  0    0    1     1           1
1  1    1    0     1           1

α\alpha is true in all 4 rows: valid. Rows are listed in the order of the slides — all false first, the last variable changing fastest — which is also the order of the binary numbers 0 to 2n−12^n - 1. Our code uses that correspondence to store whole columns in one integer (§8.3).


5. Satisfiability, validity, entailment, equivalence

5.1 Four properties of a single formula

A formula α\alpha is …if …
satisfiableI⊨αI \models \alpha for some II
falsifiableI⊭αI \not\models \alpha for some II
valid (a tautology), written ⊨α\models \alphaI⊨αI \models \alpha for every II
unsatisfiable (a contradiction)I⊭αI \not\models \alpha for every II

A set of formulas UU is satisfiable if one interpretation satisfies all its members at once.

Every formula is in exactly one of three classes: valid (all rows true), unsatisfiable (no row true), or contingent (some of each). So valid ⊂ satisfiable, unsatisfiable ⊂ falsifiable, and contingent = satisfiable ∩ falsifiable.

Script 02, Part 3 classifies the slides’ examples and a few more:

formula#vars#modelsclass
p11/2contingent
p ⇒ q23/4contingent
p ∨ ¬q23/4contingent
(p ⇒ q) ⇒ p22/4contingent
p ⇒ p, p ∨ ¬p12/2valid
p ⇒ (q ⇒ p)24/4valid
((p ⇒ q) ⇒ p) ⇒ p24/4valid (Peirce’s law)
⊤01/1valid
⊥, p ∧ ¬p0, 10/1, 0/2unsatisfiable
(p ⇒ q) ∧ p ∧ ¬q20/4unsatisfiable

Two small surprises:

  • Peirce’s law is valid although it mentions qq, which seems to play no role.
  • ⊤\top and ⊥\bot have zero variables, so their table has 20=12^0 = 1 row.

5.2 Entailment and equivalence

Validity is about one formula. Reasoning is about consequences:

  • A set UU entails β\beta, written U⊨βU \models \beta, if every interpretation that satisfies all of UU also satisfies β\beta. We also say β\beta is a logical consequence of UU.
  • α\alpha and β\beta are equivalent, α≡β\alpha \equiv \beta, if α⊨β\alpha \models \beta and β⊨α\beta \models \alpha: same value in every row.

The symbol ⊨\models is overloaded: I⊨αI \models \alpha relates an interpretation and a formula; U⊨αU \models \alpha relates a set of formulas and a formula. Context disambiguates. Neither is a connective. α⊨β\alpha \models \beta and α≡β\alpha \equiv \beta are statements about formulas (in the metalanguage), not formulas.

Script 02, Part 4 tests inference patterns. The variable version of each pattern is decided by truth table; then 1,000 random formulas are substituted for α,β,γ\alpha, \beta, \gamma:

patternholds?counterexamplerandom instances that hold
{α, α ⇒ β} ⊨ β (modus ponens)yes–100.0%
{α ⇒ β, ¬β} ⊨ ¬α (modus tollens)yes–100.0%
{α ⇒ β, β ⇒ γ} ⊨ α ⇒ γ (chaining)yes–100.0%
{α ∨ β, ¬α} ⊨ β (disjunctive syllogism)yes–100.0%
{α ⇒ β, β} ⊨ α (affirming the consequent)noa=0, b=119.4%
{α ⇒ β, ¬α} ⊨ ¬β (denying the antecedent)noa=0, b=120.4%
α ∨ β ⊨ αnoa=0, b=119.2%

A sound pattern holds for every instance. A fallacy fails on plain variables, yet about a fifth of its random instances happen to hold — for example when the substituted α\alpha is itself valid. Not a valid pattern does not mean never true; it means not true by form alone.

5.3 Duality: one procedure decides everything

The key theorems of this section (the slides prove the first; the others follow the same way):

α is valid  ⟺  ¬α is unsatisfiableα⊨β  ⟺  ⊨α⇒β  ⟺  α∧¬β is unsatisfiableα≡β  ⟺  ⊨α⇔β  ⟺  ¬(α⇔β) is unsatisfiable{α1,…,αk}⊨β  ⟺  α1∧⋯∧αk∧¬β is unsatisfiable\begin{aligned} &\alpha \text{ is valid} &&\iff \neg\alpha \text{ is unsatisfiable}\\ &\alpha \models \beta &&\iff \models \alpha \Rightarrow \beta &&\iff \alpha \wedge \neg\beta \text{ is unsatisfiable}\\ &\alpha \equiv \beta &&\iff \models \alpha \Leftrightarrow \beta &&\iff \neg(\alpha \Leftrightarrow \beta) \text{ is unsatisfiable}\\ &\{\alpha_1, \dots, \alpha_k\} \models \beta &&\iff \alpha_1 \wedge \dots \wedge \alpha_k \wedge \neg\beta \text{ is unsatisfiable} \end{aligned}

Proof of the second. α⊨β\alpha \models \beta means: no row has α\alpha true and β\beta false. α⇒β\alpha \Rightarrow \beta is false exactly in the rows where α\alpha is true and β\beta false. So “no such row” is ”α⇒β\alpha \Rightarrow \beta is true in every row”. ∎

The consequence shapes the whole course: a procedure for satisfiability decides validity, entailment and equivalence too — just negate. That is why the rest of the course builds SAT and SMT solvers, and why a counterexample to a claimed entailment is simply a model of α∧¬β\alpha \wedge \neg\beta.

Script 02, Part 5 checks all five theorem forms on 4,000 random pairs: 4,000 / 4,000 agreements each. (Among those pairs α⊨β\alpha \models \beta held 1,158 times and α≡β\alpha \equiv \beta 131 times, so both directions were exercised.)

5.4 How common is validity?

The same part classifies random formulas over p,q,rp, q, r by size (600 per size):

#connectivesvalidcontingentunsatisfiable
211.5%83.8%4.7%
1013.7%81.0%5.3%
2015.0%78.2%6.8%
3016.3%75.8%7.8%

Classification of random formulas vs size

Most random formulas are contingent. Valid ones outnumber unsatisfiable ones about 2 : 1, because ∨\vee and ⇒\Rightarrow are true in 3 of 4 rows while only ∧\wedge is true in 1. The exact percentages depend on the generator — there is no canonical “random formula”. (Random CNF formulas, Lecture 4, have a much more dramatic behaviour: a sharp threshold between satisfiable and unsatisfiable.)


6. Substitution

6.1 Definition (CC §1.5)

A substitution is a finite map σ={F1↦G1,…,Fk↦Gk}\sigma = \{F_1 \mapsto G_1, \dots, F_k \mapsto G_k\} from formulas to formulas. FσF\sigma replaces every occurrence of each FiF_i in FF by GiG_i. Two details matter:

  • replacements are simultaneous: {p↦q,q↦p}\{p \mapsto q, q \mapsto p\} swaps pp and qq; the qq put in for pp is not replaced again;
  • when both a formula and one of its subformulas are in the domain, the larger one is replaced (the replacement works top-down).

A substitution whose domain contains only variables is a variable substitution. In code: substitute(f, {"p": parse("q ∧ r")}).

6.2 Valid templates (CC Prop. 1.18)

Theorem. If FF is valid and σ\sigma is a variable substitution, then FσF\sigma is valid.

Why. Take any interpretation II. Define J(p)=J(p) = the value of pσp\sigma under II. By structural induction, the value of FσF\sigma under II equals the value of FF under JJ. Since FF is valid, that value is true. ∎

So each valid formula over a,b,ca, b, c is a template that stands for infinitely many valid formulas. The slides’ “useful tautologies” are such templates. Script 02, Part 6 checks each law and then 500 random instances of it:

lawtemplatevalid?random instances valid
distributivitya ∧ (b ∨ c) ⇔ (a ∧ b) ∨ (a ∧ c)yes500/500
implication(a ⇒ b) ⇔ (¬a ∨ b)yes500/500
negated implication¬(a ⇒ b) ⇔ (a ∧ ¬b)yes500/500
contraposition(a ⇒ b) ⇔ (¬b ⇒ ¬a)yes500/500
exportation((a ∧ b) ⇒ c) ⇔ (a ⇒ (b ⇒ c))yes500/500
De Morgan¬(a ∧ b) ⇔ (¬a ∨ ¬b), ¬(a ∨ b) ⇔ (¬a ∧ ¬b)yes500/500
NOT a law: converse(a ⇒ b) ⇔ (b ⇒ a)no13/500

The script checks 13 laws in all, including associativity, both distributive laws, double negation, excluded middle and negated equivalence. Every valid one gives 500/500.

The same argument shows that substitution preserves unsatisfiability — but not contingency. The contingent p∨qp \vee q becomes valid under {q↦¬p}\{q \mapsto \neg p\}, unsatisfiable under {p↦⊥,q↦⊥}\{p \mapsto \bot, q \mapsto \bot\}, and stays contingent under {p↦p∧q}\{p \mapsto p \wedge q\}.

6.3 Substitution of equivalents (CC Prop. 1.16)

Theorem. If Gi≡HiG_i \equiv H_i for all ii, then F{G1↦H1,… }≡FF\{G_1 \mapsto H_1, \dots\} \equiv F.

Why. By compositionality (§4.1): under any interpretation, the replaced subformulas have the same values as the originals, so every enclosing subformula has the same value too (induction on FF). ∎

Script 02 tests it 2,000 times: pick a random formula, pick one of its subformulas, rewrite that subformula’s top connective with a standard law (e.g. α⇒β\alpha \Rightarrow \beta ↦ ¬α∨β\neg\alpha \vee \beta), and substitute. The result differs syntactically in all 2,000 cases and is equivalent in all 2,000. A control replaces p⇒qp \Rightarrow q by its converse q⇒pq \Rightarrow p inside (p⇒q)∧r(p \Rightarrow q) \wedge r: not equivalent.

Why solvers care. This theorem licenses every simplification and normal form a solver applies before solving (Lecture 2): rewriting ⇒\Rightarrow away, pushing ¬\neg inward, flattening. Each step replaces a part by an equivalent part, so the whole keeps its meaning.


7. How many connectives do we need?

7.1 Defining connectives from others

A binary connective ∘\circ is defined from a set CC of connectives if α∘β≡γ\alpha \circ \beta \equiv \gamma for some γ\gamma built from α,β\alpha, \beta with connectives in CC only. The slides show that ∨,∧,⇔\vee, \wedge, \Leftrightarrow can be defined from {¬,⇒}\{\neg, \Rightarrow\}:

α∧β≡¬(α⇒¬β),α∨β≡¬α⇒β,α⇔β≡¬((α⇒β)⇒¬(β⇒α)).\alpha \wedge \beta \equiv \neg(\alpha \Rightarrow \neg\beta),\qquad \alpha \vee \beta \equiv \neg\alpha \Rightarrow \beta,\qquad \alpha \Leftrightarrow \beta \equiv \neg\big((\alpha \Rightarrow \beta) \Rightarrow \neg(\beta \Rightarrow \alpha)\big).

Why care?

  • Proofs by structural induction get shorter: fewer connectives, fewer cases.
  • Algorithms work on normal forms over a small fixed set: CNF uses {¬,∧,∨}\{\neg, \wedge, \vee\}; hardware tools use and-inverter graphs, {∧,¬}\{\wedge, \neg\}.

7.2 Functional completeness

There are 222=162^{2^2} = 16 truth functions of two variables (script 03, Part 1). Only four are binary connectives of our syntax; XOR, NAND, NOR and the rest must be built.

A set CC is functionally complete if every truth function, of any number of variables, is expressed by some formula over CC.

{¬,∧,∨}\{\neg, \wedge, \vee\} is complete. For each row where the function is true, write the conjunction of literals describing that row; take the disjunction of those conjunctions. This is the disjunctive normal form of Lecture 2. Since ∨\vee is definable from {¬,∧}\{\neg, \wedge\}, so is everything.

Script 03, Part 2 computes, for each set of connectives, how many of the 256 truth tables over p,q,rp, q, r it can build. Each set starts from the three variable columns and applies the connectives until nothing new appears:

connectivesreachedcomplete?every reachable function is …
{¬, ∧}, {¬, ∨}, {¬, ⇒}256/256yes–
{⇒, ⊥}256/256yes–
{NAND}, {NOR}256/256yes–
{⊕, ∧, ⊤}256/256yes–
{∧, ∨}18/256no⊤-preserving, ⊥-preserving, monotone
{∧, ∨, ⇒, ⇔}128/256no⊤-preserving
{⇒}38/256no⊤-preserving
{¬, ⇔}, {⇔, ⊥}16/256noaffine
{∧, ∨, ⊤, ⊥}20/256nomonotone

7.3 Proving incompleteness: find an invariant

How do we prove that no formula over {∧,∨,⇒,⇔}\{\wedge, \vee, \Rightarrow, \Leftrightarrow\} expresses ¬p\neg p? Find a property that every variable has and every connective preserves; then structural induction gives it to every formula.

Invariant: “true under the all-true interpretation”.

  • Base: every variable is true there.
  • Step: each of ∧,∨,⇒,⇔\wedge, \vee, \Rightarrow, \Leftrightarrow maps (true, true) to true.

So every formula over these connectives is true under the all-true interpretation, while ¬p\neg p is false there. ∎

The last column of the table lists, for each incomplete set, the invariants it cannot escape. Post’s theorem (1941) says these five invariants are the only obstacles. A set of connectives is complete iff, for each of the five classes below, some connective of the set lies outside it:

classproperty of ff
⊤-preservingf(1,…,1)=1f(1, \dots, 1) = 1
⊥-preservingf(0,…,0)=0f(0, \dots, 0) = 0
monotonechanging an input from 0 to 1 never changes the output from 1 to 0
self-dualf(¬x)=¬f(x)f(\neg x) = \neg f(x)
affineff is an XOR of some inputs, possibly negated

For example, {¬,⇔}\{\neg, \Leftrightarrow\} only builds affine functions: α⇔β=α⊕β⊕1\alpha \Leftrightarrow \beta = \alpha \oplus \beta \oplus 1, and XORs of XORs stay XORs. So it can never build p∧qp \wedge q. This “find an invariant, prove it by induction” pattern returns in Lecture 3, where the invariant is “every derived formula is valid” (soundness of a proof system).

7.4 The price of a small basis

Every complete basis reaches everything — at a price in formula size. Script 03, Part 3 finds the smallest formula for each truth function by dynamic programming over truth tables:

function{¬, ∧, ∨, ⇒, ⇔}{¬, ⇒}{NAND} (↑){¬, ∧}
p ∧ q3: p ∧ q5: ¬(p ⇒ ¬q)7: (p ↑ q) ↑ (p ↑ q)3: p ∧ q
p ∨ q3: p ∨ q4: ¬p ⇒ q7: (p ↑ p) ↑ (q ↑ q)6: ¬(¬p ∧ ¬q)
p ⊕ q4: ¬(p ⇔ q)8: (p ⇒ q) ⇒ ¬(q ⇒ p)1111: ¬(p ∧ q) ∧ ¬(¬p ∧ ¬q)

Averaged over all functions:

basismean smallest size, 2 variablesmean, 3 variableslargest, 3 variables
{¬, ∧, ∨, ⇒, ⇔}3.006.1610
{¬, ⇒}3.889.3422
{NAND}6.7513.1929
{¬, ∧}4.5611.7530

The slides’ identities appear as the smallest formulas over {¬,⇒}\{\neg, \Rightarrow\}. Solvers accept the size penalty on purpose: one small internal language means fewer cases in every algorithm and every correctness proof. Users, meanwhile, keep a rich input language.

Run it. python3 03_connectives_and_expressiveness.py (well under a second): the 16 functions, the closure table with Post’s invariants, and the smallest formulas.


8. Decision procedures: truth tables and semantic arguments

8.1 What we want

A decision procedure for validity takes any formula and, after finitely many steps, answers valid or not valid, correctly. A procedure need not terminate; an algorithm (and a decision procedure) must.

The slides name two fundamental strategies:

  • search: explore the space of interpretations, looking for a counterexample;
  • deduction: apply inference rules to derive validity (or a contradiction).

Modern SAT solvers interleave both (Lectures 4–5). This section builds one pure representative of each.

8.2 The truth-table method

Enumerate all 2n2^n interpretations and evaluate. It is correct and always terminates, because nn is finite. Its costs:

  • time grows like 2n2^n — every row must be visited to conclude valid or unsatisfiable;
  • memory can be tiny: one row at a time.

8.3 The bit-parallel trick (and why it changes nothing)

logic.py implements the truth-table method with one idea from hardware simulation. Store a whole column of the truth table as a single integer, whose bit rr is the value in row rr. Then one integer operation evaluates a connective on all rows at once:

¬a=FULL⊕a,a∧b=a & b,a∨b=a∣b,a⇒b=(FULL⊕a)∣b,a⇔b=FULL⊕(a⊕b)\neg a = \mathrm{FULL} \oplus a,\quad a \wedge b = a \,\&\, b,\quad a \vee b = a \mid b,\quad a \Rightarrow b = (\mathrm{FULL} \oplus a) \mid b,\quad a \Leftrightarrow b = \mathrm{FULL} \oplus (a \oplus b)

Here FULL has all 2n2^n bits set. The column of variable ii is a periodic bit pattern (2n−1−i2^{n-1-i} zeros, then as many ones, repeated). Python integers have unlimited size, so 24 variables means 16.7-million-bit integers.

This makes each row cost a fraction of a machine instruction instead of a Python function call — a large constant factor (§10.5 measures it). It does not touch the 2n2^n. Bit-parallelism moves the wall; it does not remove it.

8.4 The semantic argument method: idea

Instead of checking every row, reason about a hypothetical counterexample:

  1. To show FF is valid, assume the opposite: some interpretation II has I⊭FI \not\models F.
  2. Unfold what that assumption forces, one connective at a time. "I⊭A∧BI \not\models A \wedge B" forces ”I⊭AI \not\models A or I⊭BI \not\models B”: two cases. "I⊭A⇒BI \not\models A \Rightarrow B" forces ”I⊨AI \models A and I⊭BI \not\models B”: one case.
  3. A case that contains both I⊨GI \models G and I⊭GI \not\models G is impossible: it is closed.
  4. If every case closes, no counterexample exists: FF is valid. If a case can no longer be unfolded and is not closed, it is open, and its atomic facts describe an interpretation that really falsifies FF.

This is the semantic argument of CC §1.3.2 and the slides’ “proof by deduction”. In the literature it is called the analytic tableau method (Beth, Smullyan).

The rules (semantic_argument.py), named after the connective and the sign:

judgementruleconclusionskind
I⊨¬AI \models \neg A¬⊨I⊭AI \not\models Alinear
I⊭¬AI \not\models \neg A¬⊭I⊨AI \models Alinear
I⊨A∧BI \models A \wedge B∧⊨I⊨AI \models A, I⊨BI \models Blinear
I⊭A∧BI \not\models A \wedge B∧⊭I⊭AI \not\models A or I⊭BI \not\models Bbranching
I⊨A∨BI \models A \vee B∨⊨I⊨AI \models A or I⊨BI \models Bbranching
I⊭A∨BI \not\models A \vee B∨⊭I⊭AI \not\models A, I⊭BI \not\models Blinear
I⊨A⇒BI \models A \Rightarrow B⇒⊨I⊭AI \not\models A or I⊨BI \models Bbranching
I⊭A⇒BI \not\models A \Rightarrow B⇒⊭I⊨AI \models A, I⊭BI \not\models Blinear
I⊨A⇔BI \models A \Leftrightarrow B⇔⊨(I⊨AI \models A, I⊨BI \models B) or (I⊭AI \not\models A, I⊭BI \not\models B)branching
I⊭A⇔BI \not\models A \Leftrightarrow B⇔⊭(I⊨AI \models A, I⊭BI \not\models B) or (I⊭AI \not\models A, I⊨BI \models B)branching
I⊨GI \models G and I⊭GI \not\models G on one branch (or I⊨⊥I \models \bot, or I⊭⊤I \not\models \top)⊥the branch is closed

Each rule simply reads the truth table of its connective backwards. For instance, ⇒ is false in exactly one row, so "I⊭A⇒BI \not\models A \Rightarrow B" pins down both sides. Linear rules are called α-rules and branching rules β-rules.

8.5 The slides’ two examples, built by machine

Example 1: is p∧¬qp \wedge \neg q valid? (script 04, Part 1)

1. I ⊭ p ∧ ¬q                          assumption
├─ case 1 of 2  (∧⊭ on 1)
│  2. I ⊭ p                            ∧⊭ on 1
│  ○ open: p ↦ false  (q arbitrary)
└─ case 2 of 2  (∧⊭ on 1)
   3. I ⊭ ¬q                           ∧⊭ on 1
   4. I ⊨ q                            ¬⊭ on 3
   ○ open: q ↦ true  (p arbitrary)

Both cases stay open: p∧¬qp \wedge \neg q is not valid. The open cases describe the falsifying interpretations {p↦false}\{p \mapsto \text{false}\} and {q↦true}\{q \mapsto \text{true}\}, with the other variable arbitrary — three of the four rows, found without listing rows. The script checks all 4 completions by evaluation (0 failures).

Example 2: is (p⇒q)∧(q⇒r)⇒(p⇒r)(p \Rightarrow q) \wedge (q \Rightarrow r) \Rightarrow (p \Rightarrow r) valid?

1. I ⊭ (p ⇒ q) ∧ (q ⇒ r) ⇒ (p ⇒ r)           assumption
2. I ⊨ (p ⇒ q) ∧ (q ⇒ r)                     ⇒⊭ on 1
3. I ⊭ p ⇒ r                                 ⇒⊭ on 1
4. I ⊨ p ⇒ q                                 ∧⊨ on 2
5. I ⊨ q ⇒ r                                 ∧⊨ on 2
6. I ⊨ p                                     ⇒⊭ on 3
7. I ⊭ r                                     ⇒⊭ on 3
├─ case 1 of 2  (⇒⊨ on 4)
│  8. I ⊭ p                                  ⇒⊨ on 4
│  ✗ closed: lines 6 and 8 contradict
└─ case 2 of 2  (⇒⊨ on 4)
   9. I ⊨ q                                  ⇒⊨ on 4
   ├─ case 1 of 2  (⇒⊨ on 5)
   │  10. I ⊭ q                              ⇒⊨ on 5
   │  ✗ closed: lines 9 and 10 contradict
   └─ case 2 of 2  (⇒⊨ on 5)
      11. I ⊨ r                              ⇒⊨ on 5
      ✗ closed: lines 7 and 11 contradict

Every case closes: valid, in 11 lines with two case splits. The slides’ version has 10 lines because it uses a derived rule: modus ponens, “from I⊨AI \models A and I⊨A⇒BI \models A \Rightarrow B conclude I⊨BI \models B”. That rule avoids the split whose first case closes immediately. Derived rules make proofs shorter without changing what can be proved (exercise 10).

8.6 Unsatisfiability and models with the same rules

Starting from I⊨FI \models F instead of I⊭FI \not\models F turns the method into a test for unsatisfiability. All branches closed means no interpretation satisfies FF; an open branch is a model — exactly what a SAT solver returns. Script 04, Part 2:

  • proves (p⇒q)∧p∧¬q(p \Rightarrow q) \wedge p \wedge \neg q unsatisfiable (8 lines);
  • finds the model {p↦false,q↦true}\{p \mapsto \text{false}, q \mapsto \text{true}\} of (p∨q)∧¬p(p \vee q) \wedge \neg p;
  • proves Peirce’s law valid in 6 lines.

8.7 Why the method is correct: termination, soundness, completeness

These three properties are what Lecture 3 demands of every proof system. Here are the proofs for this one.

Termination. Look at one branch. Each rule removes a pending judgement on a formula of size ss and adds judgements on its immediate subformulas, whose sizes add up to at most s−1s - 1 per case. So the total size of pending formulas on a branch strictly decreases, and a branch has at most size(F)\mathrm{size}(F) rule applications. The tree is binary with bounded depth, hence finite (at most 2size(F)2^{\mathrm{size}(F)} leaves).

Soundness (if every branch closes, FF is valid). Suppose some I∗I^* falsifies FF. Walk down the tree from the root, always choosing a case that I∗I^* satisfies. Such a case always exists, because each rule’s cases cover every way its premise can be true — the rules read the truth tables exactly. Every judgement on this path is then true of I∗I^*, so the path never contains both I⊨GI \models G and I⊭GI \not\models G: it never closes. Hence if every branch closes, no falsifying I∗I^* exists. ∎

Completeness (if FF is valid, every branch closes; equivalently, an open finished branch yields a real counterexample). Take an open branch where every non-atomic judgement has been unfolded. Define II from the atomic judgements on it (the branch is open, so they do not conflict); give unconstrained variables any value. Claim: II makes every judgement on the branch true. Proof by induction on formula size:

  • atoms are true by construction;
  • a non-atomic judgement was unfolded, and one of its cases lies entirely on the branch; those judgements are about smaller formulas, true by the induction hypothesis; and the rule’s cases imply the premise (again: the rules read the truth tables).

In particular I⊭FI \not\models F: a genuine counterexample. ∎

(An open, fully unfolded branch is a Hintikka set, and the claim is Hintikka’s lemma.)

Script 04, Part 3 checks all three on 3,000 random formulas (329 valid, 2,512 contingent, 159 unsatisfiable):

  • 3,000 / 3,000 verdicts agree with the truth table, for both validity and unsatisfiability;
  • all 58,819 interpretations read off open branches really falsify (or satisfy) the formula as claimed: 0 failures.

8.8 Strategies: the order of rules changes the proof, not the verdict

The rules can be applied in any order; the answer never changes, but the proof size does. Script 04, Part 4 compares three strategies on six formulas:

  • α-first: unfold linear rules whenever possible, split only when nothing else is left;
  • in order: first in, first out;
  • last first: last in, first out.
formulagoalα-firstin orderlast first
(p ⇒ q) ∧ (q ⇒ r) ⇒ (p ⇒ r)valid11 / 311 / 311 / 3
(a ∨ b) ∧ (c ∨ d) ∧ (e ∨ f) ∧ ¬a ∧ ¬bunsat13 / 257 / 825 / 8
¬(p ∧ q) ⇔ ¬p ∨ ¬qvalid19 / 422 / 421 / 4

(each cell: lines / branches; the other three formulas tie)

α-first is never worse in this table and sometimes much better. A split copies every pending judgement into both cases, so splitting late copies less. On the second formula, α-first learns ¬a\neg a and ¬b\neg b before splitting on a∨ba \vee b, and both cases close at once. Use cheap, forced facts before guessing: that is the seed of unit propagation, the engine of every SAT solver (Lectures 2 and 4).

8.9 Is deduction faster than enumeration? Sometimes much faster, sometimes much slower

Script 04, Part 5 measures proof size against truth-table size on three families.

(a) Implication chains (p1⇒p2)∧⋯∧(pn−1⇒pn)⇒(p1⇒pn)(p_1 \Rightarrow p_2) \wedge \dots \wedge (p_{n-1} \Rightarrow p_n) \Rightarrow (p_1 \Rightarrow p_n), valid:

n48121620
truth-table rows162564,09665,5361,048,576
proof lines1531476379

The proof grows linearly, because every split has a case that closes at once. Deduction exploits structure that enumeration cannot see.

(b) All 2n2^n clauses over nn variables: the conjunction of every disjunction that contains each variable once, positively or negatively. It is unsatisfiable, since each interpretation falsifies exactly one clause. The formula itself has size about n⋅2nn \cdot 2^n, so the truth-table work (rows × size) is polynomial in the formula size.

n123456
truth table: rows × size8764722,54412,76861,376
proof lines, plain rules426705> 300,000 (stopped)––
proof lines, skip fulfilled4211171,04517,621580,693

The plain proof explodes, and its growth factor itself grows (×6.5, then ×27.1, then beyond the budget). This is a known theorem: D’Agostino (1992) showed that tableaux cannot even polynomially simulate truth tables.

Why so bad? The plain method splits on a clause even when the branch already makes it true, re-deriving the same facts again and again. The variant skip_fulfilled=True drops a disjunction that already holds on the branch. That is sound and complete (exercise 11) and helps enormously, but from n=5n = 5 on even it loses to the truth table.

(c) Random 3-CNF formulas with 5 clauses per variable (median of 3; the search stops at the first model):

n345
truth-table rows81632
proof lines, plain1,14344,254> 100,000 (stopped)
proof lines, skip fulfilled1592,53325,920

Semantic arguments vs truth tables

The plain method needs 44,254 lines where the truth table has 16 rows. The root cause is that the cases of a β-rule overlap: from I⊨a∨(b∨c)I \models a \vee (b \vee c) the cases are "I⊨aI \models a" and "I⊨b∨cI \models b \vee c", and an interpretation can satisfy both. The same assignments are explored again and again.

Plan vs reality. The plan for this experiment was to compare the two methods on random 3-CNF up to 14 variables. The plain tableau could not get past 4, which turned the experiment into a lesson about why.

The cure is previewed here and developed in Lectures 2–5:

  • split on a variable — the cases pp / ¬p\neg p are exclusive, so each interpretation is explored once;
  • drop satisfied clauses;
  • propagate forced literals first.

That is the DPLL procedure (Lecture 4). Its descendant CDCL (Lecture 5) adds learning, and decides the adder of §10.5 at 64 bits in seconds.

Run it. python3 04_semantic_arguments.py (about 15 seconds): every proof in this section, the correctness check, the strategy table and the three families.


9. A glimpse of deductive systems

The semantic argument reasons about interpretations. A different tradition derives formulas syntactically, from axioms by rules, never mentioning interpretations. A deductive system has a set of axioms (valid formulas) and rules. A proof of α\alpha is a sequence of formulas, each an axiom or the result of a rule applied to earlier ones, ending in α\alpha. We write ⊢α\vdash \alpha, and U⊢αU \vdash \alpha when the members of UU may be used as extra axioms (a sequent).

The slides present the Hilbert system H2: three axiom schemas and one rule (any formulas may be substituted for α,β,γ\alpha, \beta, \gamma):

A1:α⇒(β⇒α)A2:(α⇒(β⇒γ))⇒((α⇒β)⇒(α⇒γ))A3:(¬β⇒¬α)⇒(α⇒β)MP:from α and α⇒β infer β(modus ponens)\begin{aligned} \text{A1:}\quad & \alpha \Rightarrow (\beta \Rightarrow \alpha)\\ \text{A2:}\quad & (\alpha \Rightarrow (\beta \Rightarrow \gamma)) \Rightarrow ((\alpha \Rightarrow \beta) \Rightarrow (\alpha \Rightarrow \gamma))\\ \text{A3:}\quad & (\neg\beta \Rightarrow \neg\alpha) \Rightarrow (\alpha \Rightarrow \beta)\\ \text{MP:}\quad & \text{from } \alpha \text{ and } \alpha \Rightarrow \beta \text{ infer } \beta \quad\text{(modus ponens)} \end{aligned}

Even ⊢φ⇒φ\vdash \varphi \Rightarrow \varphi takes five steps:

  1. A2 with α:=φ\alpha := \varphi, β:=φ⇒φ\beta := \varphi \Rightarrow \varphi, γ:=φ\gamma := \varphi;
  2. A1 with β:=φ⇒φ\beta := \varphi \Rightarrow \varphi;
  3. MP on 1, 2;
  4. A1 with β:=φ\beta := \varphi;
  5. MP on 3, 4.

Derived rules make life easier. The most important is the deduction theorem: if U∪{α}⊢βU \cup \{\alpha\} \vdash \beta then U⊢α⇒βU \vdash \alpha \Rightarrow \beta. With it, ⊢α⇒α\vdash \alpha \Rightarrow \alpha follows in two lines from the assumption rule.

The three properties a deductive system should have:

propertymeaningH2
soundnessif ⊢α\vdash \alpha then ⊨α\models \alpha (only valid formulas are provable)yes: the axioms are valid (they are valid templates, §6.2) and MP preserves validity
completenessif ⊨α\models \alpha then ⊢α\vdash \alpha (every valid formula is provable)yes (Post 1921; Kalmár 1935)
consistencynever both ⊢α\vdash \alpha and ⊢¬α\vdash \neg\alphafollows from soundness

Hilbert systems are elegant for proving things about logic and terrible for automation. A proof may need any instance of any axiom, and MP can be applied to any pair of formulas, so the search space is infinite and unstructured. The slides conclude that we will focus on proof systems closer to semantic arguments, where every step decomposes the formula (the subformula property). Lecture 3 makes “proof system” precise in general, with soundness, completeness and termination as the three things to prove.


10. Modeling with propositional logic, and the exponential wall

10.1 From English to formulas

Translation in three steps:

  1. identify the atomic statements and give them names;
  2. recognize the connectives behind English keywords;
  3. reveal as much logical structure as possible (“John is not tall” is ¬t\neg t, not a new atom).

Script 05, Part 1 tabulates the usual keywords, with each formula’s values on the rows (p,q)(p, q) = 00, 01, 10, 11:

Englishformulavalues on 00 01 10 11
p and q; p but q; p, however qp ∧ q0001
p or q (inclusive)p ∨ q0111
either p or q (exclusive)(p ∨ q) ∧ ¬(p ∧ q)0110
if p then q; p only if q; p is sufficient for qp ⇒ q1101
p if q; p is necessary for qq ⇒ p1011
p unless q¬q ⇒ p (≡ p ∨ q)0111
neither p nor q¬p ∧ ¬q (≡ ¬(p ∨ q))1000

Pitfalls the truth table catches at once:

  • “p only if q” is p⇒qp \Rightarrow q, not q⇒pq \Rightarrow p — the commonest translation error;
  • English “or” is ambiguous, and the two readings differ exactly in the row where both hold;
  • some English cannot be expressed at all: “but” and “and” become the same ∧\wedge, and temporal or causal “and” (“she fell and broke her arm”) is lost.

10.2 Puzzles as entailment: knights and knaves

On Smullyan’s island, knights always tell the truth and knaves always lie. If kXk_X means “X is a knight”, then X saying SS contributes kX⇔Sk_X \Leftrightarrow S to the knowledge base KBKB. Script 05, Part 2:

puzzleKBmodelsconclusion
A: “We are both knaves.”kA⇔¬kA∧¬kBk_A \Leftrightarrow \neg k_A \wedge \neg k_B1: A knave, B knightKB⊨¬kAKB \models \neg k_A, KB⊨kBKB \models k_B
A: “At least one of us is a knave.”kA⇔¬kA∨¬kBk_A \Leftrightarrow \neg k_A \vee \neg k_B1: A knight, B knaveboth determined
A: “B is a knave.” B: “A and C are of the same kind.”(kA⇔¬kB)∧(kB⇔(kA⇔kC))(k_A \Leftrightarrow \neg k_B) \wedge (k_B \Leftrightarrow (k_A \Leftrightarrow k_C))2KB⊨¬kCKB \models \neg k_C; A, B not determined
A: “I am a knave.” (the liar)kA⇔¬kAk_A \Leftrightarrow \neg k_A0KB⊨KB \models everything

Puzzle 3 is the instructive one. Its two models disagree about A and B but agree that C is a knave. Entailment asks what holds in all models, not what one solution looks like.

The liar shows the danger of contradictory assumptions. An unsatisfiable KBKB entails every formula, since there is no model to contradict it. Verification tools therefore check that their assumptions are satisfiable (“vacuity checks”): a specification that proves everything proves nothing.

10.3 Combinatorial problems, and testing an encoding

Graph 3-coloring with variables xv,cx_{v,c} (“vertex vv has color cc”) and three families of constraints:

  • each vertex has at least one color: xv,0∨xv,1∨xv,2x_{v,0} \vee x_{v,1} \vee x_{v,2};
  • at most one color: ¬(xv,c∧xv,d)\neg(x_{v,c} \wedge x_{v,d});
  • adjacent vertices differ: ¬(xu,c∧xv,c)\neg(x_{u,c} \wedge x_{v,c}).

A model is then exactly a proper coloring. Script 05, Part 3 checks this by comparing the number of models with an independent count of colorings by brute force:

graph#varsrows#models#colorings (direct)#models without at-most-one
path of 4 vertices124,096242472
5-cycle1532,768303060
wheel W518262,144000
Moser spindle212,097,152000

The wheel and the Moser spindle are not 3-colorable. Proving that requires ruling out every row — 2,097,152 for the spindle, still instant bit-parallel.

Dropping the at-most-one constraints does not change satisfiability: any multi-colored solution can be trimmed. But the model count no longer matches. Model counting against an independent computation is a cheap, powerful test of an encoding, used again in Lecture 2.

10.4 Equivalence checking: the classic industrial question

Two circuits are equivalent if they compute the same outputs on every input. Build a miter: the disjunction over output bits of “the two outputs differ” (⋁ioi⊕oi′\bigvee_i o_i \oplus o'_i). The circuits are equivalent iff the miter is unsatisfiable, and a model of the miter is a concrete failing input.

Script 05, Part 4 builds nn-bit adders three ways:

  • ripple: si=(ai⊕bi)⊕cis_i = (a_i \oplus b_i) \oplus c_i, ci+1=(ai∧bi)∨(ci∧(ai⊕bi))c_{i+1} = (a_i \wedge b_i) \vee (c_i \wedge (a_i \oplus b_i));
  • or-carry: si=(ai⇔bi)⇔cis_i = (a_i \Leftrightarrow b_i) \Leftrightarrow c_i, ci+1=(ai∧bi)∨(ci∧(ai∨bi))c_{i+1} = (a_i \wedge b_i) \vee (c_i \wedge (a_i \vee b_i)) — note that ⊕⊕\oplus\oplus and ⇔⇔\Leftrightarrow\Leftrightarrow give the same three-input function, which the checker must discover;
  • buggy: the or-carry adder whose carry out of bit 2 forgets the bi∧cib_i \wedge c_i case.

At 4 bits (8 inputs, 256 rows):

  • ripple ≡ or-carry (miter unsatisfiable);
  • the buggy circuit fails on 24 of 256 inputs, the first being a=2a = 2, b=6b = 6: correct sum 8, buggy circuit 0. The carry into bit 2 is 1, and bit 2 has b2=1b_2 = 1, a2=0a_2 = 0 — exactly the forgotten case.

10.5 The exponential wall, measured

The miter of two nn-bit adders has 2n2n inputs and 4n4^n rows. Script 05 times both truth-table implementations:

  • row by row: evaluate on each interpretation;
  • bit-parallel: whole columns at once.

Times from one run on the author’s machine; they vary by machine and from run to run:

bits nrowsrow by rowbit-parallel
4256≈ 4 ms≈ 0.06–0.09 ms
716,384≈ 0.5–1.2 s≈ 0.2 ms
101,048,576–≈ 2 ms
1216,777,216–≈ 60–75 ms

Extrapolating with cost ∝ rows × circuit size, calibrated on the largest measured nn (again machine-dependent):

bits nrowsrow by row (predicted)bit-parallel (predicted)
162322^{32}days≈ 20–30 s
202402^{40}years≈ 2 hours
322642^{64}≈ 10810^8 years≈ 5×1035 \times 10^3 years
6421282^{128}≈ 102710^{27} years≈ 102310^{23} years

The exponential wall

Each extra bit multiplies the work by about 4. The bit-parallel version is thousands of times faster — and hits the same wall a few bits later. A 32-bit adder is out of reach; the age of the universe is about 1.4×10101.4 \times 10^{10} years.

Yet industrial tools check far bigger circuits every day, with SAT solvers that never enumerate rows. How that is possible is the story of Lectures 2–5.

10.6 Trees vs DAGs: a preview of Tseitin

In the “majority” style of adder, the carry ci+1=(ai∧bi)∨(ai∧ci)∨(bi∧ci)c_{i+1} = (a_i \wedge b_i) \vee (a_i \wedge c_i) \vee (b_i \wedge c_i) uses cic_i twice. Written out as a tree, the formula doubles with every bit; stored as a DAG, with shared subformulas kept once, it grows linearly like the circuit (script 05, Part 5):

bits n48121620
majority carry: tree size1512,55140,951655,35110,485,751
majority carry: DAG size295785113141

Our evaluators memoize on subformulas, so they work on the DAG and never notice the blow-up. Algorithms that copy subtrees do notice it: the semantic argument, or the textbook CNF conversion of Lecture 2. The fix is to give every shared gate its own name, a fresh variable defined by the gate. That is the Tseitin encoding (Lecture 2). It answers “equisatisfiable” rather than “equivalent”, which, by the duality theorems of §5.3, is all a SAT solver needs.

Run it. python3 05_modeling_and_the_exponential_wall.py (about 1–2 seconds): English, puzzles, coloring, the adder bug, the timing table and the tree/DAG sizes.


11. Summary

  1. Automated reasoning mechanizes inference over a formal language with a precise syntax, semantics and proof systems. Propositional logic is the simplest classical logic and the base of all others in the course.
  2. Formulas are defined inductively (atoms + formula-building operators + “nothing else”). This gives structural induction for proofs and structural recursion for algorithms. Conventions (precedence, right associativity) only abbreviate; unique readability makes each formula one tree.
  3. Semantics is compositional: an interpretation assigns truth values to variables, and connectives combine them. Over nn variables there are 2n2^n interpretations and at most 22n2^{2^n} meanings, though infinitely many formulas.
  4. Formulas are valid, unsatisfiable or contingent. Entailment and equivalence compare formulas. Validity, entailment and equivalence all reduce to unsatisfiability of a negation, so one SAT procedure decides them all.
  5. Valid templates stay valid under any substitution; replacing a part by an equivalent part preserves meaning — the license for every simplification.
  6. A set of connectives is functionally complete iff it escapes all five of Post’s invariants. Incompleteness is proved by an invariant plus structural induction. Small bases cost formula size.
  7. The truth-table method decides everything in 2n2^n steps; bit-parallelism gains a constant factor, not an escape.
  8. The semantic argument method refutes a hypothetical counterexample by case analysis on connectives. It is sound, complete and terminating, and open branches yield counterexamples. It can be exponentially better than truth tables (chains) or exponentially worse (all-clauses, random CNF), because its cases overlap and it re-splits satisfied disjunctions.
  9. Modeling translates English, puzzles, combinatorial problems and circuits into formulas. Model counting against an independent computation validates encodings. A miter reduces equivalence checking to unsatisfiability.
  10. Brute force hits a measurable exponential wall around 30 inputs. The rest of the course is about getting past it: normal forms and resolution (L2), proof systems (L3), DPLL (L4), CDCL (L5) — and beyond propositional logic.

12. Common pitfalls

PitfallWhy it is wrongCorrect view
Treating ⊨\models or ≡\equiv as connectivesThey are statements about formulas; you cannot write p∧(q⊨r)p \wedge (q \models r)α⊨β\alpha \models \beta iff ⊨α⇒β\models \alpha \Rightarrow \beta links them (§5.3)
Reading “p only if q” as q⇒pq \Rightarrow p“Only if” introduces the necessary conditionp⇒qp \Rightarrow q
“False ⇒ q is weird, so it must be false”Material implication is false only when the premise is true and the conclusion false§4.3: it is a promise that was not broken
Assuming English “or” is exclusiveLogic’s ∨\vee is inclusiveExclusive or must be written: (p∨q)∧¬(p∧q)(p \vee q) \wedge \neg(p \wedge q)
Confusing “not valid” with “unsatisfiable”A contingent formula is neither valid nor unsatisfiableThree classes: valid / contingent / unsatisfiable (§5.1)
Believing substitution preserves satisfiabilityIt preserves validity and unsatisfiability, not contingencyp∨qp \vee q becomes unsatisfiable under {p,q↦⊥}\{p, q \mapsto \bot\} (§6.2)
Testing a few formulas and calling it a proofTests can refute a universal claim, never establish itStructural induction (§3.3)
Thinking the semantic argument is always faster than truth tablesIt can be exponentially slower (§8.9b, c)Neither method escapes 2n2^n; smarter search (DPLL/CDCL) is needed
“If every branch closes, the formula is unsatisfiable”Depends on the starting judgementStart I⊭FI \not\models F: closure proves validity; start I⊨FI \models F: closure proves unsatisfiability
Expecting Or(Or(p, q), r) == Or(p, Or(q, r)) in our Python codeThey are equivalent formulas but different treesUse equivalent(f, g) for meaning, == for structure
Forgetting that an unsatisfiable knowledge base entails everythingNo model exists to refute any conclusionCheck assumptions for satisfiability first (§10.2)

13. Exercises

Answers are collapsed; try each exercise first.

1. (syntax) Which of the following are wffs of the official syntax (§2.2)? For each wff, give its main connective. (a) (¬(p∧q))(\neg(p \wedge q)) (b) ¬p∧q\neg p \wedge q (c) ((p⇒q)⇔(¬r))((p \Rightarrow q) \Leftrightarrow (\neg r)) (d) (p∧q∧r)(p \wedge q \wedge r) (e) ((¬¬p))((\neg \neg p))

Answer

(a) yes, main connective ¬. (b) no: the official syntax requires ((¬p)∧q)((\neg p) \wedge q); under the conventions it abbreviates that formula. (c) yes, main connective ⇔. (d) no: every binary connective brings its own parentheses, (p∧(q∧r))(p \wedge (q \wedge r)). (e) no: ¬¬p\neg\neg p officially is (¬(¬p))(\neg(\neg p)), which has two pairs of parentheses, and ((¬¬p))((\neg\neg p)) has an extra outer pair with nothing produced by an operator inside it. Check with the parser: to_str(parse(s), full=True).

2. (structural induction) Prove that in every official wff, the number of left parentheses equals the number of connectives (counting ¬ too).

Answer

Base: an atom has 0 parentheses and 0 connectives. Step: E¬(α)=(¬α)\mathcal{E}_\neg(\alpha) = (\neg\alpha) adds one left parenthesis and one connective; E∘(α,β)=(α∘β)\mathcal{E}_\circ(\alpha,\beta) = (\alpha \circ \beta) adds one of each to lp(α)+lp(β)=conn(α)+conn(β)\text{lp}(\alpha) + \text{lp}(\beta) = \text{conn}(\alpha) + \text{conn}(\beta) (induction hypothesis). So the set of wffs with the property is inductive. ∎

3. (structural induction) Let φ\varphi be built from the single variable pp using only ∧\wedge and ∨\vee. Prove φ≡p\varphi \equiv p.

Answer

Base: p≡pp \equiv p. Step: if α≡p\alpha \equiv p and β≡p\beta \equiv p then α∧β≡p∧p≡p\alpha \wedge \beta \equiv p \wedge p \equiv p (substitution of equivalents, §6.3, then idempotence), and similarly α∨β≡p\alpha \vee \beta \equiv p. ∎ (This is one way to see that {∧,∨}\{\wedge, \vee\} is not complete: from one variable it can only build pp.)

4. (semantics) Classify each formula as valid, contingent or unsatisfiable: (a) (p⇒q)∨(q⇒p)(p \Rightarrow q) \vee (q \Rightarrow p) (b) p⇒(p∧q)p \Rightarrow (p \wedge q) (c) (p⇔q)∧(p⇔¬q)(p \Leftrightarrow q) \wedge (p \Leftrightarrow \neg q) (d) (p⇒q)⇒(¬p⇒¬q)(p \Rightarrow q) \Rightarrow (\neg p \Rightarrow \neg q)

Answer

(a) valid — surprising at first: if qq is true the first disjunct holds, if qq is false the second does. (b) contingent (false when pp = 1, qq = 0). (c) unsatisfiable: qq would have to equal both pp and ¬p\neg p. (d) contingent: pp = 0, qq = 1 falsifies it (this is “denying the antecedent” as a formula). Check: classify(parse("...")).

5. (entailment) True or false? Prove or give a counterexample. (a) If α⊨β\alpha \models \beta and β⊨γ\beta \models \gamma then α⊨γ\alpha \models \gamma. (b) If α∨β⊨γ\alpha \vee \beta \models \gamma then α⊨γ\alpha \models \gamma. (c) If α⊨β∨γ\alpha \models \beta \vee \gamma then α⊨β\alpha \models \beta or α⊨γ\alpha \models \gamma.

Answer

(a) True: a model of α\alpha is a model of β\beta, hence of γ\gamma. (b) True: every model of α\alpha is a model of α∨β\alpha \vee \beta, hence of γ\gamma. (c) False: α=p∨q\alpha = p \vee q, β=p\beta = p, γ=q\gamma = q. Then α⊨β∨γ\alpha \models \beta \vee \gamma, but {p↦0,q↦1}\{p \mapsto 0, q \mapsto 1\} satisfies α\alpha and not β\beta, and {p↦1,q↦0}\{p \mapsto 1, q \mapsto 0\} satisfies α\alpha and not γ\gamma. Entailment does not distribute over ∨\vee on the right — one reason case splits are unavoidable.

6. (duality) Prove that {α1,…,αk}⊨β\{\alpha_1, \dots, \alpha_k\} \models \beta iff α1∧⋯∧αk∧¬β\alpha_1 \wedge \dots \wedge \alpha_k \wedge \neg\beta is unsatisfiable.

Answer

Both sides say: no interpretation makes every αi\alpha_i true and β\beta false. Left side: by definition, every interpretation satisfying all αi\alpha_i satisfies β\beta, i.e. none satisfies all αi\alpha_i and falsifies β\beta. Right side: the conjunction is true exactly under interpretations that satisfy all αi\alpha_i and falsify β\beta; unsatisfiable means there are none. ∎

7. (substitution) (a) Find variable substitutions that turn p⇒qp \Rightarrow q into a valid formula and into an unsatisfiable one. (b) Prove that if FF is unsatisfiable, so is FσF\sigma for every variable substitution σ\sigma.

Answer

(a) Valid: {q↦p}\{q \mapsto p\} gives p⇒pp \Rightarrow p. Unsatisfiable: {p↦⊤,q↦⊥}\{p \mapsto \top, q \mapsto \bot\} gives ⊤⇒⊥\top \Rightarrow \bot. (b) FF unsatisfiable means ¬F\neg F valid; by the valid-template theorem (¬F)σ=¬(Fσ)(\neg F)\sigma = \neg(F\sigma) is valid; so FσF\sigma is unsatisfiable. ∎

8. (connectives) Show that NAND (↑\uparrow, α↑β≡¬(α∧β)\alpha \uparrow \beta \equiv \neg(\alpha \wedge \beta)) alone is functionally complete.

Answer

¬α≡α↑α\neg\alpha \equiv \alpha \uparrow \alpha and α∧β≡¬(α↑β)≡(α↑β)↑(α↑β)\alpha \wedge \beta \equiv \neg(\alpha \uparrow \beta) \equiv (\alpha \uparrow \beta) \uparrow (\alpha \uparrow \beta). Since {¬,∧}\{\neg, \wedge\} is complete (§7.2), so is {↑}\{\uparrow\}. Script 03 finds the second as the smallest NAND formula for p∧qp \wedge q: 7 nodes, (p↑q)↑(p↑q)(p \uparrow q) \uparrow (p \uparrow q).

9. (invariants) Prove that p∧qp \wedge q cannot be expressed with ⇔\Leftrightarrow and ⊥\bot alone.

Answer

Invariant: “the formula’s truth function is affine”, i.e. f(x)=c⊕⨁i∈Sxif(x) = c \oplus \bigoplus_{i \in S} x_i for a constant cc and a set SS of variables. Base: variables (c=0c = 0, S={p}S = \{p\}) and ⊥\bot (c=0c = 0, S=∅S = \emptyset) are affine. Step: α⇔β=α⊕β⊕1\alpha \Leftrightarrow \beta = \alpha \oplus \beta \oplus 1, and XOR of affine functions is affine (add the constants, take the symmetric difference of the sets). But p∧qp \wedge q is not affine: an affine function of p,qp, q that is not constant is true in exactly 2 of 4 rows, while p∧qp \wedge q is true in 1 (and it is not constant). ∎ Script 03 reports exactly 16 reachable truth tables over three variables for {⇔,⊥}\{\Leftrightarrow, \bot\}: the 16 affine functions.

10. (semantic argument) Prove axiom A2 valid by a semantic argument: (p⇒(q⇒r))⇒((p⇒q)⇒(p⇒r))(p \Rightarrow (q \Rightarrow r)) \Rightarrow ((p \Rightarrow q) \Rightarrow (p \Rightarrow r)). Then show that the derived rule “from I⊨AI \models A and I⊨A⇒BI \models A \Rightarrow B conclude I⊨BI \models B” is sound.

Answer

Assume I⊭I \not\models A2. By ⇒⊭: I⊨p⇒(q⇒r)I \models p \Rightarrow (q \Rightarrow r) and I⊭(p⇒q)⇒(p⇒r)I \not\models (p \Rightarrow q) \Rightarrow (p \Rightarrow r); again ⇒⊭: I⊨p⇒qI \models p \Rightarrow q, I⊭p⇒rI \not\models p \Rightarrow r; again: I⊨pI \models p, I⊭rI \not\models r. Split ⇒⊨ on p⇒qp \Rightarrow q: I⊭pI \not\models p closes with I⊨pI \models p; otherwise I⊨qI \models q. Split on p⇒(q⇒r)p \Rightarrow (q \Rightarrow r): I⊭pI \not\models p closes; otherwise I⊨q⇒rI \models q \Rightarrow r; split: I⊭qI \not\models q closes with I⊨qI \models q, I⊨rI \models r closes with I⊭rI \not\models r. All closed: valid. Run semantic_argument(parse("(p ⇒ (q ⇒ r)) ⇒ ((p ⇒ q) ⇒ (p ⇒ r))")) and print it with format_proof.

Derived rule: if I⊨AI \models A and I⊨A⇒BI \models A \Rightarrow B, the ⇒⊨ split gives I⊭AI \not\models A (which closes immediately against I⊨AI \models A) or I⊨BI \models B. So every non-closed continuation contains I⊨BI \models B; adding it directly loses nothing.

11. (semantic argument) Justify skip_fulfilled: if a branch already contains every judgement of one case of a β-rule, the β-judgement may be dropped without splitting. Why does soundness survive? Why does completeness?

Answer

Soundness is untouched: dropping a judgement only removes work; any closed branch is still contradictory. Completeness: in the Hintikka argument (§8.7), the dropped judgement is implied by the case that is already on the branch — those judgements are true under the constructed II by the induction hypothesis, and the case implies the premise. So the open branch still yields a genuine counterexample. Termination: obviously still holds.

12. (semantic argument) Use the method to find all falsifying interpretations of (p∨q)⇒(p∧q)(p \vee q) \Rightarrow (p \wedge q).

Answer

I⊭(p∨q)⇒(p∧q)I \not\models (p \vee q) \Rightarrow (p \wedge q) gives I⊨p∨qI \models p \vee q and I⊭p∧qI \not\models p \wedge q. Split ∨⊨: case I⊨pI \models p, then split ∧⊭: I⊭pI \not\models p closes, I⊭qI \not\models q open → {p↦1,q↦0}\{p \mapsto 1, q \mapsto 0\}. Case I⊨qI \models q, split ∧⊭: I⊭pI \not\models p open → {p↦0,q↦1}\{p \mapsto 0, q \mapsto 1\}; I⊭qI \not\models q closes. Exactly the two “exclusive” rows.

13. (modeling) (a) Write “exactly one of p,q,rp, q, r” as a formula and check that it has 3 models. (b) How many clauses does the pairwise “at most one” encoding need for nn variables? (c) A says: “If I am a knight, then B is a knave.” What are A and B?

Answer

(a) (p∨q∨r)∧¬(p∧q)∧¬(p∧r)∧¬(q∧r)(p \vee q \vee r) \wedge \neg(p \wedge q) \wedge \neg(p \wedge r) \wedge \neg(q \wedge r); count_models gives 3. (b) (n2)=n(n−1)/2\binom{n}{2} = n(n-1)/2 — quadratic; Lecture 2 shows linear-size encodings with auxiliary variables. (c) KB=kA⇔(kA⇒¬kB)KB = k_A \Leftrightarrow (k_A \Rightarrow \neg k_B). If kAk_A is false, the right side kA⇒¬kBk_A \Rightarrow \neg k_B is true, contradiction. So kAk_A is true, and then ¬kB\neg k_B: A is a knight, B a knave (one model).

14. (programming) Add a function simplify(f) to a copy of logic.py that removes ⊤\top and ⊥\bot using laws such as α∧⊤≡α\alpha \wedge \top \equiv \alpha, α∧⊥≡⊥\alpha \wedge \bot \equiv \bot, ¬⊤≡⊥\neg\top \equiv \bot, α⇒⊤≡⊤\alpha \Rightarrow \top \equiv \top. Test it on 5,000 random formulas with p_const=0.3: the result must be equivalent to the input and either be a constant or contain no constants.

Answer (sketch)

Structural recursion: simplify the children first, then apply the laws at the root (e.g. for “and”: if either child is ⊥ return ⊥; if one is ⊤ return the other). Test: assert equivalent(f, simplify(f)) and a check that simplify(f) is ⊤, ⊥, or has no “true”/“false” node in subformulas. The correctness argument is substitution of equivalents (§6.3) plus induction.

15. (reflection) The bit-parallel truth table is thousands of times faster than the row-by-row loop in §10.5. Why does that not change the conclusion “a 64-bit adder is out of reach”? What kind of improvement would?

Answer

Both methods visit all 4n4^n rows; bit-parallelism only lowers the cost per row, a constant factor. A factor of 10410^4 buys about log⁡4104≈6.6\log_4 10^4 \approx 6.6 more bits, nowhere near 64. What is needed is an algorithm whose work is not proportional to the number of rows: one that reasons about many rows at once (propagation, learning, structure). That is what DPLL and CDCL provide — still exponential in the worst case (unless P = NP), but not on typical industrial instances.


14. Further reading

  • Textbooks
    • A. Bradley, Z. Manna, The Calculus of Computation, Springer 2007, Ch. 1 (§1.1–1.5 for this lecture; §1.6–1.7 for the next). The semantic-argument method and the substitution propositions used here are from §1.3 and §1.5.
    • H. Enderton, A Mathematical Introduction to Logic, 2nd ed., 2001, §1.0–1.2 (formal languages, the induction principle); §1.3 (unique readability); §1.5 (completeness of connectives).
    • D. Kroening, O. Strichman, Decision Procedures, 2nd ed., 2016, Ch. 1 (decision procedures, soundness and completeness).
    • M. Ben-Ari, Mathematical Logic for Computer Science, 3rd ed., Springer 2012, Ch. 2–3 (semantic tableaux, Hilbert systems) — the “ML” book of the Iowa course.
    • R. Smullyan, First-Order Logic, 1968 (analytic tableaux, Hintikka sets).
  • History and context
    • M. Davis, “The early history of automated deduction”, in Handbook of Automated Reasoning, 2001.
    • J. Franco, J. Martin, “A history of satisfiability”, Ch. 1 of the Handbook of Satisfiability, 2nd ed., 2021.
    • D. Knuth, The Art of Computer Programming, Vol. 4B, “Satisfiability” (2022): a deep, playful tour of SAT.
  • Papers mentioned
    • E. Post, “Introduction to a general theory of elementary propositions”, American Journal of Mathematics, 1921 (truth tables, completeness); “The two-valued iterative systems of mathematical logic”, 1941 (the five classes).
    • S. Cook, “The complexity of theorem-proving procedures”, STOC 1971.
    • M. D’Agostino, “Are tableaux an improvement on truth-tables?”, Journal of Logic, Language and Information, 1992.
    • N. Rungta, “A billion SMT queries a day”, CAV 2022 (invited paper).
    • M. Heule, O. Kullmann, V. Marek, “Solving and verifying the Boolean Pythagorean triples problem via cube-and-conquer”, SAT 2016.
  • Slides: C. Tinelli, Propositional Logic Basics and Course Introduction, Iowa CS:4980, Spring 2024 (adapted from Stanford CS 257 slides by Barrett, Trippel and Wu).

15. Next lecture

Lecture 2 (Normal forms, SAT solving and resolution) takes the first step past the exponential wall.

  • Normal forms. NNF, DNF and CNF fix a small internal language. Converting to CNF by distribution can blow up exponentially (the majority adder of §10.6 is a ready-made example). The Tseitin encoding avoids that by naming subformulas, giving an equisatisfiable formula of linear size.
  • Resolution. On clauses there is a single inference rule, resolution, which is sound and refutationally complete. The Davis–Putnam procedure turns it into a decision procedure: eliminate variables, propagate units, drop pure literals.
  • Code. cnf.py, sat_families.py and resolution.py build on logic.py. The first experiments compare CNF sizes on the adders of this lecture and show how resolution proofs grow on the pigeonhole problem.
← 返回课程目录