PPhilosophy, Built

Act I · The Machinery of Reason

Part 2 of 42

The Laws of Thought

propositional logic and SAT

Introductorystarts at this level58 min of film17 chaptersprerequisites: Part 1

If an argument is built from 'and', 'or', 'not' and 'if', can a machine always say whether it is valid, and at what price?

A knight-and-knave puzzle is settled by an eight-row table, and a 2016 computer proof colours the numbers 1 to 400 with no one-colour Pythagorean triple: the same calculation at two scales. The part builds propositional logic from Boole's algebra, where x squared equals x has the roots 0 and 1, through formulas as trees, the sixteen binary truth functions and Post's criterion for when connectives suffice. Validity becomes a truth table, which decides every question and costs 2 to the n rows. Natural deduction is shown sound and complete, so proof and truth agree. Then the search is made clever: resolution, DPLL's propagate, branch and back up, and CDCL, which learns a clause from every conflict. The turn is the price: SAT is NP-complete, random 3-SAT is hardest near 4.27 clauses per atom, and the pigeonhole formulas force exponentially long resolution proofs. The part ends by reading Socrates' elenchus as the same computation: the minimal inconsistent sets of Republic I and the minimal correction sets that restore consistency, and with them the first full Price List, the problem of evil with its six exits.

What you need. Nothing beyond school algebra; powers of two.

The calculation
truth tables, resolution, SAT
The wall
NP-completeness (Cook–Levin)
Built toy
DPLL/CDCL solver; the Price List engine

What you will be able to do

Introductory

  • Build the truth table of a formula and use it to decide whether an argument form is valid, giving the countermodel row when it is not.
  • Lay out a set of jointly inconsistent claims as a Price List: find its minimal inconsistent subsets and every minimal set of claims whose rejection restores consistency.

Advanced

  • Prove soundness by induction on proofs, and prove completeness by extending a consistent set to a maximal one with Lindenbaum's lemma.
  • Convert a formula to clauses by Tseitin's encoding and refute a clause set by resolution.
  • Run DPLL by hand on a small clause set: propagate, branch, back up.

Research

  • Sketch the Cook-Levin reduction from a machine's run to a clause set, and state Haken's lower bound for resolution on the pigeonhole formulas and what extended resolution changes.
  • State the Cook-Reckhow question and its relation to NP versus coNP.

Applied

  • Encode a dependency or scheduling problem as clauses, hand it to a SAT solver, and read the model or the learned clauses back.
  • Explain what a conflict-driven solver learns from a conflict and why whatever is hard for resolution is hard for it.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Introductory 28 min · Advanced 50 min · Research 58 min · Applied 34 min.

  1. 0Settling an argument by calculationIntroductory4 min
  2. 1Boole's algebra of thoughtIntroductory5 min
  3. 2Formulas, trees and truth functionsIntroductory4 min
  4. 3Enough connectivesAdvanced4 min
  5. 4Valid by calculationIntroductory3 min
  6. 5Normal formsAdvanced4 min
  7. 6Natural deductionIntroductory3 min
  8. 7Soundness: proofs never lieAdvanced4 min
  9. 8Completeness: every validity has a proofResearch4 min
  10. 9One rule: resolutionAdvanced3 min
  11. 10Searching for a modelAdvanced3 min
  12. 11Learning from conflictApplied3 min
  13. 12The price of calculationResearch4 min
  14. 13SAT at workApplied3 min
  15. 14Socrates as a SAT solverIntroductory3 min
  16. 15The first Price List: the problem of evilIntroductory3 min
  17. Recap, problems, and where this comes backAll tracks2 min

Also on this page: Lecture · Key results · Try it · Lab · Problems · Notes and sources · 中文 · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film. A dashed box stands for a number the film computes when it is rendered (hover over it to see what is computed); the README's figures for each chapter, where it lists them, follow the chapter's text.

Settling an argument by calculationIntroductory4 min

In Part 1 we met Leibniz's dream: that one day, when two philosophers disagree, they will not argue. They will take up their pencils, sit down at their slates, and say to each other: let us calculate. This part builds the first piece of that calculator: the logic of and, or, not, and if. It is the one corner of philosophy where the dream comes true, at a price we will measure.

Here is a dispute to settle. On an island, everyone is either a knight, who only tells the truth, or a knave, who only lies. You meet three islanders. A says: all of us are knaves. B says: exactly one of us is a knight. C says nothing. Who is what? The puzzle is Raymond Smullyan's. You can reason it out, and you might reason it out wrongly.

Or you can calculate. Write a for the sentence 'A is a knight'. Then what A says is true exactly when A is a knight: a, if and only if not a and not b and not c. The same for B. Two equations, in three unknowns that can each be only true or false.

So there are only eight possibilities. Check each one against both equations, and strike out every row where somebody's words don't fit what they are. One row survives. A and C are knaves; B is a knight. No cleverness: a table, filled in the same way by anyone, or anything.

Now make the puzzle enormous. Colour the whole numbers from one to n, each blue or orange, so that no Pythagorean triple, like three, four, five, is all one colour. Here are the first , coloured by the solver we will build in this part. Three, four, five; five, twelve, thirteen; twenty, twenty-one, twenty-nine: every one of the triples below uses both colours.

How far can you go? In 2016 Marijn Heule, Oliver Kullmann and Victor Marek settled it: the numbers up to 7,824 can be split this way, and up to 7,825 they cannot. No person found that proof. A program did, and the certificate it wrote out runs to two hundred terabytes, far too long for anyone to read. It was checked by a second, much simpler program. That is Leibniz's slate, at a scale he never imagined.

So this part is about the logic of whole sentences, propositional logic, and about what it means to calculate with it. We begin with Boole's algebra of thought, formulas as trees, and the sixteen ways two sentences can combine. Then truth tables, and what validity is. Natural deduction, with proofs a machine can check; then soundness and completeness, the two theorems that say proof and truth agree. Then the solvers: resolution, search, and clause learning; what they cost; and what they do for industry and for philosophy.

Two of the series' devices begin here. The first is the Wall. Every part adds a brick: the theorem that marks where calculation stops. Part 1 laid Zeno's. This part's brick will not say that we can't calculate. It will say what calculating costs.

The second is the Price List. When Socrates showed someone that their beliefs contradicted each other, he left them stuck, in what the Greeks called aporia: no way through. We will build a machine that lists every way out of a contradiction, exactly, and use it on one of the oldest arguments there is: the problem of evil.

What it establishes: Leibniz's calculemus; Smullyan's knights and knaves settled by a table; the Boolean Pythagorean triples (Heule, Kullmann and Marek 2016); the plan; the Wall and the Price List introduced.; Computed on screen: the 8-row table and its one surviving row; 1 … 400 two-coloured with no one-colour triple (294 triples) by our CDCL solver

1Boole's algebra of thoughtIntroductory5 min

The logic of whole sentences is older than Boole. In the third century before our era, the Stoic Chrysippus listed five arguments he called indemonstrable: the starting points from which every other inference was to follow. The first: if the first, then the second; the first; therefore the second. The second: if the first, then the second; not the second; therefore not the first. Then three more, about 'not both', 'either, or' and exclusion. We still use the first two every day, under their Latin names: modus ponens and modus tollens.

The Stoics also argued about what 'if' means. Philo of Megara held that 'if p then q' is false in only one case: when p is true and q is false. Diodorus Cronus demanded more, a connection that holds at every time. The dispute was so famous that the poet Callimachus joked that even the crows on the rooftops were cawing about which conditionals are true. Philo's answer is the one this part will use, and in Part 14 we will see why the crows were right to keep cawing.

Two thousand years later, George Boole, a self-taught schoolmaster from Lincoln who became a professor in Cork, did something new. In 1847, and then in An Investigation of the Laws of Thought in 1854, he wrote logic as algebra. Let x stand for the class of white things and y for the class of sheep. Then x times y is the class of white sheep. x plus y gathers the two, when they don't overlap. One is the universe of everything we are talking about, and one minus x is everything that is not white. Zero is the empty class.

One of Boole's laws is unlike ordinary algebra. The white things that are white are just the white things: x times x is x. Boole called it the law of duality. As an equation about numbers, it has only two solutions: the curve x squared meets the line x at zero and at one. That is where the two truth values come from. Read one as true and zero as false, and Boole's algebra of classes becomes an algebra of sentences.

And from that one law Boole derived the oldest principle in logic, Aristotle's principle of contradiction. Start from x squared equals x. Subtract x squared from both sides. Factor. x times one minus x is zero: the class of things that are both x and not x is empty. Nothing is both white and not white. A law of thought, derived by algebra.

Boole's algebra could be done by a machine, and in 1869 the economist William Stanley Jevons built one: the logic piano. Its method is the one we used on the island. Take two premises: iron is a metal, and every metal is an element. Write out every combination of the three terms: there are .

The first premise strikes out the combinations with iron that is not a metal. The second strikes out the remaining ones with a metal that is not an element. combinations survive, and in every surviving one that contains iron, element is there too. So iron is an element. Jevons's keys and levers did exactly this, for up to four terms: they enumerated the cases and threw away the impossible ones. Our island solver, and every truth table in this part, works the same way.

