PPhilosophy, Built

Act I · The Machinery of Reason

Part 4 of 42

Necessity and Possibility

modal logics

Introductorystarts at this level50 min of film17 chaptersprerequisites: Part 2, Part 3

What do 'must', 'might', 'ought' and 'always' have in common, and what decides which of their laws hold?

Aristotle asks whether it is already true that there will be a sea battle tomorrow, and Diodorus Cronus answers with the Master Argument: three claims that cannot all be true, and three ancient exits. C. I. Lewis's strict implication turns the puzzle into axiom systems, S1 to S5, with fourteen modalities in S4 and six in S5. Kripke gives them one semantics: worlds, arrows saying which worlds each world can see, and a box that means 'true in every world seen'. Then each axiom turns out to be a shape of arrows (T reflexive, 4 transitive, B symmetric, 5 euclidean, D serial), proved and checked on every frame of up to four worlds. The turn is Löb's axiom, valid exactly on the transitive frames with no infinite ascending chain, a condition no first-order sentence states: modal logic is not first-order logic in disguise. Canonical models, bisimulation and filtration give completeness, the limit of what the box can see, and decidability. The part ends with the box read as obligation, as time and as the runs of a program, and a model checker that verifies Peterson's mutual-exclusion protocol and finds the eight-step failure of a broken variant.

What you need. Propositional logic (Part 2) and the idea of a relation; graphs drawn with arrows.

The calculation
Kripke semantics
The wall
correspondence limits (Goldblatt–Thomason)
Built toy
Kripke and LTL model checker; Peterson's mutex verified

What you will be able to do

Introductory

  • Evaluate formulas with box and diamond at each world of a small Kripke model.
  • State the Master Argument as three jointly inconsistent claims and say which one Diodorus, Cleanthes and Chrysippus each gave up.
  • Read the box as necessity, knowledge, obligation or 'always' and say what the arrows mean under each reading.

Advanced

  • Prove both directions of a correspondence (T and reflexivity, 4 and transitivity, B and symmetry), giving the refuting valuation when the frame lacks the property.
  • Compute the largest bisimulation between two models and use it to show that a property is not modally definable.
  • Filter a model through the subformulas of a formula and explain why K, T, S4 and S5 are decidable.

Research

  • Show by compactness that the frame condition of Löb's axiom is not first-order, and state the Goldblatt-Thomason and Sahlqvist theorems.
  • Carry out the canonical-model proof of completeness for K, and say why it works for T and 4 and fails for GL.

Applied

  • Specify mutual exclusion and freedom from starvation in temporal logic, and explain what fairness adds.
  • Read a model checker's counterexample trace, and write a loop invariant for a Hoare triple.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Introductory 14 min · Advanced 44 min · Research 50 min · Applied 25 min.

  1. 0Ways things might have beenIntroductory3 min
  2. 1The sea battle and the master argumentIntroductory3 min
  3. 2Strict implication and the systems S1–S5Advanced3 min
  4. 3Possible worlds, made preciseIntroductory3 min
  5. 4Axioms and framesAdvanced4 min
  6. 5Löb's axiom and the limits of correspondenceResearch4 min
  7. 6Completeness by canonical modelsResearch2 min
  8. 7What modal logic cannot seeAdvanced3 min
  9. 8Finite models and decidabilityAdvanced4 min
  10. 9Quantifiers and modalityAdvanced3 min
  11. 10The logic of obligationIntroductory3 min
  12. 11The logic of timeAdvanced3 min
  13. 12Temporal logic for machinesApplied3 min
  14. 13Checking a mutual-exclusion protocolApplied3 min
  15. 14Programs as modalitiesApplied2 min
  16. 15Model checking at workApplied3 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.

Ways things might have beenIntroductory3 min

Parts 2 and 3 built the logic of what is the case. But most of what we say goes beyond that. It might have rained. Two plus two must be four. You ought to keep your promise. The lift will always come eventually. Might, must, ought, always: these are modalities, ways in which a sentence is true. This part builds their logic, and it turns out to be one logic with many readings, from metaphysics to the chips in your phone.

Write a box for 'necessarily'. The same box can mean that something is necessary, that an agent knows it, that it is obligatory, that it will always be so, that it is provable in arithmetic, or that it holds after every run of a program. The remarkable discovery of the twentieth century is that all of these share one logic and one semantics: possible worlds, and a relation saying which worlds can be seen from which.

Here is the whole idea in one picture. Four worlds, and arrows saying which worlds are possible from which. In two of them, p is true. 'Necessarily p' is true at a world when p is true in every world it can see; 'possibly p', when p is true in at least one. So at world zero, necessarily p is false, because world two is visible and lacks p; at world one it is true. We will build this into a calculator, prove which axioms match which shapes of arrows, check a real concurrent program with it, and find the place where modal logic and first-order logic part ways: this part's brick in the Wall.

So: the ancient puzzles about the future and the possible. Lewis's systems, and the fourteen modalities of S4. Kripke's semantics, and the exact match between axioms and shapes of frames, checked by the Reasoner on every frame of up to four worlds. Löb's axiom, completeness, what modal logic cannot see, and why it is decidable. Quantifiers and the Barcan formula. Then the applied logics: obligation, time, and the temporal logics that verify hardware and software, with a model checker we build ourselves.

What it establishes: might, must, ought, always: modalities; one box with six readings (Leibniz, Hintikka 1962, von Wright 1951, Prior 1957, Gödel–Löb–Solovay, Hoare–Pratt–Pnueli); the plan; the Wall's fourth brick, previewed.; Computed on screen: a first Kripke model evaluated

1The sea battle and the master argumentIntroductory3 min

Modal logic begins with a battle that has not happened yet. In On Interpretation, chapter nine, Aristotle considers the sentence 'there will be a sea battle tomorrow'. Today the future branches: tomorrow there may be a battle, or there may not. Now argue: if the sentence is already true today, the battle cannot fail to happen; if it is already false, the battle cannot happen. Either way, everything that happens happens of necessity. That is fatalism. Aristotle seems to conclude that such sentences about the future are not yet true or false, though scholars still dispute what he meant. Chapter eleven will give two precise answers.

A generation later, Diodorus Cronus made an argument so famous that it was simply called the Master. Only its premises survive, in a report by Epictetus. Every true proposition about the past is necessary: what has happened cannot now not have happened. Nothing impossible follows from something possible. And something is possible that neither is true nor ever will be: a battle that could have been fought but never is. Diodorus claimed that these three are inconsistent, and the ancient schools agreed. They disagreed about which one to give up.

As a Price List: three claims, one conflict, and three exits. The Stoics took all three. Diodorus gave up the third: the possible is just what is or will at some time be true. Nothing that never happens was ever possible. Cleanthes, Zeno's successor, gave up the first: some truths about the past are not necessary. And Chrysippus, the great Stoic logician, gave up the second: something impossible can follow from something possible. Notice that each exit is a theory of what 'possible' means. To decide between them, we need a definition, and that took two thousand years.

Medieval logicians kept refining the logic of necessity. Avicenna distinguished what is necessary in itself from what is necessary through another, and around 1300 John Duns Scotus argued that at the very moment I choose, I could have chosen otherwise: alternatives existing side by side, not one after another. That idea of simultaneous alternatives is the ancestor of possible worlds. Leibniz gave it its most famous picture. God surveyed infinitely many possible worlds, and created the best of them. A truth is necessary when it holds in every possible world; possible, when it holds in some; contingent, when it holds in some and fails in others. One thing was still missing, and it turned out to be the key: worlds that are possible from one world need not be possible from another. That idea arrived in 1959.

What it establishes: Aristotle's sea battle (De Interpretatione 9); the Master Argument of Diodorus Cronus (c. 300 BCE); Price List: the exits of Diodorus, Cleanthes and Chrysippus; Avicenna's necessary and possible existents (c. 1020); Duns Scotus and synchronic contingency (c. 1300); Leibniz's possible worlds (Theodicy, 1710).; Computed on screen: the MUS {P, I, C} and its three minimal corrections

2Strict implication and the systems S1–S5Advanced3 min

In Part 2 we chose Philo's conditional: 'if p then q' is false only when p is true and q false. It makes these tautologies. A true conclusion is implied by anything: if the moon is made of cheese, then two plus two is four. And a false premise implies anything: if two plus two is five, then I am the Pope. In 1912 the American logician C. I. Lewis protested that this is not what 'implies' means. For p to imply q, it must be impossible for p to be true and q false. Not false as it happens: impossible.

Lewis defined a new connective. p strictly implies q when, necessarily, if p then q. With his student Cooper Langford he published five axiom systems in 1932, S1 to S5, each a different answer to the question: which laws does 'necessarily' obey? Is what is necessary necessarily necessary? Is what is possible necessarily possible? Strict implication has paradoxes of its own: an impossible proposition strictly implies everything. Logics that refuse even this are relevance logics, in Part 5.