So by 1870 the pieces were on the table: sentences as variables that take two values; connectives as operations on them; and validity as something checked by exhausting the cases. What was missing was a precise account of what a formula is, and of what the connectives can and cannot build. That comes next.

What it establishes: Chrysippus's five indemonstrables; Philo vs Diodorus on 'if'; Boole's algebra of classes; x² = x has the roots 0 and 1; the principle of contradiction derived; Jevons's logic piano (1869).; Computed on screen: Jevons's method on "iron is a metal; every metal is an element": 8 combinations, 4 struck, the conclusion read off

2Formulas, trees and truth functionsIntroductory4 min

A formula is built by rules, the way a grammar builds sentences. Start with atoms: p, q, r, each standing for a whole sentence, like 'it is raining'. If A and B are formulas, then so are not A; A and B; A or B; if A then B; and A if and only if B, each in brackets. Nothing else is a formula.

Here is one formula, built in seven steps: the shape of modus tollens. Two atoms; if p then q; not q; their conjunction; not p; and the whole conditional. This is an inductive definition, and every proof about formulas in this part follows its shape: show something holds for the atoms, then show each rule preserves it. Then it holds for every formula there is.

Every formula has exactly one parse tree. Atoms sit at the leaves; each connective sits above what it connects; the main connective, here the last 'if then', is the root. The tree says how to compute truth: from the leaves up. Give the atoms values, p true and q false. Each connective reads its children and writes its own value. If p then q is false; not q is true; the conjunction false; not p false; and the whole conditional, true.

Brackets are what make the tree unique. Without them, 'p and q or r' could be built two ways, and the two trees can disagree: with p false and q and r true, one is true and the other false. A logic for settling arguments cannot leave it to the reader to guess. Frege, in 1879, was the first to insist on this precision for all of reasoning.

What a connective does is captured by its truth table: a function from the truth values of its inputs to a truth value. With two inputs, there are four rows: both true, true then false, false then true, both false. Each row's output can be true or false, so there are two to the four, sixteen, possible connectives of two sentences. Here are all sixteen, green for true and red for false.

Some have names everyone knows: and, or, if then, if and only if. Some have names only logicians use: exclusive or, nand, nor. Some are barely connectives at all: always true, always false, or a copy of p. With n inputs there are two to the two to the n truth functions: for three inputs, and for five, over four billion. The question for the next chapter is how many of them we need.

One of the sixteen deserves a closer look: the Stoic Philo's conditional, false only when the 'if' part is true and the 'then' part false. It makes 'if the moon is made of cheese, then two plus two is four' true, and many people feel that is wrong: there is no connection between the parts. But suppose 'if' is to be a truth function at all. Then three modest demands pick it out.

First, modus ponens must be valid: if p and 'if p then q' are true, q is true. of the sixteen pass. Second, 'if p then p' must always be true: remain, if-then and if-and-only-if. Third, 'if p then q' must not say the same as 'if q then p'. One remains: Philo's. So the oddity of the cheese conditional is the price of making 'if' a truth function. Part 14 asks whether 'if' should be one.

What it establishes: the grammar of formulas; parse trees and evaluation from the leaves; unique readability; the 16 binary truth functions; three demands single out Philo's conditional.; Computed on screen: the 16 truth tables; the filter 16 → 4 → 2 → 1

3Enough connectivesAdvanced4 min

Every one of those truth functions can be written with just three connectives: not, and, or. The recipe reads the table row by row. Take exclusive or. It is true in two rows: p true and q false, or p false and q true. Describe each true row exactly with an 'and': p and not q; not p and q. Join the descriptions with 'or'. The result is true in exactly the true rows, as its own table confirms.

The recipe works for any table with any number of inputs. If no row is true, write p and not p. So not, and, or are functionally complete: they can express every truth function there is. The form the recipe produces has a name, the disjunctive normal form, and it comes back in Chapter five.

Can we use fewer? De Morgan's law, p or q is the same as not both not p and not q, removes 'or': not and 'and' are enough. In 1913 Henry Sheffer showed that one connective is enough: 'not both', usually called nand and written with an up arrow. Not p is p nand p. p and q is the nand of p nand q with itself. And or is the nand of two negations. Each identity checks in all four rows. Charles Sanders Peirce had found this in 1880, in a manuscript nobody read for fifty years.

This is why a computer can be built from one kind of part. Four nand gates, wired like this, compute exclusive or. Run all four inputs through it and the output is true exactly when the inputs differ. Adders, memories and processors can all be built from nand gates alone, and flash memory, NAND flash, is named after the way its cells are wired. Sheffer's truth function, found with pencil and paper, is in your pocket billions of times over.

But not every set is enough. And with or can never build not, however you combine them. In 1941 Emil Post found the exact test. There are five properties a connective can have: it keeps falsehood, mapping all false to false; it keeps truth; it is self-dual; it is monotone; or it is affine, a sum modulo two. Here is each connective, with a hollow circle where it lacks the property.

Each property survives composition. Take monotone: switching an input from false to true never switches the output from true to false. And and or are monotone, and anything wired from monotone parts is monotone too. Not isn't, so it can never be built. So a complete set needs, for each of the five properties, some connective that lacks it. Post proved that is also enough. Checking sets: not with and, complete; nand alone, complete; and with or, stuck in the monotone class; not with if-and-only-if, stuck among the affine ones; and if-then, even with and, or and if-and-only-if, stuck keeping truth, because every one of them is true when all its inputs are. We cross-checked each verdict by generating every function the set can build.

What it establishes: DNF, so {¬, ∧, ∨} is complete; De Morgan; Sheffer's nand (and Peirce's, 1880); XOR from four nand gates; Post's five classes and criterion (1941).; Computed on screen: the nand identities on all rows; the four-gate circuit swept; Post's table; completeness of 12 sets cross-checked by closure

4Valid by calculationIntroductory3 min

Now the definitions everything else rests on. A valuation assigns true or false to every atom: one way the world might be, as far as these sentences can tell. A formula is a tautology if it comes out true under every valuation, and satisfiable if it comes out true under at least one. And a set of premises, gamma, entails a conclusion, written with this double turnstile, if every valuation that makes all the premises true also makes the conclusion true. That is what validity is: truth preserved, in every case there is.

Is Peirce's law, if 'if p then q' implies p, then p, a tautology? Most people have no intuition about it at all. So calculate. One column for each atom, then one for each subformula, from the inside out. Every row of the last column is true. A tautology. Though, as we will see in Chapter six, a strange one: there are logicians who refuse to accept it.

Arguments are checked the same way. Modus ponens: in every row where both premises are true, so is the conclusion. Valid. Modus tollens, the disjunctive syllogism, the chain of two conditionals: valid, valid, valid.

Now a famous mistake, affirming the consequent. If it rained, the streets are wet; the streets are wet; so it rained. The table finds the row that refutes it: p false and q true. No rain, wet streets: somebody ran a sprinkler. That row is a countermodel, and one countermodel is all it takes. Denying the antecedent fails in the same row.

So propositional logic is decidable. There is a mechanical procedure that answers every question of validity, yes or no, and always halts. Emil Post used truth tables this way in his thesis of 1921, and Wittgenstein's Tractatus used them the same year. For this part of reasoning, Leibniz's dream is literally true: anyone can calculate, and everyone gets the same answer.

Literally true, and ruinously expensive. A table needs one row for every valuation: two to the n rows for n atoms. Thirty atoms, about a billion rows: one second, for a machine checking a billion rows a second. Sixty atoms: years. A hundred atoms: times the age of the universe. Our own table-filler, in plain Python, manages about rows a second. Real problems have millions of atoms. Brute force will not do, and the rest of this part is about doing better.

What it establishes: valuation, tautology, satisfiability, ⊨; Peirce's law by table; six argument forms and their countermodels; Post and Wittgenstein (1921): a decision procedure; its 2ⁿ cost.; Computed on screen: Peirce's table; the verdicts; table time for 20 … 100 atoms; this machine's Python rows per second

5Normal formsAdvanced4 min

Chapter three built a formula from a table's true rows: an 'or' of 'and's, the disjunctive normal form. Turn the recipe around. Look at the false rows instead. For each, write a clause that says 'not this row': for p true and q false, not p or q. The 'and' of those clauses is true exactly where no false row holds: the conjunctive normal form, an 'and' of 'or's.

Each clause is a constraint that any satisfying valuation must meet, so a formula in this form is just a list of constraints. This is the form every SAT solver reads, in a plain text format called DIMACS: one clause per line, atoms as numbers, a minus sign for not. Problems from chip design, scheduling and mathematics all arrive at the solver as lists like this one.

But getting into this form by algebra can explode. Take x one and y one, or x two and y two, and so on, n pairs. To write it as clauses, distribute 'or' over 'and', the way you multiply out brackets. Each clause picks one letter from every pair, so there are two to the n of them. Ten pairs: clauses. Forty pairs: about a trillion. A formula that fits on one line becomes a list no computer can hold.

In 1968 Grigori Tseitin showed the way around. Don't distribute. Give every subformula a fresh name, and write a few clauses saying the name means what it should. For t standing for x and y: if t then x; if t then y; and if x and y, then t. Three clauses for each connective, plus one saying that the whole formula's name is true. The size now grows in a straight line: for ten pairs, clauses instead of .

The new formula is not equivalent to the old one: it has new letters. But it is satisfiable exactly when the old one is, which is all a solver needs. So from now on, every question is a list of clauses, and 'is this argument valid?' becomes 'are these clauses, together with the negation of the conclusion, unsatisfiable?' That is the question the solvers of Chapters nine to eleven answer.

Not every list of clauses is equally hard. A clause with at most one un-negated atom is called a Horn clause, after the logician Alfred Horn, and it is just a rule: not rain, or wet, says 'if it rains, the streets are wet'. Given facts, rain and cold, a solver needs no search at all. It fires every rule whose conditions are known, and keeps going: . That is unit propagation from the last chapter's toolbox, and for Horn clauses it decides satisfiability in linear time. It is the engine of the programming language Prolog and of the rule-based expert systems of the 1980s. Clauses of two literals are easy too. With three literals per clause, the problem becomes as hard as any problem whose answers can be checked quickly, as we will see in Chapter twelve.

What it establishes: CNF from the false rows; clauses and DIMACS; the 2ⁿ blowup of distribution; Tseitin's linear encoding (1968); Horn clauses and forward chaining; 2-SAT and 3-SAT.; Computed on screen: distribution vs Tseitin clause counts for n = 1 … 12; a forward-chaining run, checked by entailment

6Natural deductionIntroductory3 min

Truth tables tell you whether an argument is valid. They don't tell you why, and they don't scale. Proofs do both: a chain of small steps, each licensed by a rule, from the premises to the conclusion. In 1934 and 1935, Stanisław Jaśkowski and Gerhard Gentzen independently designed a proof system meant to look like ordinary reasoning, and Gentzen called it natural deduction. Every connective gets two kinds of rule: one to introduce it, one to eliminate it.

Some rules simply say what the connective means. From A and from B, infer A and B; from A and B, infer A. Others use temporary assumptions. To prove 'if A then B', assume A, derive B under that assumption, then discharge it and conclude 'if A then B'. That is conditional proof. Negation works the same way: if assuming A leads to a contradiction, the false constant written as an upside-down T, conclude not A. And from a contradiction, anything follows.

Here is modus tollens, proved rather than tabulated, in the layout Frederic Fitch introduced in 1952. The premises: if p then q; not q. Now assume p, for the sake of argument. The bar marks how long the assumption lives. From p and 'if p then q', q: that is arrow elimination. But we also have not q: a contradiction. So the assumption has to go. Close its box, and conclude not p. Six lines, each one a rule anyone can check.

Checking a proof is mechanical, so the Reasoner does it: it looks at each line, the rule it cites and the lines that rule uses. It accepts our proof. Now change the last line: instead of discharging the assumption, reuse the q we derived inside the box. The checker refuses: . That q only held while p was assumed. Never use what was only assumed for the sake of argument: that rule is the whole point of the boxes.

Not every tautology comes so easily. Here is Peirce's law, proved in lines with two nested assumptions. Look at the line that does the real work. It drops a double negation: from not not p, infer p. Excluded middle, p or not p, needs the same rule, and so does every proof of Peirce's law.

Remove that one rule and you get intuitionistic logic, the logic of the Dutch mathematician L. E. J. Brouwer. Brouwer held that to assert 'p or not p' you must be able to say which, and that a proof of 'not not p' is not yet a proof of p. Every table in this part says that excluded middle is a tautology, so on his view the tables themselves assume too much. Part 9 builds his logic, with its own semantics. One innocent-looking rule marks one of the deepest divides in the philosophy of mathematics.

What it establishes: Jaśkowski and Gentzen; introduction and elimination rules; Fitch's boxes; modus tollens proved; the checker rejects a misuse of a closed subproof; Peirce's law and excluded middle need ¬¬E: the intuitionist divide (Part 9).; Computed on screen: four proofs checked by the Reasoner; the broken one rejected with its message

7Soundness: proofs never lieAdvanced4 min

We now have two ways of saying that a conclusion follows from premises. One is about proof: there is a derivation, written with a single turnstile. The other is about truth: every valuation that makes the premises true makes the conclusion true, the double turnstile. Proof is something we do, with marks on paper, and anyone can check it. Truth is about every way the world might be. Are the two the same? Two theorems answer, one for each direction. The first is soundness: whatever we can prove is valid. Proofs never lie.

The proof follows the shape of proofs: induction on their length. A premise is true in every valuation that makes the premises true, trivially. Then show that every rule, applied to lines that are true in a valuation, produces a line that is true in it. Each rule's condition is a small entailment or tautology of its own, so the Reasoner checks them all, one by one. All pass.

The rules that close boxes need a little more care, because the premises change inside a box. Arrow introduction says: if the premises together with A lead to B, then the premises alone lead to 'if A then B'. Its condition is this formula, with G standing for the premises: and it is a tautology, so the step is safe whatever G says.

Compare a rule we must not add: from 'if A then B' and B, infer A, affirming the consequent as a rule. The Reasoner finds its countermodel at once: A false, B true. A system with that rule would prove false conclusions from true premises. Soundness has a corollary. No valuation makes the false constant true, so no proof from no premises can ever reach it: the system is consistent. What we can check never outruns what is so.

Soundness also says something about what rules can and cannot do. In 1960 Arthur Prior invented a connective he called tonk, with an introduction rule like 'or': from A, infer A tonk B; and an elimination rule like 'and': from A tonk B, infer B. Two harmless-looking rules, and together they prove anything from anything. From 'it rains', infer 'it rains tonk the moon is cheese', and then 'the moon is cheese'.

Could some truth table make tonk sound? Its introduction needs it true whenever A is true; its elimination needs B true whenever it is. The Reasoner checks all sixteen tables. make the introduction sound, make the elimination sound, and none does both: in the row where A is true and B false, the demands collide. Nuel Belnap's reply, in 1962, was that rules can give a word its meaning only if they are in harmony with the rest of the language: adding them must prove nothing new about the old words. Our rules pass that test; tonk's do not. The question of how rules give meaning returns in Part 28.

What it establishes: ⊢ and ⊨; soundness by induction on proofs; each rule's condition a tautology; an unsound rule's countermodel; consistency as a corollary.; Computed on screen: the ten rule conditions checked; the countermodel

8Completeness: every validity has a proofResearch4 min

Soundness says the rules never prove too much. Completeness says they never prove too little: if a conclusion follows from the premises in every valuation, then there is a derivation of it, using only the handful of rules from Chapter six. Paul Bernays proved it for propositional logic in 1918, Emil Post in 1921 by other means, and Kurt Gödel, in 1929, for the far richer logic of Part 3.

The proof turns the question around. Suppose the conclusion phi cannot be proved. Then adding not phi to the premises can never lead to a contradiction: if it did, negation introduction and double-negation elimination would prove phi after all. The set is consistent. So suppose we can show that every consistent set has a model, a valuation that makes all of it true. Then some valuation makes the premises true and phi false, and the argument is not valid. That is completeness, read backwards.

Consistency is a fact about proofs: no derivation of a contradiction. Having a model is a fact about truth. The whole weight of the theorem rests on the highlighted step, which builds a bridge from the first kind of fact to the second.

The bridge is due to Adolf Lindenbaum. List every formula there is, one after another: they can be counted, like words in a dictionary. Start with a consistent set: here, p or q, and not p. Now go down the list. For each formula, add it if the set stays consistent; otherwise, add its negation. The first is : . And so on, forever. Here are the first fourteen steps, computed.

In the limit, the set decides every formula: it contains each one or its negation, and it is still consistent, since any contradiction would use finitely many of its members, and every finite stage is consistent. Now read off a valuation: make an atom true exactly when the set contains it. A truth lemma, proved by induction on formulas, says this valuation makes true exactly the formulas in the set. So every consistent set has a model, and completeness is proved.

The construction has a remarkable consequence, called compactness. If every finite subset of a set of sentences can be made true, so can the whole set, even when the set is infinite. For example: an infinite map can be coloured with four colours, so that neighbours differ, as long as every finite piece of it can be. Nicolaas de Bruijn and Paul Erdős proved that in 1951. One sentence per country; every finite set satisfiable; so the whole map is colourable.

In propositional logic, then, proof and truth coincide exactly: what is valid can be proved, and what can be proved is valid. Nothing true escapes the rules. Compactness returns in Part 3, where it conjures numbers larger than every natural number, and the agreement of proof and truth breaks for good in Part 7.

What it establishes: completeness (Bernays 1918, Post 1921, Gödel 1929); the contrapositive strategy; Lindenbaum's lemma run; the truth lemma; compactness and de Bruijn–Erdős (1951).; Computed on screen: 14 steps of Lindenbaum's construction and the valuation it decides; a properly coloured map (schematic)

9One rule: resolutionAdvanced3 min