Today the systems are built from a base called K, after Kripke. K has one axiom: if necessarily p implies q, and necessarily p, then necessarily q. And one rule: whatever is a theorem is necessary. On top go the optional axioms. T: what is necessary is true. Four: what is necessary is necessarily necessary. B: what is true is necessarily possible. Five: what is possible is necessarily possible. Lewis's S4 is K with T and four; S5 is K with T and five. Why these axioms and not others, and what do they mean? Chapter four has an exact answer.

Here is one way to see how much the axioms matter. Take p, and stack boxes, diamonds and negations in front of it, every string of up to five symbols. How many of them say different things? In S4, the Reasoner found exactly fourteen: p, necessarily p, possibly necessarily p, necessarily possibly necessarily p, and so on, and their negations. Every longer string collapses onto one of these. In S5, the collapse is total: only six survive, because in S5 only the last operator in a string matters. Each answer was found by checking every string on every frame of up to four worlds that obeys the axioms.

The number fourteen had appeared before, in topology. In 1922 Kazimierz Kuratowski proved that starting from one set of points and applying closure and complement, you can get at most fourteen different sets. In 1944 J. C. C. McKinsey and Alfred Tarski explained why: read the box as interior, the diamond as closure, and negation as complement, and S4 is exactly the logic of topology. Kuratowski's fourteen sets are S4's fourteen modalities. The box was not only about metaphysics; it had a geometry.

What it establishes: the paradoxes of material implication; C. I. Lewis's strict implication (1912); Symbolic Logic (1932) and S1–S5; the axioms K, T, 4, 5 and necessitation; the 14 modalities of S4 and 6 of S5; topology: Kuratowski's closure axioms (1922) and McKinsey and Tarski (1944): S4 is the logic of interior.; Computed on screen: all 258 strings of up to five operators on p sorted into 14 classes (S4) and 6 (S5), on every reflexive transitive frame (389) and every equivalence frame (23) with up to 4 worlds

3Possible worlds, made preciseIntroductory3 min

In 1959 Saul Kripke, then eighteen, published a paper in the Journal of Symbolic Logic that gave modal logic its semantics. Stig Kanger, Jaakko Hintikka, Richard Montague and Arthur Prior had similar ideas in the same years; Kripke's version became the standard. The idea adds one thing to Leibniz. Necessary does not mean true in all worlds, but true in all worlds accessible from this one. Change which worlds are accessible, and you change the logic.

Here are the definitions. A frame is a set of worlds and a relation between them, accessibility, drawn as arrows. A model adds, for each atomic sentence, the worlds where it is true. Here p is true at worlds one and three. Necessarily phi is true at a world when phi is true at every world it can see. Possibly phi is true when phi is true at some world it can see. Everything else works exactly as in Part 2, one world at a time. It is Tarski's definition again, with worlds in place of objects.

Now compute. Possibly p: every world here can see some p-world. World zero sees world one, world two sees world three, and worlds one and three see themselves. True everywhere. Necessarily p is false at world zero, which can see world two, where p fails. It is true at the other three. Necessarily possibly p: at every visible world, p is possible. True everywhere, since possibly p was. And 'if necessarily p, then p' fails at world two: everything world two can see has p, but world two itself does not, because it cannot see itself. That failure is the clue to the next chapter.

One special case deserves a look. A world that sees no world at all. At such a dead end, necessarily phi is true for every phi, because there is no visible world where phi could fail. Even a contradiction is necessary there, and nothing is possible. So 'necessarily p implies possibly p' fails at a dead end. That axiom, D, says exactly that every world sees some world, and Chapter ten will need it for obligation.

The arrows are where the readings differ. For logical possibility, every world can see every world. For physical possibility, the visible worlds are those with our laws of nature. For knowledge, a world is visible when, for all the agent knows, it might be the actual one. For obligation, the visible worlds are the ideal ones, where every duty is done. For time, the visible moments are the later ones; for programs, the reachable states. And each reading suggests a shape for the arrows, which, as we are about to see, decides exactly which axioms hold.

What it establishes: Kripke (1959), with Kanger, Hintikka, Montague and Prior; frames, models and the clauses for □ and ◇; evaluation world by world; dead ends and axiom D; what the arrows mean under six readings.; Computed on screen: ◇p, □p, □◇p and □p → p at all four worlds of a model

4Axioms and framesAdvanced4 min

Truth in a model depends on where p happens to be true. To study the axioms we need something sturdier. A formula is valid on a frame when it is true at every world under every possible choice of where the atoms are true. Then a question with a clean answer becomes possible: on which frames is 'if necessarily p, then p' valid? Because we quantify over every valuation, the answer can only depend on the arrows.

Here is the theorem, and its proof, which fits on one screen. Suppose every world sees itself. If necessarily p is true at w, then p is true at every world w sees, and w is one of them. So p is true at w. Conversely, suppose some world w does not see itself. Make p true everywhere except at w. Then at w, necessarily p is true, since every world w sees has p, and p is false. The axiom fails. So T is valid on exactly the reflexive frames.

The same recipe proves the match for axiom four. Suppose the frame is not transitive: u sees v, v sees w, but u does not see w. Make p true exactly at the worlds u sees, here just v. Then necessarily p holds at u, but necessarily necessarily p fails, because v sees w, where p is false. Conversely, if the arrows are transitive, any world u reaches in two steps it reaches in one, so whatever is necessary at u is necessarily necessary. Every proof in this chapter has this shape: a valuation tailored to the frame refutes the axiom wherever the condition fails.

Watch a frame change as axioms are imposed. Three worlds, each seeing the next. Only K holds. Demand T, and every world must see itself. Demand four as well, and the arrows must be transitive: world zero must see world two. That is S4. Demand five too, and the frame becomes an equivalence relation: here, every world sees every world. That is S5, Leibniz's picture, where possible means possible from anywhere.

The same holds for the others, each with its own proof. D, necessarily p implies possibly p, matches seriality: every world sees at least one world. B matches symmetry, four matches transitivity, and five matches the Euclidean property: two worlds visible from one see each other. The Reasoner checked every pairing exhaustively, on all five hundred and twelve frames with three worlds and all sixty-five thousand five hundred and thirty-six with four. On every single frame, the axiom is valid exactly when the condition holds. Proof and brute force agree.

This turns arguments about axioms into arguments about arrows. For knowledge, T says what is known is true: the actual world is never ruled out. Four says that if you know something, you know that you know it, which Timothy Williamson has argued against, in Part 11. For obligation we want D but not T: duties can be broken, but they can always be met together. And for time, four but not T: a moment later than a later moment is later, but now is not later than now.

What it establishes: validity on a frame; T ⇔ reflexive and 4 ⇔ transitive, with both directions proved; D, B, 5; the table of correspondences; what correspondence means philosophically.; Computed on screen: every frame on 3 and 4 worlds: T 64 / 4,096, D 343 / 50,625, B 64 / 1,024, 4 171 / 3,994, 5 39 / 306 valid, agreeing with the frame condition on all 512 and 65,536 frames

5Löb's axiom and the limits of correspondenceResearch4 min

Here is an axiom with a stranger meaning. In 1955 Martin Löb proved a theorem about arithmetic: if arithmetic proves 'if phi is provable, then phi', then arithmetic proves phi itself. Read the box as 'arithmetic proves', and Löb's theorem becomes a modal axiom. Add it to K and you get the system GL. In 1976 Robert Solovay proved that GL is exactly the logic of provability: every modal law of 'provable' is a theorem of GL. Gödel's incompleteness theorems become one-line theorems of this logic, in Part 7.

Here is what Löb's axiom can do. Take the axiom, and let p be a contradiction, falsum. Then 'if falsum is provable, then falsum' just says that falsum is not provable: arithmetic is consistent. So the instance reads: if arithmetic proves that it is consistent, then arithmetic proves a contradiction. That is Gödel's second incompleteness theorem, a consistent arithmetic cannot prove its own consistency, as a one-line consequence of a modal axiom. Part 7 builds the theorem itself.

Löb's axiom has a frame condition too. It is valid exactly when the arrows are transitive and there is no infinite chain of them: no world sees a world that sees a world, forever. On a finite frame that means no cycles at all: the arrows form a strict partial order. The Reasoner checked: of the frames with two, three and four worlds, the axiom is valid on three, nineteen and two hundred and nineteen, which are exactly the strict partial orders, on every frame.

Now a surprise, proved with a tool from Part 3. Suppose some first-order sentence sigma said 'there is no infinite chain', at least for transitive frames. Add new names c zero, c one, c two, and so on, with c zero seeing c one, c one seeing c two, forever. Every finite part of this set has a model: a finite chain, with no infinite chain in it. So by compactness the whole set has a model. It contains an infinite chain, and yet it satisfies sigma. Contradiction. Löb's axiom corresponds to a condition on the arrows, but no first-order sentence can state that condition.