Natural deduction has ten rules, and needs a person to choose which to use next. Resolution has one rule, and a machine can apply it blindly. From a clause containing x, and a clause containing not x, infer the clause made of everything else. A or x; B or not x; therefore A or B. It is sound by cases. If x is true, the second clause needs B. If x is false, the first needs A. Either way, A or B. And when the two clauses are just x and not x, nothing is left: the empty clause, drawn as a box, which no valuation can satisfy. A contradiction, in its purest form.

Resolution proves things by refutation. To show that premises entail a conclusion, add the conclusion's negation, turn everything into clauses, and resolve until the empty clause appears. If it does, the premises and the negated conclusion cannot all be true: the conclusion follows. Martin Davis and Hilary Putnam used resolution on propositional clauses in 1960. In 1965 John Alan Robinson made it the single rule of a prover for the full logic of Part 3, and it has been the engine of automated reasoning ever since.

Back to the island. Our two equations become clauses. To prove that B is a knight, add the opposite, not b, and look for the empty clause. The Reasoner finds a refutation in steps. Each step resolves two clauses already on the board, which flash as they are used.

Read it as an argument. A is a knave: the puzzle's clauses contain that directly, since a knight could never say 'we are all knaves'. Then, with B a knave, C would have to be both a knave and a knight. The box closes. B is a knight, as the table said, and now we know why.

Resolution is refutation complete: if a set of clauses is unsatisfiable, resolution eventually derives the empty clause. So it, too, decides validity. But blind resolution can generate enormous numbers of clauses, and choosing which pair to resolve next is the whole art. Our resolver takes the shortest clauses first, and throws away any clause that says more than one it already has. Even so, on a family of formulas we will meet in Chapter twelve, the count explodes. The next two chapters search for models instead, and learn as they go.

What it establishes: the resolution rule and its soundness by cases; refutation; Davis–Putnam (1960), Robinson (1965); the island refuted; refutation completeness.; Computed on screen: the island's 10 clauses and a 5-step refutation; resolution's growth on pigeonhole formulas

10Searching for a modelAdvanced3 min

A truth table tries every valuation. A smarter search builds a single valuation one step at a time, and backs up when it gets into trouble. This is the method of Martin Davis, George Logemann and Donald Loveland, from 1962, now called DPLL. It has three moves. Propagate: if every literal of a clause is false but one, that one is forced. If a is true, the clause not a or c forces c. Branch: when nothing is forced, pick an open atom and try true. Back up: if some clause has every literal false, undo the last choice and try the other value.

Here it is on a formula of clauses in five atoms, the Reasoner's own run, recorded.

The search visited nodes, where the table would have filled rows. On real problems the difference is astronomical, because one forced value forces another, in long chains, and a single conflict prunes a whole subtree at once. It is also how a careful person reasons from a hypothesis: suppose, follow the consequences, and when they clash, withdraw the supposition. DPLL is reductio ad absurdum, done systematically.

How hard is a random formula? Generate clauses of three random literals over n atoms, and turn one dial: the number of clauses per atom. With few clauses, almost every formula is satisfiable, and DPLL finds a model at once. With many, almost every formula is contradictory, and the conflicts come quickly. In between, near 4.27 clauses per atom, the chance of satisfiability falls from nearly one to nearly zero, more steeply as n grows. And near it, DPLL's work peaks: for 40 atoms, at clauses per atom; for small formulas the peak sits a little to the right of the threshold. The hardest formulas live on the knife edge between satisfiable and unsatisfiable, a phase transition, like water freezing. Ehud Friedgut proved in 1999 that the drop is sharp; exactly where it falls has been proved only for long clauses, by Jian Ding, Allan Sly and Nike Sun in 2015.

What it establishes: propagate, branch, back up (Davis, Logemann and Loveland 1962); a recorded search; reductio, done systematically.; Computed on screen: the search tree (6 nodes, 2 conflicts) and its model; narration generated from the run

11Learning from conflictApplied3 min

DPLL forgets. When a branch fails, it backs up one step and tries again; and if the same mistake lurks elsewhere in the tree, it rediscovers it, again and again. In 1996 João Marques-Silva and Karem Sakallah, with their solver GRASP, taught the search to learn from every failure. Five years later, the solver Chaff made the idea fast. Conflict-driven clause learning is inside every serious SAT solver today.

Watch it on a formula of clauses in eight atoms, the Reasoner's own run. First decision: a is true. Propagation follows. a forces b, and c. b and c together force d. d forces e. d and e force f. Draw each forced value with arrows from the values that forced it, and you have the implication graph. Then a clause fails: not f or not a. Conflict.

Now ask why. Trace the conflict back through the graph toward the decisions that caused it. Every path leads back to one cause: deciding a. So learn a clause that forbids that cause: not a. It follows from the formula, by resolving along the graph, so adding it rules out no satisfying valuation; but the solver will never make this mistake again, anywhere in the search.

Then jump back: not one step, but to the level where the learned clause first becomes useful, here the very top, before any decision. The learned clause forces not a at once. Then propagation forces g, h and b. Deciding d forces e and f, and one last decision, c, leaves every clause satisfied. One conflict, one lesson, and the search never returned to the dead end.

Does learning pay? Here are random formulas at the ratio of clauses to atoms where they are hardest, formulas at each size, solved by the Reasoner's DPLL and its CDCL. As the formulas grow, CDCL needs far fewer decisions: at fifty atoms, a median of , against . Industrial solvers add much more, and handle formulas with millions of atoms. Underneath is a deep fact: what CDCL learns are resolvents, so it is resolution in disguise. With restarts it can simulate any resolution proof, as Knot Pipatsrisawat and Adnan Darwiche showed in 2011. Which means that whatever makes resolution slow makes CDCL slow too. That is the next chapter.

What it establishes: GRASP (1996) and Chaff (2001); the implication graph; first-UIP learning; the backjump; CDCL as resolution (Pipatsrisawat and Darwiche 2011).; Computed on screen: a recorded run: one conflict, the learned clause ¬a, the finish; DPLL vs CDCL decisions on random 3-SAT, n = 20 … 60, 7 seeds

12The price of calculationResearch4 min

Every solver we have built works on small examples. The real question is how the work grows with the size of the problem. Some problems can be solved in time that grows like a polynomial in their size: sorting a list, finding a shortest path. Call that class P. Others have answers that are quick to check, once someone hands you one. A satisfying valuation is checked clause by clause in a moment. Call that class NP. Whether every problem with quickly checked answers also has quickly found answers, whether P equals NP, is the most famous open problem in computer science, one of the Clay Institute's million-dollar Millennium Problems.

In 1971 Stephen Cook, and independently Leonid Levin in Moscow, proved that SAT is NP-complete. Take any problem whose answers can be checked quickly, by some machine. Write the machine's whole run as a grid: one row for each moment, one column for each cell of its tape. Make an atom for every fact of the form 'at time t, cell i holds symbol s'. Then write clauses saying that each row follows from the one above by the machine's rules, and that the last row says 'accept'. These clauses are satisfiable exactly when the problem has an answer. So a fast method for SAT would be a fast method for everything whose answers can be checked: timetables, protein design, and breaking most of today's encryption. Most researchers believe there is none.

Even a formula that is obviously false can be expensive to refute. Put n plus one pigeons into n holes, at most one pigeon per hole. Anyone can see it can't be done. As clauses: every pigeon is in some hole; no two pigeons share a hole. In 1985 Armin Haken proved that every resolution refutation of these formulas is exponentially long, however cleverly it is found.

Here is what our own solvers did. Resolution generated clauses as the holes went from one to . CDCL needed conflicts for holes, roughly times more with each hole added. And the truth table, for holes, would need two to the rows.

Is that a limit of proof itself, or only of resolution? Stronger proof systems do better. Extended resolution, which may name new ideas the way Tseitin's encoding names subformulas, has short proofs of the pigeonhole principle, as Cook showed in 1976. Whether some proof system has short proofs of every tautology turns out to be the same question as whether NP equals its mirror image, coNP, posed by Stephen Cook and Robert Reckhow in 1979. It is open.

So here is the second brick of the Wall. Leibniz's calculation exists: every question of propositional validity can be settled mechanically, by anyone, with the same answer every time. But unless P equals NP, some of those questions cost more to settle than the universe can pay. The dream survives, with a price tag.

What it establishes: P and NP; Cook–Levin (1971, 1973) by the tableau; the pigeonhole principle and Haken (1985); extended resolution (Cook 1976); Cook–Reckhow (1979); the Wall's second brick.; Computed on screen: resolution (3 → 586,005 clauses) and CDCL (up to 1,608 conflicts) on PHP(n+1, n), n ≤ 7

13SAT at workApplied3 min

In 1994 the mathematician Thomas Nicely noticed that Intel's new Pentium processor got certain divisions wrong. Intel estimated about one random division in nine billion. It replaced the chips, at a cost of four hundred and seventy-five million dollars. After that, chip makers turned to proof: write the chip's logic as formulas, and check it against its specification for every input, not a sample. One method, bounded model checking, from 1999, unrolls a circuit over k clock cycles: a copy of its transition logic for each step, the starting state at one end, and the failure of a property at the other. Is there an input sequence that reaches the failure? One SAT question. If the answer is no, no input can break the chip within k steps.

In the cloud, the same idea guards data. Amazon's tool Zelkova translates the access policies that customers write into logic, and asks a solver whether some request could be allowed that would expose the data to the public. The solvers here are SMT solvers: SAT solvers extended with arithmetic, strings and other theories. In 2022 Amazon's Neha Rungta reported that such checks were running about a billion times a day.

Installing software is a logic problem too. Each package demands certain versions of others and conflicts with some: clauses. Here, A one needs version two or three of B, C one cannot live with B three, and only one version of B can be installed. The Reasoner's solver picks B two. With thousands of packages this is a real search: deciding whether a package can be installed at all is NP-complete, and package managers, from Linux distributions to the scientific Python installer conda, hand it to SAT-style solvers.

And in mathematics. The Pythagorean triples of the opening, in 2016. The fifth Schur number, 160, the next year, with a proof of two petabytes. Keller's conjecture about tilings by cubes, in dimension seven, in 2020. Each is a theorem that no person has checked line by line, certified instead by a proof checker small enough to verify on its own.

Is a two-hundred-terabyte certificate a proof? The question is older than these solvers. In 1976 Kenneth Appel and Wolfgang Haken proved the four-colour theorem with a computer, and three years later the philosopher Thomas Tymoczko argued that accepting it meant changing what we mean by proof: that mathematics had admitted experiment. Today the standard answer is formal: a certificate is a proof if a small, trusted program checks it. Part 9 asks what such a check shows, and what it leaves out.

What it establishes: the Pentium FDIV bug (1994) and bounded model checking (1999); Zelkova and SMT at AWS; package installation; Schur 5, Keller 7; Appel–Haken (1976) and Tymoczko (1979) on computer proofs.; Computed on screen: a dependency problem solved by the Reasoner

14Socrates as a SAT solverIntroductory3 min

Socrates' method was a kind of calculation. In Book One of Plato's Republic, the old man Cephalus suggests that justice is telling the truth and giving back what one owes. Socrates asks: suppose a friend, in his right mind, leaves weapons with you, then goes mad and asks for them back. Ought you to return them? Three claims. Justice is giving back what is owed. Returning the weapons is giving back what is owed. And returning them, to a madman, is not just. Each is plausible; together they are inconsistent.

Cephalus leaves to see to a sacrifice, and his son Polemarchus takes over the argument with a new definition: justice is helping one's friends and harming one's enemies. So the just will sometimes harm an enemy. Socrates presses. Harming a person makes him worse in human excellence, and justice is a human excellence: harming makes a person less just. But it cannot be the work of justice to make anyone less just. Four more claims, a second contradiction.

Feed all claims to the Reasoner, each as a formula: o for 'returning the weapons is giving back what is owed', j for 'it is just', and so on. It checks every one of the subsets of claims for consistency, and returns the minimal inconsistent ones: sets that are contradictory, but stop being so if any single claim is removed. There are exactly : the two contradictions Socrates found, and no others hiding in the mixture.

Now the question an interlocutor actually faces: which claims to give up? A minimal correction set is a smallest set of claims whose removal restores consistency. Here there are : one claim from the first contradiction and one from the second, in every combination. That is no accident. A theorem of Raymond Reiter, from 1987, says the minimal correction sets are exactly the minimal hitting sets of the minimal inconsistent ones: the smallest ways of breaking every contradiction at once.

Socrates' own choice was one of these: give up both definitions. The logic did not choose for him. It showed exactly where the choices were. This is the engine of the series' Price List. For each great puzzle we will state the plausible claims, let the machine find every exit, and label each exit with the philosophers who take it, and, where the 2020 PhilPapers survey asked, how many philosophers take it.

What it establishes: Republic I: Cephalus and Polemarchus; minimal unsatisfiable subsets; minimal correction sets; Reiter's hitting-set duality (1987); the Price List engine.; Computed on screen: 128 subsets checked: 2 MUSes, 12 MCSes, duality verified

15The first Price List: the problem of evilIntroductory3 min

The argument is very old. Lactantius, writing around the year 300, attributed it to Epicurus. David Hume gave it to Philo in his Dialogues Concerning Natural Religion: Is he willing to prevent evil, but not able? then is he impotent. Is he able, but not willing? then is he malevolent. Is he both able and willing? whence then is evil? In 1955 J. L. Mackie sharpened it into a charge of inconsistency. The theist's beliefs, he said, are not merely unsupported but positively irrational: they contradict one another.

State it as six claims. God exists. God is omnipotent. God is omniscient. God is wholly good. A good, all-knowing, all-powerful being would prevent all evil. And there is evil. The Reasoner confirms Mackie: the six are inconsistent. And the only minimal inconsistent set is all six of them. So the positions are exactly six: give up any one claim, and consistency returns.

Give up the first: there is no God. That was Mackie's own conclusion, and in the 2020 PhilPapers survey about two in three philosophers accepted or leaned toward atheism.

Give up omnipotence: God's power is limited. Process theologians, after Whitehead and Hartshorne, hold that God persuades rather than coerces.

Limit what God knows: some open theists hold that the future free choices of creatures are not yet there to be known.

Give up perfect goodness: an exit very few philosophers take. Deny that evil is real: some traditions call it illusion. Augustine's view, that evil is a privation, an absence of good, comes close to this exit without quite taking it.

Or give up the bridge premise: a good, all-powerful being might allow evil for the sake of a greater good. Alvin Plantinga's free-will defense, from 1974, argues that a world of free creatures who sometimes do wrong may be better than any world God could make without evil. Most philosophers, theists or not, now agree that this exit is at least logically open, and that the purely logical problem of evil fails.

Notice what the calculation did, and what it did not. It found every exit, exactly, with nothing overlooked. It did not say which exits are open. Whether free will is worth the evil it permits is not a question of propositional logic. Part 23 returns to it, where the argument becomes one about probabilities.

And notice one more thing. We wrote 'all evil' and 'every being' inside the atoms, where the logic cannot see them. Propositional logic can't look inside a sentence. 'All humans are mortal; Socrates is human; so Socrates is mortal' is, to it, p and q, therefore r: invalid, with a countermodel. To see inside sentences we need 'all' and 'some', quantifiers. That is Part 3.

What it establishes: Epicurus, Hume's Philo, Mackie (1955); the first Price List: six claims, six positions (atheism, process theology, open theism, dystheism, evil as illusion, the free-will defense); what propositional logic cannot see.; Computed on screen: the MUS (all six) and the six MCSes; the Socrates syllogism's countermodel

Recap, problems, and where this comes backAll tracks2 min

Let's gather what we built. Boole wrote logic as algebra, and his law x squared equals x gave logic its two values. Formulas are trees; there are sixteen ways to connect two sentences, and one, nand, is enough for all of them, by Post's criterion. Validity is truth preserved in every valuation, decidable by truth tables, at a cost of two to the n rows. Normal forms turn every question into a list of clauses. Natural deduction gives proofs a machine can check, and soundness and completeness say that proof and truth agree exactly. Resolution, DPLL and clause learning are the solvers inside industry. SAT is NP-complete, and some obvious truths have only enormous proofs. And Socrates' method, run as SAT, lists every way out of a contradiction.

The Reasoner now has its first module: formulas, tables, normal forms, a proof checker, three solvers, and the Price List engine, each tested against brute force. Every later part adds to it, and Part 39 will use this very SAT solver to check a case of Arrow's theorem about voting. And the Wall has its second brick: the price of calculation.

Six problems, with full solutions in this part's notes. Two on connectives and proofs, one on encodings, one more island, one half of Reiter's theorem, and one to argue with Socrates. Pause here, and try them.

Where this comes back. The SAT solver and the Price List return in the sorites, the problem of evil, the mind and body, free will, and Arrow's theorem. Completeness and compactness return in Parts 3 and 7. The double-negation rule is where Part 9's intuitionists get off. Philo's conditional is cross-examined in Part 14. And next, in Part 3, we open up the atoms: 'all', 'some', relations and models, Gödel's completeness theorem, and the first result that no calculation can get around.

The books and papers this part follows are on screen, and in the notes. Thanks for watching.

Where it goes next. The Price List engine (minimal inconsistent and minimal correction sets) is used in every later part; quantifiers, which propositional logic cannot see, are Part 3; compactness returns in Parts 3 and 6; the rule of double negation divides classical from intuitionistic logic in Part 9; the problem of evil returns as an argument about probabilities in Part 23, and the SAT solver checks a case of Arrow's theorem in Part 39.

Key results

The part's results in one place, for revision.