This is the fourth brick in the Wall. The dream was to read every modal axiom off the frames as a plain statement about arrows, in the logic of Part 3. The wall: some axioms correspond to no first-order condition at all. Modal logic, read on frames, is a fragment of second-order logic. Robert Goldblatt and Steven Thomason characterized in 1975 exactly which classes of frames modal axioms can define. McKinsey's axiom, necessarily possibly p implies possibly necessarily p, is another axiom with no first-order condition.

There is good news on the other side of the wall. In 1975 Henrik Sahlqvist proved that every axiom of a certain syntactic shape has a first-order frame condition, which an algorithm can compute, and that adding such axioms to K always gives a complete logic. T, D, B, four and five all have that shape. Löb's and McKinsey's axioms do not, which is exactly why they escape. Today the algorithm runs inside tools that translate modal problems into first-order ones for the provers of Part 3.

What it establishes: Löb (1955) and Solovay (1976): GL is the logic of provability; Gödel's second incompleteness theorem as a one-line instance; GL ⇔ transitive and conversely well-founded; why that is not first-order (compactness); the Wall's fourth brick: Goldblatt–Thomason (1975); Sahlqvist's theorem (1975).; Computed on screen: Löb's axiom valid on exactly the strict partial orders: 3 of 16, 19 of 512, 219 of 65,536 frames

6Completeness by canonical modelsResearch2 min

As in Parts 2 and 3, we want proof and truth to agree. On one side, the theorems of K, derived from its axiom and its rules. On the other, the formulas valid on every frame. Soundness is easy: K's axiom is valid on every frame, and the rules preserve validity. For completeness, we use Henkin's idea from Part 3 once more: build the model out of the logic itself.

Here is the canonical model. Its worlds are the maximal consistent sets of formulas: sets that decide every formula, one way or the other, without contradiction, built by Lindenbaum's construction from Part 2. One world sees another when everything the first says is necessary is true in the second. If w contains 'necessarily p' and 'necessarily, if p then q', then every world w sees contains p and 'if p then q', and so q. The truth lemma says that a formula is true at a world exactly when it belongs to it. The key step is the diamond: if w says 'possibly r', there really is a visible world containing r. With the truth lemma, any formula K cannot prove is false somewhere in the canonical model, so it is not valid.

The same model proves completeness for the stronger logics too, when the axioms shape the canonical frame. If every world contains all instances of T, then whatever a world says is necessary, it contains, so it sees itself: the canonical frame is reflexive. With four, it is transitive. So S4 is complete for reflexive transitive frames, and S5 for equivalence relations. Axioms with this property are called canonical, and every Sahlqvist axiom is one. Löb's axiom is not: the canonical frame of GL has infinite chains, and its completeness had to be proved with finite models instead.

What it establishes: soundness and completeness for K; maximal consistent sets as worlds; the canonical relation; the truth lemma; canonicity of T and 4; S4 and S5 complete; GL is not canonical (Segerberg 1971).

7What modal logic cannot seeAdvanced3 min

A modal formula looks at the world from inside: from here, it can only follow arrows. When do two worlds look the same from inside? When there is a bisimulation between them: a relation that matches worlds with the same atoms, such that every move on one side can be matched by a move on the other, to matched worlds, in both directions. The basic theorem: bisimilar worlds satisfy exactly the same modal formulas. The proof is an induction on formulas; the box case uses the back and forth conditions.

Bisimulation also compresses. Here is a model with six worlds. The Reasoner computes the largest bisimulation of the model with itself, by repeatedly removing pairs that break the back-and-forth conditions. Worlds one and two are bisimilar: both have p, and both lead to a dead end without p. Worlds three and four are bisimilar too. Merge each class into one world. The result has four worlds, and no modal formula can tell it from the original. Process algebra and model checkers use exactly this to shrink systems before checking them.

Bisimulation also shows what modal logic cannot say. On the left, one world that sees itself. On the right, three worlds in a cycle, all with p. Match the single world with each of the three: every move is matched, back and forth. They are bisimilar. So no modal formula can say 'this world sees itself', since that is true on the left and false on the right, and none can count the length of a cycle.

How does modal logic sit inside the first-order logic of Part 3? Translate it: necessarily p at x becomes 'for every y, if x sees y, then y has P'; possibly p, 'there is a y that x sees, with P'. Every modal formula becomes a first-order formula with one free variable. In 1976 Johan van Benthem proved which ones: a first-order formula comes from a modal formula exactly when bisimulation cannot change its truth value. Modal logic is the bisimulation-invariant part of first-order logic, a characterization in the spirit of Lindström's theorem.

What it establishes: bisimulation (forth and back); the invariance theorem; the largest bisimulation and the minimal model; a loop and a cycle that no formula can tell apart; the standard translation; van Benthem's theorem (1976).; Computed on screen: the 6-world model merged into 4 classes, {0}, {1, 2}, {3, 4}, {5}; the loop ~ the 3-cycle

8Finite models and decidabilityAdvanced4 min

Bisimulation merges worlds that no formula can tell apart. Filtration goes further, and merges worlds that one particular formula cannot tell apart. Here is a model of twelve worlds in a line, with p true at every third one. Take a formula, here McKinsey's axiom, and list its subformulas: six of them. Two worlds that agree on all six are, as far as this formula is concerned, the same. The Reasoner colours the worlds by what they make true: four kinds. Merge each kind into one world. The formula has the same truth value at every world as at its class. Whatever the size of the original model, even infinite, the filtered one has at most two to the six worlds.

This gives an algorithm for the propositional systems K, T, S4 and S5. If a formula in one of these systems fails anywhere, it fails in a finite model, of size bounded by the number of its subformulas. So to decide validity, search every model of the appropriate frame class up to that size. It is slow, but it always halts. Richard Ladner measured the true cost in 1977: S5 satisfiability is NP-complete, like SAT; S5 validity is coNP-complete. Both problems for K, T and S4 are PSPACE-complete. First-order logic, which contains all of them, is undecidable. The reason is that a modal formula can only look along the arrows: it lives in the guarded fragment that Chapter ten of Part 3 found decidable. These familiar systems form decidable islands in first-order logic. Other modal logics can be undecidable; the language and frame conditions matter.

Part 3 promised that the tableau method would return for necessity and possibility. Here it is: a tableau in which every line is labelled with a world. To test K's axiom, deny it at world zero, and break it into pieces there: necessarily, if p then q; necessarily p; and not necessarily q. A new kind of rule: 'not necessarily q' demands a world where q fails. Create it, world one, visible from world zero. And the boxes at world zero now reach world one: p is true there, and if p then q. Split on the conditional. Not p contradicts p; q contradicts not q. Both branches close: the axiom is valid. The tree creates a world only when a diamond demands one, so for K it always stops: another decision procedure.

When a branch stays open, it is a countermodel, as in Part 3. Test: if p is possible and q is possible, are p and q possible together? The tableau creates one world for each diamond: one where p holds and one where q holds, and nothing forces them to be the same world. The open branch is the model: invalid. And T's axiom in plain K: the branch stays open, with a single world that sees nothing, where necessarily p is vacuously true and p is false. Add the rule that every world sees itself, and the same tree closes. Each frame condition is a tableau rule.

What it establishes: filtration through the subformulas; the finite model property; decidability of K, T, S4 and S5; satisfiability (Ladner 1977): S5 NP-complete, K, T and S4 PSPACE-complete; S5 validity coNP-complete; the guarded fragment; prefixed tableaux.; Computed on screen: a 12-world chain filtered to 4 worlds for □◇p → ◇□p (bound 2⁶ = 64); K's axiom closed in 8 steps; ◇p ∧ ◇q → ◇(p ∧ q) refuted by a 3-world model; □p → p open in K, closed in T

9Quantifiers and modalityAdvanced3 min

Now add quantifiers. Ruth Barcan Marcus built the first quantified modal logics in 1946 and 1947, and one formula still carries her name. If there could have been something with a property, then there is something that could have had it. It sounds harmless until you try an example. There could have been a child of Wittgenstein, who had none. Does it follow that something actually exists that could have been his child? A merely possible child, existing already?

In Kripke's semantics for quantified modal logic, each world has its own domain of things. Here world zero contains one thing, a, and it sees world one, which contains a and a newcomer, b. Let F be true of a at world one, but not of b. Then at world zero, everything is necessarily F: the only thing there is a. But it is not necessary that everything is F, because world one has something that is not. So the Barcan formula holds when every world has the same domain, and fails when domains can grow. Accepting it means believing in a fixed stock of possible things: necessitism, as Timothy Williamson defends it.

Quine thought the whole project was confused. Necessarily, nine is greater than seven. In 1953 there were nine known planets, so nine was the number of planets. Substitute equals for equals, and you get: necessarily, the number of planets is greater than seven, which is false, since there could have been five. The answer, made precise by Russell's scope distinctions from Part 3, separates two readings. De dicto: necessarily, whatever number the planets have exceeds seven: false. De re: the thing that is in fact the number of planets, namely nine, necessarily exceeds seven: true. Quine's further worry, that de re necessity commits us to essences, is the subject of Part 22.

One more theorem with philosophical teeth. Suppose a is b. Everything is necessarily identical to itself, so necessarily a is a. Substitute b for the second a, and you get: necessarily a is b. Marcus proved it in 1947: identities, if true, are necessary. But Hesperus, the evening star, turned out to be Phosphorus, the morning star: a discovery of astronomy. How can it be necessary? Kripke's answer in 1971 was that names are rigid: they pick out the same thing in every world, so the identity is necessary, though we learn it by observation. Necessary truths known a posteriori: a central idea of Part 22.

What it establishes: Barcan Marcus (1946, 1947); the Barcan formula and its converse; constant and growing domains; Quine's objections (1953): the number of planets; de dicto and de re; the necessity of identity; Hesperus and Phosphorus; Kripke's rigid designators (1971).; Computed on screen: the Barcan formula true with constant domains, false with growing ones

10The logic of obligationIntroductory3 min

In 1951 Georg Henrik von Wright proposed a logic of 'ought'. In Kripke's terms it is simple. p is obligatory when p is true in every ideal world, every world where all duties are met. p is permitted when it is true in some ideal world. And there is always at least one ideal world: what is obligatory is permitted. That is axiom D. But not axiom T: what ought to be is not always so. The result, K plus D, is standard deontic logic.

The logic has odd theorems. Alf Ross noticed in 1941 that from 'you ought to mail the letter' it follows that 'you ought to mail it or burn it'. The Reasoner confirms it is valid in standard deontic logic. Most logicians take this as odd but harmless: the disjunctive duty is only satisfied by burning if mailing is also done, since the original duty remains.

In 1963 Roderick Chisholm found a deeper problem, with an ordinary story. Jones ought to go to help his neighbours. It ought to be that, if he goes, he tells them he is coming. If he does not go, he ought not to tell them. And he does not go. These four sentences are consistent, and none of them follows from the others. The third is a contrary-to-duty obligation: what you ought to do once you have already failed.

Now formalize the story in standard deontic logic. Sentences one and four are clear: O of g, and not g. Sentences two and three can each be written two ways: the obligation can govern the whole conditional, or only its consequent. That gives four versions. The Reasoner checked each one, searching all serial models of up to three worlds for consistency, and for whether any sentence follows from the other three. Version C is inconsistent: from one and two, Jones ought to tell; from three and four, he ought not to; and D forbids both. Versions A, B and D are consistent, but in each, at least one sentence follows from the others, though in the story none does. No version captures the story. Chisholm's paradox led to logics of conditional obligation, 'ought q, given p', and it marks a limit of the simple semantics.

What it establishes: von Wright (1951); standard deontic logic = KD; Ross's paradox (1941); Chisholm's contrary-to-duty paradox (1963); dyadic obligation (Hansson 1969, Lewis 1973).; Computed on screen: Ross's inference valid on every serial frame up to 3 worlds; Chisholm's four versions: each inconsistent or with a redundant sentence

11The logic of timeAdvanced3 min

Arthur Prior, a New Zealand logician, founded tense logic in the 1950s, inspired partly by Diodorus. Its operators: F p, it will at some time be that p; G p, it will always be that p; and their mirror images for the past, P and H. In Kripke's terms, the worlds are moments, and the arrows point to later moments: G is a box over the future, and H a box over the past, using the arrows backwards.

As with necessity, each axiom fixes a shape of time. 'Always in the future p' implies 'always always p': time is transitive. 'Always p' implies 'sometime p': there is no last moment. Density: between any two moments there is another. And this long axiom says the future does not branch: of any two future events, one comes first, or they coincide. Is the future linear? That is exactly Aristotle's question about the sea battle.

Prior's answer to Aristotle was to let the future branch. Today, two histories continue: in one there is a sea battle tomorrow, in the other there is not. Now 'there will be a sea battle' can be read two ways. Prior called them Peircean and Ockhamist, after Charles Peirce and William of Ockham. The Peircean reading: it will be, on every history. The Ockhamist reading: the sentence is true or false only relative to a history, a complete way the future might go.

The Reasoner evaluated four sentences today on the two-branch tree. On the Peircean reading, 'there will be a battle' is false, since one history has none, and 'there will be no battle' is also false. Their disjunction is false too, but 'there will be: a battle or none' is true. That is close to Aristotle's own view: the future disjunction is necessary, and neither disjunct is yet true. On the Ockhamist reading, every sentence has a truth value on each history: on the first, 'there will be a battle' is true; on the second, false. What is open is only which history is ours. The choice matters for free will, and for the old puzzle of divine foreknowledge, which returns in Part 23.

What it establishes: Prior's tense logic (1957); F, G, P, H; transitivity, no last moment, density and linearity as axioms; branching time; Peircean and Ockhamist readings of the sea battle.; Computed on screen: four sentences evaluated on the two-history tree, Peircean and Ockhamist

12Temporal logic for machinesApplied3 min

In 1977 Amir Pnueli, an Israeli computer scientist, saw that Prior's tense logic was exactly what programmers needed. Many programs are never supposed to stop: an operating system, a network protocol, a pacemaker. Their correctness is not a final answer but a pattern of behaviour over time: something bad never happens, something good always eventually happens. Pnueli received the Turing Award for it in 1996.

Pnueli's logic speaks about a single run of a system, an infinite sequence of states. X p: p holds in the next state. F p: p holds eventually, at some later state. G p: p holds always, at every state. And p until q: q eventually holds, and p holds at every state before that.

Two kinds of property matter most, as Leslie Lamport observed in 1977. Safety: something bad never happens. For example, two processes are never in their critical sections at the same time. A safety violation can be shown with a finite trace: here is the moment it went wrong. Liveness: something good eventually happens. Whoever asks to enter the critical section eventually gets in. A liveness violation needs an infinite run, one where the waiting never ends. Bowen Alpern and Fred Schneider proved in 1985 that every property of runs is a combination of the two.

In 1981 Edmund Clarke and Allen Emerson, and independently Jean-Pierre Queille and Joseph Sifakis, turned this into an algorithm called model checking, and shared the Turing Award for it in 2007. Their logic, CTL, can also quantify over paths. AG phi: on every path, always phi. EF phi: on some path, eventually phi; that is, a phi-state is reachable. EG phi: some path stays in phi forever. Each is computed as a fixed point on the finite graph of the system's states. EF grows a set backwards from the target until nothing changes; EG shrinks a set until every state left can continue. Both are in the Reasoner, and the next chapter runs them on a real protocol.

Linear temporal logic has its own algorithm, found by Moshe Vardi and Pierre Wolper in 1986. Negate the property. 'Every request is eventually granted' becomes 'some request is never granted'. Build an automaton that reads a run of the system and accepts exactly the runs that violate the property. Here it waits, jumps when a request arrives that is not yet granted, and accepts if it can stay forever where the grant never comes. Such automata on infinite words were invented by Julius Büchi in 1962, to prove a logic decidable. Run the automaton alongside the system, and search the combined graph for a reachable cycle through an accepting state. If there is one, it is a counterexample run; if not, the property holds. SPIN works exactly this way.

What it establishes: runs as paths; Pnueli (1977); X, F, G, U; safety and liveness (Alpern and Schneider 1985); CTL and model checking (Clarke and Emerson, Queille and Sifakis, 1981); fixed points; Vardi and Wolper's automata (1986), Büchi (1962).

13Checking a mutual-exclusion protocolApplied3 min

Here is a classic problem. Two processes share a resource, say a printer, and must never use it at the same time. Each has a critical section where it uses the resource. In 1981 Gary Peterson published a famous short solution using three shared variables. To enter, process i raises its flag, then gives the turn to the other process, then waits until either the other process's flag is down, or the turn has come back to i. On leaving, it lowers its flag. The flag says 'I want in'; the turn says 'after you'. Is it correct? With two processes interleaving their steps, intuition is unreliable. So check every possible interleaving.

The Reasoner's model checker starts from the state where both processes are idle and explores every possible next step of either process, breadth first. It finds reachable states, joined by transitions. Colour each state by how many processes are in their critical sections. A violation of mutual exclusion would be a red state, with both inside. There is none. Necessarily, on every path, always, at most one process is critical. Peterson's algorithm is safe, and this is not a test of a few runs: it is every run.

Now change one detail: give the turn away before raising the flag, the two middle lines swapped. The state graph grows to fifty states, and this time some are red. Because the checker explores breadth first, it hands back the shortest path to a violation: steps. Process zero gives the turn away. Process one gives it back, raises its flag, and, since process zero's flag is still down, enters. Then process zero raises its flag, finds that the turn is its own, and enters too. Both are inside. A bug that a test might never hit, found and explained by exhaustive search.