Consequence, by table\(\displaystyle \Gamma\models\varphi\iff\text{no }\allowbreak \text{row }\allowbreak \text{of }\allowbreak \text{the } 2^{n} \text{ makes } \Gamma \text{ true }\allowbreak \text{and } \varphi \text{ false}\)
Soundness and completeness\(\displaystyle \Gamma\vdash\varphi\iff\Gamma\models\varphi\)
Resolution\(\displaystyle \frac{C\lor p\qquad\allowbreak D\lor\lnot p}{C\lor D}\,,\qquad\allowbreak \Gamma\ \text{unsatisfiable}\iff\Gamma\vdash_{\mathrm{res}}\Box\)
Tseitin's encoding\(\displaystyle k \text{ binary }\allowbreak \text{connectives, } m \text{ of }\allowbreak \text{them } \leftrightarrow:\quad\allowbreak 3k+m+1 \text{ clauses}\)
The price\(\displaystyle \text{SAT }\allowbreak \text{is }\allowbreak \text{NP-complete};\qquad\allowbreak \text{resolution }\allowbreak \text{on } \mathrm{PHP}^{n+1}_{n} \text{ needs }\allowbreak \text{size } 2^{\Omega(n)}\)
Reiter's duality\(\displaystyle \text{MCSes}=\text{minimal }\allowbreak \text{hitting }\allowbreak \text{sets }\allowbreak \text{of }\allowbreak \text{the }\allowbreak \text{MUSes}\)

Try it

Lab 2 · The Price List engine and two SAT solvers

Feed the seven claims of Republic I to the Reasoner, list every minimal inconsistent set and every minimal way out, and check Reiter's duality between them. Then solve random 3-SAT formulas by DPLL and by CDCL, check both against the truth table, and count their decisions.

Figure produced by Lab 2: The Price List engine and two SAT solvers
Produced by the lab below, seed 0, in 0.6 s.
python -m videos.philosophy.labs 2 needs numpy, scipy, matplotlib · download lab02.py · source on GitHub
Republic I: subsets of the 7 claims checked         128
minimal inconsistent sets                           2:  {D1, o, nj}  {D2, h, H, N}
minimal correction sets (the exits)                 12   (3 x 4: one claim from each contradiction)
exits = minimal hitting sets of the contradictions  True
solvers agree with the truth table (n = 10, 14)     18 of 18 formulas
median decisions at n = 40                          DPLL 166   CDCL 24   (truth table: 2^40 rows)
CDCL conflicts on PHP(n+1, n), n = 1 ... 5          0  2  10  33  108
growth per added hole (last step)                   x 3.3

The machine finds every exit from Socrates' two contradictions and nothing else; the same search, scaled up, is a SAT solver, and the pigeonhole formulas show what it costs.
The code (119 lines; it asserts its own result)
"""Lab 2: run Socrates' elenchus as a search for minimal correction sets, and race DPLL against CDCL."""

import random

import numpy as np

from videos.coursekit import labs
from explainer.philosophy.reasoner import prop

TITLE = "The Price List engine and two SAT solvers"
GOAL = ("Feed the seven claims of Republic I to the Reasoner, list every minimal inconsistent set and every minimal "
        "way out, and check Reiter's duality between them. Then solve random 3-SAT formulas by DPLL and by CDCL, "
        "check both against the truth table, and count their decisions.")
TASKS = [
    "Add an eighth claim that Polemarchus might accept (for example 'j2 -> j') and rerun mus_mcs. How many minimal "
    "inconsistent sets and how many exits are there now?",
    "Change the ratio 4.26 to 3.0 and then to 6.0. What happens to the share of satisfiable formulas and to the "
    "number of decisions each solver needs?",
    "Push the pigeonhole formulas to n = 6 and 7 holes and compare CDCL's conflicts with prop.dpll's on the same "
    "formulas.",
]

REPUBLIC = {  # Republic I, as in the film's Chapter 14
    "D1": "o -> j",      # justice is giving back what is owed
    "o": "o",            # returning a mad friend's weapon is giving back what is owed
    "nj": "~j",          # returning it is not just
    "D2": "h -> j2",     # justice is helping friends and harming enemies
    "h": "h",            # the just will sometimes harm an enemy
    "H": "h -> w",       # harming a person makes them less just
    "N": "j2 -> ~w",     # it is not the work of justice to make anyone less just
}


def brute_force(clauses, n):
    """Is some row of the truth table a model?  (numpy over all 2^n rows)"""
    rows = ((np.arange(2 ** n)[:, None] >> np.arange(n)) & 1).astype(bool)  # rows[r, v-1]: the value of atom v
    ok = np.ones(2 ** n, bool)
    for c in clauses:
        sat = np.zeros(2 ** n, bool)
        for lit in c:
            sat |= rows[:, abs(lit) - 1] == (lit > 0)
        ok &= sat
    return bool(ok.any())


def run(seed=0):
    lab = labs.Lab()
    r = prop.mus_mcs({k: prop.parse(f) for k, f in REPUBLIC.items()})
    hitting = {tuple(sorted(h)) for h in prop.hitting_sets(r["mus"])}
    lab.row("Republic I: subsets of the 7 claims checked", f"{2 ** len(REPUBLIC)}")
    lab.row("minimal inconsistent sets", f"{len(r['mus'])}:  " + "  ".join("{" + ", ".join(m) + "}" for m in r["mus"]))
    lab.row("minimal correction sets (the exits)", f"{len(r['mcs'])}   (3 x 4: one claim from each contradiction)")
    lab.row("exits = minimal hitting sets of the contradictions", f"{hitting == {tuple(sorted(m)) for m in r['mcs']}}")
    assert not r["consistent"] and len(r["mus"]) == 2 and sorted(map(len, r["mus"])) == [3, 4]
    assert len(r["mcs"]) == 12 and all(len(m) == 2 for m in r["mcs"])
    assert hitting == {tuple(sorted(m)) for m in r["mcs"]}, "Reiter's duality"
    assert ("D1", "D2") in r["mcs"], "Socrates' own exit: give up both definitions"

    # Random 3-SAT at 4.26 clauses per atom: DPLL and CDCL against the truth table (small n), then their work.
    sizes, per = (10, 14, 20, 30, 40), 9
    dpll_med, cdcl_med, agree, checked, sat_share = [], [], 0, 0, []
    dd_all, cc_all = [], []
    for n in sizes:
        dd, cc, sat = [], [], 0
        for k in range(per):
            cl = prop.random_ksat(n, round(4.26 * n), 3, random.Random(10_000 * seed + 100 * n + k))
            m1, s1 = prop.dpll(cl, n)
            m2, s2 = prop.cdcl(cl, n)
            assert (m1 is None) == (m2 is None), "the two solvers agree"
            for m in (m1, m2):  # a model, when returned, satisfies every clause
                assert m is None or all(any(m[abs(x)] == (x > 0) for x in c) for c in cl)
            if n <= 14:
                checked += 1
                agree += brute_force(cl, n) == (m1 is not None)
            sat += m1 is not None
            dd.append(s1["decisions"])
            cc.append(s2["decisions"])
        dpll_med.append(float(np.median(dd)))
        cdcl_med.append(float(np.median(cc)))
        dd_all.append(dd)
        cc_all.append(cc)
        sat_share.append(sat / per)
    lab.row("solvers agree with the truth table (n = 10, 14)", f"{agree} of {checked} formulas")
    lab.row("median decisions at n = 40", f"DPLL {dpll_med[-1]:.0f}   CDCL {cdcl_med[-1]:.0f}   (truth table: 2^40 rows)")
    assert agree == checked
    assert cdcl_med[-1] < dpll_med[-1], "learning pays on the larger formulas"
    assert dpll_med[-1] < 2 ** 20, "far fewer steps than rows"

    # The pigeonhole principle: obviously false, expensive to refute.
    holes, conflicts = [1, 2, 3, 4, 5], []
    for n in holes:
        cl, nv = prop.pigeonhole(n)
        model, st = prop.cdcl(cl, nv)
        assert model is None, "n + 1 pigeons do not fit in n holes"
        conflicts.append(st["conflicts"])
    growth = conflicts[-1] / conflicts[-2]
    lab.row("CDCL conflicts on PHP(n+1, n), n = 1 ... 5", "  ".join(str(c) for c in conflicts))
    lab.row("growth per added hole (last step)", f"x {growth:.1f}")
    assert all(b > a for a, b in zip(conflicts, conflicts[1:])) and growth > 2, "conflicts grow geometrically"
    lab.note = ("The machine finds every exit from Socrates' two contradictions and nothing else; the same search, "
                "scaled up, is a SAT solver, and the pigeonhole formulas show what it costs.")

    fig, ax = labs.figure(2, size=(11, 4.2))
    x = np.array(sizes)
    for xs, ys, color in ((x - 0.6, dd_all, labs.BLUE), (x + 0.6, cc_all, labs.GOLD)):
        for xi, y in zip(xs, ys):
            ax[0].scatter(np.full(len(y), xi), np.maximum(y, 1), s=10, color=color, alpha=0.45)
    ax[0].plot(x, np.maximum(dpll_med, 1), "o-", color=labs.BLUE, label="DPLL (median)")
    ax[0].plot(x, np.maximum(cdcl_med, 1), "o-", color=labs.GOLD, label="CDCL (median)")
    ax[0].set(title="Random 3-SAT at 4.26 clauses per atom", xlabel="atoms n", ylabel="decisions", yscale="log",
              xticks=sizes)
    ax[0].legend(loc="upper left")
    ax[1].plot(holes, np.maximum(conflicts, 1), "o-", color=labs.RED, label="CDCL conflicts")
    ax[1].plot(holes, [2.0 ** ((n + 1) * n) for n in holes], "--", color=labs.MUTED, label="truth-table rows $2^{n(n+1)}$")
    ax[1].set(title="Pigeonhole formulas: n + 1 pigeons, n holes", xlabel="holes n", yscale="log", ylim=(0.5, 1e9),
              xticks=holes)
    ax[1].legend(loc="upper left")
    lab.fig = fig
    return lab