Safety is half the story. Can a process that wants to enter wait forever? With an arbitrary scheduler, yes: the Reasoner finds paths on which process zero waits forever, because the scheduler simply never lets it move. That is not the algorithm's fault. So add an assumption about the scheduler, strong fairness: a process that is able to move infinitely often does move infinitely often. Under fairness, the checker finds no path of endless waiting. Peterson's algorithm is starvation-free. The computation looks for cycles in the state graph on which waiting could last forever, and discards those that are unfair to either process.

What it establishes: a state graph; Peterson's algorithm (1981); mutual exclusion as AG ¬(crit₀ ∧ crit₁); a broken variant and its counterexample; starvation and fairness.; Computed on screen: Peterson: 34 states, 62 edges, mutual exclusion holds; the broken variant: 50 states and an 8-step trace to both in the critical section; endless waiting possible from 8 states without fairness, on no fair path

14Programs as modalitiesApplied2 min

Temporal logic checks what a program does over time. Program logic proves what it computes. Robert Floyd in 1967 and Tony Hoare in 1969 proposed triples: P, then a command C, then Q, meaning that if P is true before C runs, then Q is true afterwards, if C finishes. Each kind of command has a rule. An assignment: Q holds after x gets e if Q with e for x held before. A sequence: chain the middle condition. And a loop: find an invariant, a condition the body preserves. Then it still holds when the loop stops, together with the negation of the loop's test.

Here is a small proof. Starting with n at least zero, this loop adds the numbers from one to n. Afterwards s should be n times n plus one over two. The invariant: s equals i times i plus one over two, and i is at most n. It holds at the start, when both are zero. Each pass of the body preserves it, by a line of algebra. And when the loop stops, i equals n, so s has the right value. A proof covers every n at once. As a sanity check, the Reasoner ran the loop for n up to and tested the invariant at all points where it should hold.

In 1976 Vaughan Pratt saw that this, too, is modal logic. Give each program alpha its own box: box alpha phi means that after every run of alpha that ends, phi holds. And diamond alpha phi: some run of alpha ends with phi. The worlds are states of the machine, and the arrows are runs of programs. A Hoare triple is just the modal formula 'if P, then box alpha Q'. The laws of programs become modal axioms: doing alpha then beta is a box inside a box; choosing alpha or beta is a conjunction of boxes; repeating alpha is a fixed point, like the ones in the model checker.

What it establishes: Floyd (1967) and Hoare (1969) triples; the rules for assignment, sequence and loops; a loop invariant; Pratt's dynamic logic (1976).; Computed on screen: the summation invariant checked at all 496 loop points for n = 0, …, 30

15Model checking at workApplied3 min

The first big customer was hardware. In 1994 a missing entry in a lookup table made Intel's Pentium divide wrongly, in rare cases, and the recall cost Intel four hundred and seventy-five million dollars. The industry turned to formal verification. Kenneth McMillan's symbolic model checker represented sets of states as binary decision diagrams, checking systems with more states than there are grains of sand. Bounded model checking, from Part 2, translates temporal formulas into SAT. Today processors, their floating-point units and their cache protocols are checked against temporal specifications before they are made.

The idea that made hardware verification practical is a data structure. In 1986 Randal Bryant introduced reduced ordered binary decision diagrams: a decision tree for a Boolean function, with the variables tested in a fixed order and every repeated piece shared. Sets of states become such diagrams, and the fixed points of model checking become operations on them. Their size depends dramatically on the order. Take this function, built from n pairs. The Reasoner built its diagram both ways. Testing each x right before its partner y, the diagram grows by two nodes per pair. Testing all the x's first, it doubles with every pair, because the diagram must remember every x before it sees any y. Finding a good order is itself hard, and much of the engineering of model checkers lies there.

Software followed. Gerard Holzmann's SPIN checks protocols against LTL specifications, and has been used on flight software at NASA. Microsoft's Static Driver Verifier checks Windows device drivers against temporal rules for the kernel's interface. At Amazon, engineers specified the designs of DynamoDB and S3 in Leslie Lamport's temporal logic TLA plus, and the model checker found subtle bugs, one of them needing a thirty-five-step trace to show. And whole systems have been proved correct: the seL4 operating-system kernel, and the CompCert C compiler.

Two limits remain. The first is state explosion: n processes with k states each make k to the n global states. The field's answers are symbolic representations, reductions that skip equivalent interleavings, abstraction, and the bisimulation minimization of Chapter seven. The second limit is philosophical. A model checker proves that a system satisfies a formula; it cannot tell you whether the formula says what you meant. That problem, saying exactly what we want, returns at the very end of this series, in Part 42.

What it establishes: the Pentium FDIV bug (1994) and formal verification of chips; SPIN, SLAM, TLA⁺ at Amazon, seL4 and CompCert; state explosion and its answers; Bryant's BDDs (1986).; Computed on screen: the BDD of (x₁ ∧ y₁) ∨ … ∨ (xₙ ∧ yₙ): 2n + 2 nodes in a good order, 2ⁿ⁺¹ in a bad one, for n = 1, …, 6

Recap, problems, and where this comes backAll tracks2 min

Let's gather what we built. The ancient puzzles: the sea battle and the master argument. Lewis's strict implication, the modern systems, and the fourteen modalities of S4. Kripke's semantics, and the exact match between axioms and shapes of arrows, checked on every frame of up to four worlds. Then the wall: Löb's axiom has no first-order frame condition. Canonical models, bisimulation, filtration, and decidability. The Barcan formula, obligation, and time. And temporal logic in industry, with our own model checker verifying Peterson's algorithm and catching its broken twin.

The Reasoner has a third module, for modal logic: Kripke models, an exhaustive checker of axioms against frames, a model finder, bisimulation, and an explicit-state model checker with fairness. Each is tested against numbers known from the literature: fourteen modalities, one hundred and seventy-one transitive relations on three points, two hundred and nineteen partial orders on four. And the Wall has its fourth brick.

Six problems, with full solutions in this part's notes. Two correspondence proofs, a countermodel, a pair of bisimilar models, two specifications in temporal logic, and one for Diodorus. Pause here, and try them.

Where this comes back. Knowledge as a modality, and the debate over introspection, in Parts 11 and 12. Provability logic in Part 7. Possible worlds, rigid designators and essence in Part 22. Branching time and divine foreknowledge in Part 23. Obligation in ethics and in fair machines. And specification, at the very end. Next, Part 5: logics with more than two truth values, sentences that are neither true nor false, and the paradox of the heap.

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

Where it goes next. Knowledge as a modality and the debate over introspection are Parts 11 and 12; provability logic and Löb's theorem return in Part 7; possible worlds, rigid designators and essence in Part 22; branching time and foreknowledge in Part 23; the many-valued logics of Part 5 come next.

Key results

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

Kripke's clause\(\displaystyle \mathcal M,w\models\Box\varphi\iff\mathcal M,v\models\varphi\ \text{for }\allowbreak \text{every } v \text{ with } wRv\)
T and 4\(\displaystyle \Box p\to p:\ \text{reflexive};\qquad\allowbreak \Box p\to\Box\Box p:\ \text{transitive}\)
B, 5 and D\(\displaystyle p\to\Box\Diamond p:\ \text{symmetric};\quad\allowbreak \Diamond p\to\Box\Diamond p:\ \text{euclidean};\quad\allowbreak \Box p\to\Diamond p:\ \text{serial}\)
Löb's axiom\(\displaystyle \Box(\Box p\to p)\to\Box p:\ \text{transitive, }\allowbreak \text{no }\allowbreak \text{infinite }\allowbreak \text{chain } w_0Rw_1R\cdots\)
The Barcan formula\(\displaystyle \forall x\,\Box\varphi\to\Box\,\forall x\,\varphi\quad\allowbreak \text{(constant }\allowbreak \text{domains)}\)
Mutual exclusion\(\displaystyle \mathrm{AG}\,\lnot(\mathrm{crit}_0\land\mathrm{crit}_1)\)

Try it

Lab 4 · Axioms, frames, and a protocol

For T, D, B, 4, 5 and Löb's axiom, count the frames on three worlds where the axiom is valid and compare with the frames that have the matching shape of arrows; repeat on random five-world frames; then explore the state graphs of Peterson's algorithm and its broken variant.

Figure produced by Lab 4: Axioms, frames, and a protocol
Produced by the lab below, seed 0, in 0.3 s.
python -m videos.philosophy.labs 4 needs numpy, scipy, matplotlib · download lab04.py · source on GitHub
T: []p -> p                valid on  64 of 512 frames; agrees with 'reflexive' on 512
D: []p -> <>p              valid on 343 of 512 frames; agrees with 'serial' on 512
B: p -> []<>p              valid on  64 of 512 frames; agrees with 'symmetric' on 512
4: []p -> [][]p            valid on 171 of 512 frames; agrees with 'transitive' on 512
5: <>p -> []<>p            valid on  39 of 512 frames; agrees with 'euclidean' on 512
L: []([]p -> p) -> []p     valid on  19 of 512 frames; agrees with 'transitive, no cycles' on 512
random frames on 5 worlds  axiom and condition agree on 240 of 240 (94 have the shape)
Peterson's algorithm       34 reachable states, 62 edges, mutual exclusion holds: True
the broken variant         50 states; both critical after 8 steps

Each axiom is valid on exactly the frames with its shape of arrows, on every frame tried; the same world-by-world evaluation, run over a program's states, proves Peterson's protocol and finds the eight-step failure of its broken twin.
The code (110 lines; it asserts its own result)
"""Lab 4: check each modal axiom against its frame condition on every small frame, then model-check Peterson's protocol."""

import numpy as np

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

TITLE = "Axioms, frames, and a protocol"
GOAL = ("For T, D, B, 4, 5 and Löb's axiom, count the frames on three worlds where the axiom is valid and compare "
        "with the frames that have the matching shape of arrows; repeat on random five-world frames; then explore "
        "the state graphs of Peterson's algorithm and its broken variant.")
TASKS = [
    "Add the axiom '<>[]p -> []<>p' to the table. Which frames on three worlds validate it? Guess the condition on "
    "the arrows before you look.",
    "Check '[]<>p -> <>[]p' (McKinsey) on every three-world frame and try to state its frame condition in "
    "first-order terms.",
    "In modal.peterson, make a third variant that never sets the turn. Does mutual exclusion still hold? Is every "
    "waiting process eventually served?",
]

NAMES = {"T": "reflexive", "D": "serial", "B": "symmetric", "4": "transitive", "5": "euclidean",
         "L": "transitive, no cycles"}
EXPECT = {"T": 64, "D": 343, "B": 64, "4": 171, "5": 39, "L": 19}  # the film's counts on three worlds


def closure(R, n, kind):
    R = set(R)
    if kind == "T":
        R |= {(w, w) for w in range(n)}
    if kind == "B":
        R |= {(v, u) for u, v in R}
    if kind in ("4", "L"):
        if kind == "L":
            R = {(u, v) for u, v in R if u < v}  # a strict order to start from
        while True:
            new = {(u, x) for u, v in R for w, x in R if v == w} - R
            if not new:
                break
            R |= new
    return R


def run(seed=0):
    rng = np.random.default_rng(seed)
    lab = labs.Lab()
    counts = {}
    for name in "TDB45L":
        r = modal.correspondence(name, 3)
        counts[name] = r["valid"]
        lab.row(f"{name}: {r['formula']}", f"valid on {r['valid']:>3} of {r['frames']} frames; "
                                           f"agrees with '{NAMES[name]}' on {r['agree']}")
        assert r["agree"] == r["frames"] == 512 and r["mismatch"] is None, f"{name} matches its frame condition"
        assert r["valid"] == EXPECT[name]

    # Random frames on five worlds (2^25 of them, too many to list): half are pushed into the class, half are not.
    n, trials, agree, inside = 5, 240, 0, 0
    for k in range(trials):
        name = "TB4L5D"[k % 6]
        R = {(u, v) for u in range(n) for v in range(n) if rng.random() < rng.uniform(0.1, 0.6)}
        if rng.random() < 0.5:
            R = closure(R, n, name)
        f, cond = modal.parse(modal.AXIOMS[name][0]), modal.AXIOMS[name][1]
        valid, shaped = modal.valid_on_frame(f, R, n), cond(R, n)
        agree += valid == shaped
        inside += shaped
    lab.row("random frames on 5 worlds", f"axiom and condition agree on {agree} of {trials} ({inside} have the shape)")
    assert agree == trials and 30 < inside < trials - 30, "both kinds of frame were tried, and the match is exact"

    good, bad = modal.peterson(), modal.peterson(broken=True)
    ok, _, n_good = modal.mutual_exclusion(good)
    ok_bad, trace, n_bad = modal.mutual_exclusion(bad)
    lab.row("Peterson's algorithm", f"{n_good} reachable states, {len(good.graph()[1])} edges, mutual exclusion holds: {ok}")
    lab.row("the broken variant", f"{n_bad} states; both critical after {len(trace) - 1} steps")
    assert ok and n_good == 34 and len(good.graph()[1]) == 62
    assert not ok_bad and n_bad == 50 and len(trace) - 1 == 8 and trace[-1][0] == trace[-1][1] == 4
    for a, b in zip(trace, trace[1:]):
        assert b in [t for _, t in bad.step(a)], "the counterexample is a real run"
    lab.note = ("Each axiom is valid on exactly the frames with its shape of arrows, on every frame tried; the same "
                "world-by-world evaluation, run over a program's states, proves Peterson's protocol and finds the "
                "eight-step failure of its broken twin.")

    fig, ax = labs.figure(2, size=(11, 4.2))
    x = np.arange(6)
    ax[0].bar(x, [counts[k] for k in "TDB45L"], color=labs.BLUE)
    for i, k in enumerate("TDB45L"):
        ax[0].text(i, counts[k] + 8, f"{counts[k]}\n" + NAMES[k].replace(", ", ",\n"), ha="center", va="bottom",
                   fontsize=8.5, color=labs.INK)
    ax[0].set(title="Frames on 3 worlds (of 512) where the axiom is valid", xticks=x, ylim=(0, 440),
              xticklabels=["T", "D", "B", "4", "5", "Löb"], ylabel="frames")

    def by_depth(system):
        order, parent = system.explore()
        depth = {}
        for s in order:
            depth[s] = 0 if parent[s] is None else depth[parent[s][0]] + 1
        d = np.bincount(list(depth.values()))
        bad_at = [depth[s] for s in order if s[0] == 4 and s[1] == 4]
        return d, bad_at

    dg, _ = by_depth(good)
    db, bad_at = by_depth(bad)
    ax[1].plot(range(len(dg)), dg, "o-", color=labs.GREEN, label=f"Peterson: {n_good} states, never both critical")
    ax[1].plot(range(len(db)), db, "o-", color=labs.RED, label=f"broken variant: {n_bad} states")
    ax[1].axvline(min(bad_at), color=labs.RED, ls="--", lw=1)
    ax[1].text(min(bad_at) - 0.15, 0.6, "both critical", color=labs.RED, ha="right", fontsize=9)
    ax[1].set(title="Reachable states by number of steps from the start", xlabel="steps", ylabel="new states",
              ylim=(0, max(db.max(), dg.max()) + 4))
    ax[1].legend(loc="upper left")
    lab.fig = fig
    return lab

Now change it

  1. Add the axiom '<>[]p -> []<>p' to the table. Which frames on three worlds validate it? Guess the condition on the arrows before you look.
  2. Check '[]<>p -> <>[]p' (McKinsey) on every three-world frame and try to state its frame condition in first-order terms.
  3. In modal.peterson, make a third variant that never sets the turn. Does mutual exclusion still hold? Is every waiting process eventually served?

Problems, with solutions

Try each problem before opening its solution.

  1. B, p → □◇p, is valid on exactly the symmetric frames.

    Solution

    If the frame is symmetric: suppose p is true at w, and w R v. By symmetry v R w, so v sees a p-world, and ◇p is true at v. That holds for every v that w sees, so □◇p is true at w. If the frame is not symmetric: some w R v without v R w. Make p true at w only. Then p is true at w, but v sees no p-world (the only one is w, which v does not see), so ◇p fails at v, and □◇p fails at w. The Reasoner's correspondence checker agrees on all 16, 512 and 65,536 frames with 2, 3 and 4 worlds.

  2. In S5, ◇□p → □p is valid; axiom 5 does the work.

    Solution

    Axiom 5 is ◇q → □◇q. Put q = ¬p and contrapose: ¬□◇¬p → ¬◇¬p, and since ◇¬ is ¬□ and □¬ is ¬◇, this is ◇□p → □p. So it holds in every logic containing 5, on every euclidean frame; T and 4 are not needed. Semantically: if w sees v where □p holds, and w R u, then by the euclidean condition v R u, so p holds at u. The Reasoner finds ◇□p → □p valid on exactly the euclidean frames: 7 of 16 with two worlds and 39 of 512 with three, the same frames as axiom 5.

  3. A smallest frame on which □p → □□p fails has two worlds.

    Solution

    On one world, both possible relations (empty and a loop) are transitive, so 4 is valid. On two worlds, take 0 R 1 and 1 R 0, with no loops, and make p true at 0 only. At world 1, □p is true (the only world it sees is 0, where p holds), but □□p is false: 1 sees 0, which sees 1, where p fails. The Reasoner finds exactly three two-world frames on which 4 fails, each containing this two-cycle with at most one loop.

  4. Bisimilar models, one with a cycle and one without.

    Solution

    Take M, one world with a loop, and N, the infinite chain 0 → 1 → 2 → …, with the same atoms true everywhere in both. The relation that links M's world with every world of N is a bisimulation: every move on either side is matched by a move on the other, to a linked world with the same atoms. They are not isomorphic (one world versus infinitely many). No finite model without a cycle would do: in a finite acyclic model every path has at most n steps, so □ⁿ⁺¹⊥ is true at every world, while ◇ⁿ⁺¹⊤ is true at the loop.

  5. Two specifications in LTL. Write 'the light is never green in both directions' and 'every request is eventually granted' in LTL.

    Solution

    "The light is never green in both directions": G ¬(green_NS ∧ green_EW), a safety property (a finite trace can refute it). "Every request is eventually granted": G (request → F grant), a liveness property (only an infinite run can refute it).

  6. (Essay) The Master Argument has three exits. (Essay) Which exit from the master argument would you take, and what does it say 'possible' means?

    Solution

    A strong answer chooses one and prices it. Diodorus (reject C: the possible is what is or will be true): the cost is a near-determinism in which nothing that never happens was ever possible, and possibility becomes a fact about time. Cleanthes (reject P: some past truths are not necessary): the cost is that the past is not fixed, unless "necessary" is read as unpreventable only for genuine past events and not for "soft facts" about the past that depend on the future, the line taken by Ockham and, in Part 23, by the debate over foreknowledge. Chrysippus (reject I: the impossible can follow from the possible): the cost is that "possible" is no longer closed under entailment, so it cannot be "true in some world", and the Kripke semantics of this part must be given up or reinterpreted. Each choice is a theory of what "possible" means.