Now change it

  1. Add an eighth claim that Polemarchus might accept (for example 'j2 -> j') and rerun mus_mcs. How many minimal inconsistent sets and how many exits are there now?
  2. Change the ratio 4.26 to 3.0 and then to 6.0. What happens to the share of satisfiable formulas and to the number of decisions each solver needs?
  3. Push the pigeonhole formulas to n = 6 and 7 holes and compare CDCL's conflicts with prop.dpll's on the same formulas.

Problems, with solutions

Try each problem before opening its solution.

  1. Show that {→, ⊥} is functionally complete. Is {∨, →}?

    Solution

    ¬p ≡ p → ⊥ and p ∨ q ≡ ¬p → q ≡ (p → ⊥) → q, and {¬, ∨} is complete (De Morgan turns DNF into ¬ and ∨). By Post's criterion: → lies outside "keeps F" (F → F is T), outside "self-dual", "monotone" and "affine"; ⊥ lies outside "keeps T". {∨, →} is not complete: both keep T (each is true when all its inputs are), so everything built from them is true when every atom is, and ¬p is not.

  2. A Fitch proof of (p → q) → ((q → r) → (p → r)).

    Solution

    1 | p → q (assumption); 2 | | q → r (assumption); 3 | | | p (assumption); 4 | | | q (→E 1, 3); 5 | | | r (→E 2, 4); 6 | | p → r (→I 3–5); 7 | (q → r) → (p → r) (→I 2–6); 8 (p → q) → ((q → r) → (p → r)) (→I 1–7). The Reasoner's checker accepts it.

  3. Tseitin's clause count. How many clauses does Tseitin's encoding produce for a formula with \(k\) binary connectives, none of them \(\leftrightarrow\)? With \(m\) of them \(\leftrightarrow\)?

    Solution

    Our encoding gives each binary connective a fresh atom: three clauses for ∧, ∨ or →, four for ↔, and negations cost nothing (they flip a literal's sign). With k binary connectives of which m are ↔, that is 3(k − m) + 4m + 1 = 3k + m + 1 clauses, the 1 being the clause asserting the whole formula.

  4. The second island. On another island, A says 'B is a knave' and B says 'A and C are of the same kind'. What can you conclude about A? About C?

    Solution

    A ↔ ¬B and B ↔ (A ↔ C). If B is a knight, A and C are of the same kind; A's claim "B is a knave" is false, so A is a knave, so C is a knave. If B is a knave, A and C differ; A's claim is true, so A is a knight, so C is a knave. Two solutions (the Reasoner finds exactly these): nothing follows about A or B separately, but C is a knave either way.

  5. Every minimal correction set meets every minimal unsatisfiable subset.

    Solution

    Let M be an MCS and S an MUS, and suppose M ∩ S = ∅. Then S lies inside the complement of M, which is a maximal satisfiable subset; so S is satisfiable, contradicting its unsatisfiability. (The other half: a minimal hitting set H of the MUSes leaves a complement containing no MUS, hence satisfiable, and minimality of H makes it maximal.)

  6. (Essay) Another exit in Republic I. (Essay) In Republic I Socrates gives up both definitions. Make the best case for a different exit from one of the two contradictions.

    Solution

    Two good candidates. (a) Deny o: what is owed is what is fitting or due, so returning weapons to a madman is not owing anything; Polemarchus takes a version of this when he reinterprets Simonides, and much later Aristotle's account of justice as giving each what is due follows it. (b) Deny H: harming the wicked by punishment may make them better, not worse, a view Socrates himself defends in the Gorgias. A strong essay states the claim it rejects, the cost of rejecting it, and why that cost is lower than rejecting a definition.

Notes and sources

Sources

Books: Enderton, A Mathematical Introduction to Logic, ch. 1; van Dalen, Logic and Structure, chs. 1–2; Sider, Logic for Philosophy, ch. 2; Biere, Heule, van Maaren and Walsh (eds.), Handbook of Satisfiability (2nd ed., 2021); Kneale and Kneale, The Development of Logic.

Papers and texts: Diogenes Laertius VII.80 and Sextus Empiricus, Outlines II.157 (the indemonstrables) and Against the Mathematicians I.309 (Callimachus); Boole, An Investigation of the Laws of Thought (1854); Jevons, "On the Mechanical Performance of Logical Inference" (Phil. Trans. 1870); Sheffer (1913); Post, "Introduction to a General Theory of Elementary Propositions" (1921) and The Two-Valued Iterative Systems of Mathematical Logic (1941); Bernays (1926); Gentzen, "Untersuchungen über das logische Schließen" (1935); Jaśkowski (1934); Fitch, Symbolic Logic (1952); Tseitin (1968); Davis and Putnam (1960); Davis, Logemann and Loveland (1962); Robinson (1965); Cook (1971, 1976); Levin (1973); Cook and Reckhow (1979); Haken (1985); Marques-Silva and Sakallah (1996, 1999); Moskewicz et al. (2001); Pipatsrisawat and Darwiche (2011); Dowling and Gallier (1984); Aspvall, Plass and Tarjan (1979); de Bruijn and Erdős (1951); Biere, Cimatti, Clarke and Zhu (1999); Backes et al. (2018); Rungta (CAV 2022); Mancinelli et al. (2006); Heule, Kullmann and Marek (2016); Heule (2017); Brakensiek, Heule, Mackey and Narváez (2020); Appel and Haken (1977); Tymoczko (J. Phil. 1979); Reiter (1987); Liffiton and Sakallah (2008); Plato, Republic I 331c–335e (trans. Jowett); Hume, Dialogues Concerning Natural Religion X (1779); Mackie, "Evil and Omnipotence" (Mind 1955); Plantinga, God, Freedom, and Evil (1974); Hick, Evil and the God of Love (1966); Smullyan, What Is the Name of This Book? (1978); Bourget and Chalmers, "Philosophers on Philosophy: The 2020 PhilPapers Survey" (Phil. Imprint 2023).

About this partfrom its README

Part 2 of Philosophy, Built (series plan, syllabus): propositional logic, built and run. It is the first act's foundation, and the source of two devices the series uses throughout: the Reasoner's SAT solver and the Price List (Socrates' elenchus as minimal correction sets). Its brick in the Wall is the price of calculation: SAT is NP-complete, and resolution proofs of the pigeonhole principle are exponentially long.

Every table, proof, search and count on screen is computed by the Reasoner (explainer/philosophy/reasoner/prop.py, tested against brute force in tests/philosophy/test_prop.py) and cached by compute.py. Published facts (the 2016 Pythagorean-triples proof, the Pentium bug, Zelkova, the 2020 PhilPapers survey) are cited on screen. Schematics are labelled schematic.

Chapter notes
# Scene What it establishes Computed on screen
0 Hook Leibniz's calculemus; Smullyan's knights and knaves settled by a table; the Boolean Pythagorean triples (Heule, Kullmann and Marek 2016); the plan; the Wall and the Price List introduced. the 8-row table and its one surviving row; 1 … 400 two-coloured with no one-colour triple (294 triples) by our CDCL solver
1 Boole Chrysippus's five indemonstrables; Philo vs Diodorus on 'if'; Boole's algebra of classes; x² = x has the roots 0 and 1; the principle of contradiction derived; Jevons's logic piano (1869). Jevons's method on "iron is a metal; every metal is an element": 8 combinations, 4 struck, the conclusion read off
2 Syntax the grammar of formulas; parse trees and evaluation from the leaves; unique readability; the 16 binary truth functions; three demands single out Philo's conditional. the 16 truth tables; the filter 16 → 4 → 2 → 1
3 Post DNF, so {¬, ∧, ∨} is complete; De Morgan; Sheffer's nand (and Peirce's, 1880); XOR from four nand gates; Post's five classes and criterion (1941). the nand identities on all rows; the four-gate circuit swept; Post's table; completeness of 12 sets cross-checked by closure
4 Semantics valuation, tautology, satisfiability, ⊨; Peirce's law by table; six argument forms and their countermodels; Post and Wittgenstein (1921): a decision procedure; its 2ⁿ cost. Peirce's table; the verdicts; table time for 20 … 100 atoms; this machine's Python rows per second
5 Normal CNF from the false rows; clauses and DIMACS; the 2ⁿ blowup of distribution; Tseitin's linear encoding (1968); Horn clauses and forward chaining; 2-SAT and 3-SAT. distribution vs Tseitin clause counts for n = 1 … 12; a forward-chaining run, checked by entailment
6 Deduction Jaśkowski and Gentzen; introduction and elimination rules; Fitch's boxes; modus tollens proved; the checker rejects a misuse of a closed subproof; Peirce's law and excluded middle need ¬¬E: the intuitionist divide (Part 9). four proofs checked by the Reasoner; the broken one rejected with its message
7 Soundness ⊢ and ⊨; soundness by induction on proofs; each rule's condition a tautology; an unsound rule's countermodel; consistency as a corollary. the ten rule conditions checked; the countermodel
8 Completeness completeness (Bernays 1918, Post 1921, Gödel 1929); the contrapositive strategy; Lindenbaum's lemma run; the truth lemma; compactness and de Bruijn–Erdős (1951). 14 steps of Lindenbaum's construction and the valuation it decides; a properly coloured map (schematic)
9 Resolution the resolution rule and its soundness by cases; refutation; Davis–Putnam (1960), Robinson (1965); the island refuted; refutation completeness. the island's 10 clauses and a 5-step refutation; resolution's growth on pigeonhole formulas
10 DPLL propagate, branch, back up (Davis, Logemann and Loveland 1962); a recorded search; reductio, done systematically. the search tree (6 nodes, 2 conflicts) and its model; narration generated from the run
11 CDCL GRASP (1996) and Chaff (2001); the implication graph; first-UIP learning; the backjump; CDCL as resolution (Pipatsrisawat and Darwiche 2011). a recorded run: one conflict, the learned clause ¬a, the finish; DPLL vs CDCL decisions on random 3-SAT, n = 20 … 60, 7 seeds
12 Cost P and NP; Cook–Levin (1971, 1973) by the tableau; the pigeonhole principle and Haken (1985); extended resolution (Cook 1976); Cook–Reckhow (1979); the Wall's second brick. resolution (3 → 586,005 clauses) and CDCL (up to 1,608 conflicts) on PHP(n+1, n), n ≤ 7
13 Industry the Pentium FDIV bug (1994) and bounded model checking (1999); Zelkova and SMT at AWS; package installation; Schur 5, Keller 7; Appel–Haken (1976) and Tymoczko (1979) on computer proofs. a dependency problem solved by the Reasoner
14 Elenchus Republic I: Cephalus and Polemarchus; minimal unsatisfiable subsets; minimal correction sets; Reiter's hitting-set duality (1987); the Price List engine. 128 subsets checked: 2 MUSes, 12 MCSes, duality verified
15 Evil Epicurus, Hume's Philo, Mackie (1955); the first Price List: six claims, six positions (atheism, process theology, open theism, dystheism, evil as illusion, the free-will defense); what propositional logic cannot see. the MUS (all six) and the six MCSes; the Socrates syllogism's countermodel
16 Outro recap; the Reasoner's first module; the Wall; problems; payoffs; references. —

Companion material in this repository

The syllabus's plan for this partfrom SYLLABUS.md, the plan of record
  1. Boole's Laws of Thought (1854): algebra of classes, x² = x.
  2. Syntax: formulas as trees; connectives; truth functions. Every n-ary function is expressible, and Post's functional completeness theorem says which sets of connectives suffice ({NAND} does).
  3. Semantics: valuations; tautology, satisfiability, consequence ⊨. Truth tables filled live.
  4. Normal forms: CNF and DNF, with Tseitin's linear-size transformation.
  5. Natural deduction (Gentzen 1935): introduction and elimination rules; proof trees for contraposition and Peirce's law.
  6. Soundness, proved by induction on proofs.
  7. Completeness via maximal consistent sets (Lindenbaum's lemma).
  8. Compactness as a corollary; it returns in Parts 3 and 6.
  9. Resolution (Robinson 1965), with refutation completeness sketched.
  10. DPLL and CDCL: unit propagation, clause learning, the implication graph. Built and run live.
  11. Cook–Levin: SAT is NP-complete. The cost of calculation (the Wall).
  12. Pigeonhole formulas need exponential-size resolution proofs (Haken 1985); measured with our solver.
  13. Industry: SAT/SMT at work, including hardware verification, AWS Zelkova (verifying access policies), package managers, and the Boolean Pythagorean triples proof (Heule, Kullmann and Marek 2016; a 200 TB certificate).
  14. The elenchus as SAT: minimal unsatisfiable subsets (MUS) and minimal correction sets (MCS), with their hitting-set duality proved. This is the Price List engine.
  15. First full Price List: the problem of evil as an inconsistent quartet (God is omnipotent, omniscient and wholly good; there is evil). The MCSs are the positions; Part 23 returns to it.
  16. What propositional logic can't say (quantifiers), leading to Part 3.
  17. Recap and Problems.

Built: reasoner.prop (parser, truth tables, a natural-deduction checker, Tseitin, DPLL/CDCL, MUS/MCS enumeration via MARCO). Tested against brute force. Wall: NP-completeness; exponential lower bounds for resolution. Visuals: the formula tree evaluating bottom-up; CDCL's implication graph with a learned clause cutting it; the MUS/MCS hitting-set duality as a bipartite light-up. References: Enderton ch. 1; van Dalen chs. 1–2; Sider ch. 2; Biere et al., Handbook of Satisfiability; Liffiton and Sakallah 2008.

中文讲义

本讲的中文部分(与英文版对应)。

习题与解答
  1. 证明 {→, ⊥} 是函数完全的。{∨, →} 呢?

    解答

    ¬p ≡ p → ⊥,p ∨ q ≡ ¬p → q ≡ (p → ⊥) → q;而 {¬, ∨} 是完全的(德摩根律把析取范式改写成只用 ¬ 和 ∨)。用波斯特判据:→ 不在"保F"类中(F → F 为 T),也不在"自对偶""单调""仿射"类中;⊥ 不在"保T"类中。{∨, →} 不完全:两者都"保T" (所有输入为真时输出为真),所以由它们构造的一切公式在所有原子为真时都为真,而 ¬p 不是这样。

  2. (p → q) → ((q → r) → (p → r)) 的菲奇式证明。 给出 \((p \to q) \to ((q \to r) \to (p \to r))\) 的菲奇式证明。

    解答

    1 | p → q(假设);2 | | q → r(假设);3 | | | p(假设);4 | | | q(→E 1, 3); 5 | | | r(→E 2, 4);6 | | p → r(→I 3–5);7 | (q → r) → (p → r)(→I 2–6);8 (p → q) → ((q → r) → (p → r))(→I 1–7)。 推理机的检查器接受这个证明。

  3. 采廷编码的子句数。

    解答

    每个二元联结词得到一个新原子:∧、∨、→ 各三个子句,↔ 四个子句;否定不增加子句(只翻转文字的符号)。若共有 k 个二元 联结词,其中 m 个是 ↔,子句数为 3(k − m) + 4m + 1 = 3k + m + 1,最后的 1 是断言整个公式为真的那个子句。

  4. 第二座岛。 在另一座岛上,A说"B是无赖",B说"A和C是同一类人"。关于A,你能得出什么结论?关于C呢?

    解答

    A ↔ ¬B,B ↔ (A ↔ C)。若 B 是骑士,则 A 与 C 同类;A 说"B 是无赖"为假,所以 A 是无赖,从而 C 也是无赖。若 B 是无赖,则 A 与 C 不同类;A 的话为真,所以 A 是骑士,从而 C 是无赖。共两组解(推理机找到的正是这两组):A 和 B 各自是什么无法确定,但无论哪种情况,C 都是无赖。

  5. 每个极小修正集都与每个极小不可满足子集相交。

    解答

    设 M 是极小修正集,S 是极小不可满足子集,假设 M ∩ S = ∅。那么 S 包含在 M 的补集中,而这个补集 是一个极大可满足子集,所以 S 可满足,与 S 不可满足矛盾。(另一半:所有极小不可满足子集的一个极小碰集 H,其补集不含任何极小不可满足子集,因而可 满足;H 的极小性保证这个补集是极大的。)

  6. (论述题)《理想国》第一卷的另一条出路。

    解答

    两个好的候选:(a) 否认 o:所"欠"的是"应得的、恰当的",因此把武器还给疯子并不是在还所欠之物; 玻勒马霍斯重新解释西蒙尼德斯时走的正是这条路,后来亚里士多德把正义理解为"给每个人以其所应得",也延续了这一思路。(b) 否认 H:用惩罚去伤害恶人, 可能使他们变好而不是变坏,苏格拉底本人在《高尔吉亚篇》中就为这一观点辩护。一篇好的论述应当说明它拒绝哪个主张、拒绝的代价是什么,以及为什么 这个代价比放弃一个定义更低。

Build the film

python -m videos.philosophy.philosophy2.compute        # the part's numbers, into .cache/philosophy2
python tools/build.py philosophy2                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py philosophy2 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/philosophy/philosophy2. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it
python -m videos.philosophy.philosophy2.compute        # every computed item (about 30 s; cached in .cache/philosophy2)
python tools/build.py philosophy2 -q l                 # 480p preview
python tools/build.py philosophy2                      # 1080p30 -> renders/philosophy2.mp4
python tools/qa_scene.py philosophy2 CDCL              # one chapter, silent, with a contact sheet