Notes and sources

Sources

Books: Hughes and Cresswell, A New Introduction to Modal Logic (1996); Blackburn, de Rijke and Venema, Modal Logic (2001), chs. 1–4; Chellas, Modal Logic: An Introduction (1980); Sider, Logic for Philosophy (2010), chs. 6–9; Garson, Modal Logic for Philosophers (2nd ed., 2013); Boolos, The Logic of Provability (1993); Huth and Ryan, Logic in Computer Science (2nd ed., 2004); Baier and Katoen, Principles of Model Checking (2008); Clarke, Grumberg and Peled, Model Checking (1999).

Texts and papers: Aristotle, De Interpretatione 9; Epictetus, Discourses II.19; Avicenna, The Metaphysics of The Healing; Duns Scotus, Lectura I.39; Leibniz, Theodicy (1710); C. I. Lewis, "Implication and the Algebra of Logic" (Mind 1912); Lewis and Langford, Symbolic Logic (1932); Kuratowski (1922); Ross, "Imperatives and Logic" (1941); McKinsey and Tarski, "The Algebra of Topology" (1944); Barcan, "A Functional Calculus of First Order Based on Strict Implication" (JSL 1946) and "The Identity of Individuals in a Strict Functional Calculus of Second Order" (1947); von Wright, "Deontic Logic" (Mind 1951); Quine, "Three Grades of Modal Involvement" (1953) and "Reference and Modality" (1953); Löb, "Solution of a Problem of Leon Henkin" (JSL 1955); Prior, Time and Modality (1957) and Past, Present and Future (1967); Kripke, "A Completeness Theorem in Modal Logic" (JSL 1959), "Semantical Analysis of Modal Logic I" (1963) and "Identity and Necessity" (1971); Hintikka, Knowledge and Belief (1962); Büchi (1962); Chisholm, "Contrary-to-Duty Imperatives and Deontic Logic" (Analysis 1963); Floyd, "Assigning Meanings to Programs" (1967); Hoare, "An Axiomatic Basis for Computer Programming" (CACM 1969); Hansson (1969); Segerberg, An Essay in Classical Modal Logic (1971); D. Lewis, Counterfactuals (1973); Goldblatt and Thomason, "Axiomatic Classes in Propositional Modal Logic" (1975); Sahlqvist, "Completeness and Correspondence in the First and Second Order Semantics for Modal Logic" (1975); van Benthem, Modal Correspondence Theory (1976); Solovay, "Provability Interpretations of Modal Logic" (1976); Pratt, "Semantical Considerations on Floyd–Hoare Logic" (1976); Pnueli, "The Temporal Logic of Programs" (FOCS 1977); Ladner, "The Computational Complexity of Provability in Systems of Modal Propositional Logic" (SIAM J. Comput. 1977); Peterson, "Myths About the Mutual Exclusion Problem" (IPL 1981); Clarke and Emerson (1981); Queille and Sifakis (1982); Alpern and Schneider, "Defining Liveness" (IPL 1985); Bryant, "Graph-Based Algorithms for Boolean Function Manipulation" (IEEE Trans. Comput. 1986); Vardi and Wolper (LICS 1986); Holzmann, The SPIN Model Checker (2003); Ball and Rajamani, SLAM (2002); Klein et al., seL4 (SOSP 2009); Leroy, CompCert (CACM 2009); Newcombe et al., "How Amazon Web Services Uses Formal Methods" (CACM 2015).

About this partfrom its README

Part 4 of Philosophy, Built (series plan, syllabus): modal logic, from Aristotle's sea battle and Diodorus's Master Argument to Kripke's possible worlds, the correspondence theory of axioms and frames, completeness, bisimulation and decidability, and on to its readings as obligation, time, programs, and the model checkers that verify chips and protocols. Its brick in the Wall is Goldblatt and Thomason's theorem (1975): some modal axioms, Löb's and McKinsey's among them, correspond to no first-order condition on the frames, so modal logic is not just first-order logic in disguise. Its Price List is the Master Argument: three claims that cannot all be true, and the three ancient exits.

Every frame count, truth table, tableau, bisimulation, filtration and state graph on screen is computed by the Reasoner's modal module (explainer/philosophy/reasoner/modal.py: a parser for □, ◇, the tense and deontic operators; Kripke models and evaluation; every frame on up to four worlds with its frame conditions; the correspondence checker; a finite model finder; the largest bisimulation and the minimal model; CTL's fixed points with fairness; Peterson's protocol and its broken variant; a prefixed tableau for K and T), tested in tests/philosophy/test_modal.py, and cached by compute.py.

Chapter notes
# Scene What it establishes Computed on screen
0 Hook might, must, ought, always: modalities; one box with six readings (Leibniz, Hintikka 1962, von Wright 1951, Prior 1957, Gödel–Löb–Solovay, Hoare–Pratt–Pnueli); the plan; the Wall's fourth brick, previewed. a first Kripke model evaluated
1 Ancient Aristotle's sea battle (De Interpretatione 9); the Master Argument of Diodorus Cronus (c. 300 BCE); Price List: the exits of Diodorus, Cleanthes and Chrysippus; Avicenna's necessary and possible existents (c. 1020); Duns Scotus and synchronic contingency (c. 1300); Leibniz's possible worlds (Theodicy, 1710). the MUS {P, I, C} and its three minimal corrections
2 Lewis the paradoxes of material implication; C. I. Lewis's strict implication (1912); Symbolic Logic (1932) and S1–S5; the axioms K, T, 4, 5 and necessitation; the 14 modalities of S4 and 6 of S5; topology: Kuratowski's closure axioms (1922) and McKinsey and Tarski (1944): S4 is the logic of interior. all 258 strings of up to five operators on p sorted into 14 classes (S4) and 6 (S5), on every reflexive transitive frame (389) and every equivalence frame (23) with up to 4 worlds
3 Kripke Kripke (1959), with Kanger, Hintikka, Montague and Prior; frames, models and the clauses for □ and ◇; evaluation world by world; dead ends and axiom D; what the arrows mean under six readings. ◇p, □p, □◇p and □p → p at all four worlds of a model
4 Corr validity on a frame; T ⇔ reflexive and 4 ⇔ transitive, with both directions proved; D, B, 5; the table of correspondences; what correspondence means philosophically. every frame on 3 and 4 worlds: T 64 / 4,096, D 343 / 50,625, B 64 / 1,024, 4 171 / 3,994, 5 39 / 306 valid, agreeing with the frame condition on all 512 and 65,536 frames
5 Lob Löb (1955) and Solovay (1976): GL is the logic of provability; Gödel's second incompleteness theorem as a one-line instance; GL ⇔ transitive and conversely well-founded; why that is not first-order (compactness); the Wall's fourth brick: Goldblatt–Thomason (1975); Sahlqvist's theorem (1975). Löb's axiom valid on exactly the strict partial orders: 3 of 16, 19 of 512, 219 of 65,536 frames
6 Canonical soundness and completeness for K; maximal consistent sets as worlds; the canonical relation; the truth lemma; canonicity of T and 4; S4 and S5 complete; GL is not canonical (Segerberg 1971). —
7 Bisim bisimulation (forth and back); the invariance theorem; the largest bisimulation and the minimal model; a loop and a cycle that no formula can tell apart; the standard translation; van Benthem's theorem (1976). the 6-world model merged into 4 classes, {0}, {1, 2}, {3, 4}, {5}; the loop ~ the 3-cycle
8 FMP filtration through the subformulas; the finite model property; decidability of K, T, S4 and S5; satisfiability (Ladner 1977): S5 NP-complete, K, T and S4 PSPACE-complete; S5 validity coNP-complete; the guarded fragment; prefixed tableaux. a 12-world chain filtered to 4 worlds for □◇p → ◇□p (bound 2⁶ = 64); K's axiom closed in 8 steps; ◇p ∧ ◇q → ◇(p ∧ q) refuted by a 3-world model; □p → p open in K, closed in T
9 QML Barcan Marcus (1946, 1947); the Barcan formula and its converse; constant and growing domains; Quine's objections (1953): the number of planets; de dicto and de re; the necessity of identity; Hesperus and Phosphorus; Kripke's rigid designators (1971). the Barcan formula true with constant domains, false with growing ones
10 Deontic von Wright (1951); standard deontic logic = KD; Ross's paradox (1941); Chisholm's contrary-to-duty paradox (1963); dyadic obligation (Hansson 1969, Lewis 1973). Ross's inference valid on every serial frame up to 3 worlds; Chisholm's four versions: each inconsistent or with a redundant sentence
11 Tense Prior's tense logic (1957); F, G, P, H; transitivity, no last moment, density and linearity as axioms; branching time; Peircean and Ockhamist readings of the sea battle. four sentences evaluated on the two-history tree, Peircean and Ockhamist
12 Temporal runs as paths; Pnueli (1977); X, F, G, U; safety and liveness (Alpern and Schneider 1985); CTL and model checking (Clarke and Emerson, Queille and Sifakis, 1981); fixed points; Vardi and Wolper's automata (1986), Büchi (1962). —
13 Peterson a state graph; Peterson's algorithm (1981); mutual exclusion as AG ¬(crit₀ ∧ crit₁); a broken variant and its counterexample; starvation and fairness. Peterson: 34 states, 62 edges, mutual exclusion holds; the broken variant: 50 states and an 8-step trace to both in the critical section; endless waiting possible from 8 states without fairness, on no fair path
14 Hoare Floyd (1967) and Hoare (1969) triples; the rules for assignment, sequence and loops; a loop invariant; Pratt's dynamic logic (1976). the summation invariant checked at all 496 loop points for n = 0, …, 30
15 Industry the Pentium FDIV bug (1994) and formal verification of chips; SPIN, SLAM, TLA⁺ at Amazon, seL4 and CompCert; state explosion and its answers; Bryant's BDDs (1986). the BDD of (x₁ ∧ y₁) ∨ … ∨ (xₙ ∧ yₙ): 2n + 2 nodes in a good order, 2ⁿ⁺¹ in a bad one, for n = 1, …, 6
16 Outro recap; the Reasoner's modal 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. Aristotle's sea battle and Diodorus's master argument: modality as an old problem.
  2. C. I. Lewis's strict implication (1912) and the systems S1–S5.
  3. Kripke semantics (1959–63): frames, models, □ and ◇. WorldGraph is introduced.
  4. Correspondence: T ↔ reflexive, 4 ↔ transitive, B ↔ symmetric, 5 ↔ Euclidean. Each is proved, then checked exhaustively on all frames of up to 4 worlds.
  5. Sahlqvist's theorem (statement), and Löb's axiom as a non-first-order frame condition (Goldblatt–Thomason).
  6. Completeness via canonical models.
  7. Bisimulation: what modal logic cannot distinguish; van Benthem's theorem (modal logic is the bisimulation- invariant fragment of FOL).
  8. Decidability and the finite model property; filtrations.
  9. Quantified modal logic: the Barcan formula; constant vs varying domains; Kripke's rigid designators (Part 22).
  10. Deontic logic: SDL, Ross's paradox, Chisholm's contrary-to-duty paradox (shown to be inconsistent in SDL by the Reasoner).
  11. Tense logic: Prior's tense logic; Ockhamist vs Peircean branching time (Part 23 returns to it).
  12. Temporal logic for machines: LTL and CTL (Pnueli 1977; Clarke, Emerson and Sifakis). Automata-theoretic model checking.
  13. Built: an LTL model checker verifying Peterson's mutual-exclusion algorithm, then finding the bug in a broken variant and showing the counterexample trace.
  14. Dynamic logic and Hoare logic: programs as modalities; {P} C {Q}.
  15. Industry: model checking in chip design (Intel after the 1994 FDIV bug), TLA+ at Amazon (Newcombe et al. 2015), SPIN and NuSMV.
  16. Recap and Problems.

Built: reasoner.modal (Kripke model checker, frame-property enumerator, bisimulation minimizer, LTL to Büchi, explicit-state model checking). Wall: correspondence limits (some modal axioms have no first-order frame condition); Chisholm's paradox for SDL. Visuals: frames morphing as an axiom is imposed; two bisimilar models collapsing into one; the Peterson state graph lighting up its reachable states and the bug trace. References: Hughes and Cresswell; Blackburn, de Rijke and Venema chs. 1–4; Sider ch. 6; Baier and Katoen; McNamara (SEP), "Deontic Logic".

中文讲义

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

习题与解答
  1. B,即 p → □◇p,恰好在对称框架上有效。

    解答

    若框架是对称的: 设 p 在 w 上为真,且 w R v。由对称性 v R w,所以 v 能看到一个 p 世界,◇p 在 v 上为真。这对 w 看到的每个 v 都成立,所以 □◇p 在 w 上为真。若框架不是对称的: 有某个 w R v 而没有 v R w。只让 p 在 w 上为真。那么 p 在 w 上为真,但 v 看不到任何 p 世界(唯一的 p 世界是 w,而 v 看不到它),所以 ◇p 在 v 上为假,□◇p 在 w 上为假。 推理机的对应检查器在 2、3、4 个世界的全部 16、512 和 65,536 个框架上都与此一致。

  2. 在 S5 中,◇□p → □p 有效;起作用的是公理 5。

    解答

    公理 5 是 ◇q → □◇q。令 q = ¬p 并取逆否:¬□◇¬p → ¬◇¬p,由于 ◇¬ 就是 ¬□, □¬ 就是 ¬◇,这正是 ◇□p → □p。所以它在任何包含 5 的逻辑中成立,在每个欧几里得框架上有效;不需要 T 和 4。从语义上看:若 w 看到一个 □p 成立的 v,且 w R u,则由欧几里得条件 v R u,所以 p 在 u 上成立。推理机发现 ◇□p → □p 恰好在欧几里得框架上有效:两个世界时 16 个中 有 7 个,三个世界时 512 个中有 39 个,与公理 5 的框架完全相同。

  3. 使 □p → □□p 不成立的最小框架有两个世界。

    解答

    只有一个世界时,两种可能的关系(空关系和一个自环)都是传递的,所以 4 有效。两个世界时, 取 0 R 1 和 1 R 0,没有自环,只让 p 在 0 上为真。在世界 1 上,□p 为真(它唯一看到的世界是 0,p 在那里成立),但 □□p 为假:1 看到 0, 0 看到 1,而 p 在 1 上不成立。推理机找到恰好三个使 4 不成立的两世界框架,每个都包含这个二元环,至多再加一个自环。

  4. 两个互模拟的模型,一个有环,一个无环。

    解答

    取 M 为一个带自环的世界,N 为无穷链 0 → 1 → 2 → …,两者处处有相同的原子为真。把 M 的 世界与 N 的每个世界相连的关系是一个互模拟:任一方的每一步都能被另一方的一步匹配,到达一个相连的、原子相同的世界。它们不同构(一个世界对 无穷多个)。任何无环的有限模型都不行:在有限无环模型中每条路径至多 n 步,所以 □ⁿ⁺¹⊥ 在每个世界上为真,而 ◇ⁿ⁺¹⊤ 在自环世界上为真。

  5. 两个 LTL 规约。 用LTL写出"信号灯从不在两个方向同时为绿"和"每个请求最终都会被批准"。

    解答

    "信号灯从不在两个方向同时为绿":G ¬(green_NS ∧ green_EW),这是安全性质(一条有限轨迹就能驳倒它)。"每个请求 最终都会被批准":G (request → F grant),这是活性性质(只有无穷的运行才能驳倒它)。

  6. (论述题)主论证有三条出路。

    解答

    好的回答选择一条并给它标价。狄奥多罗斯(拒绝 C:可能的就是现在或将来为真的):代价是一种近乎决定论 的立场,从不发生的事从来都不可能,可能性变成了关于时间的事实。克莱安西斯(拒绝 P:有些关于过去的真理不是必然的):代价是过去并不固定, 除非把"必然"理解为只对真正的过去事件不可阻止,而不包括依赖于未来的、关于过去的"软事实",这是奥卡姆的路线,也是第23部分关于预知的争论 所采取的路线。克吕西波(拒绝 I:不可能的可以从可能的推出):代价是"可能"不再在蕴涵下封闭,因此它不能是"在某个世界中为真",本部分的 克里普克语义学就必须放弃或重新解释。每一种选择都是一种关于"可能"意味着什么的理论。

Build the film

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

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

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