When does a conclusion really follow?

Logic

How truth became a one

SIX STOPS

Browse the stops with the arrows or by swiping left and right; the timeline stays at the top.

PROLOGUE · TODAY · A PUZZLE TO START

Is it even a statement?

I

QuestionWhich of this is a claim?

Before we set off for Athens, here is a sentence of the kind you might hear on the news. A politician declares:

“The presumption of innocence applies. For an ordinary citizen it is sacred and inviolable. For a politician, however, the presumption of guilt applies.”

Is that one statement? Which parts are claims whose truth can be decided, and which only express a judgement or give an order?

One possible analysis – once you have thought it through

These are three sentences, each of a different kind. “The presumption of innocence applies” is a claim that can be checked against the law. “It is sacred and inviolable” is a judgement: the truth of such a sentence cannot be decided, you can only agree or disagree with it. “For a politician the presumption of guilt applies” is, as a description of the law, a false claim; if the speaker means it as a demand (“it should apply”), then it is not a statement at all.

This is exactly how Aristotle would ask: which parts of what was said are claims, and what really follows from them?

II

IdeaLogic began as rules for speech.

The word logic itself comes from the Greek logos – word, speech, reason, reckoning. So logic began as rules for speech. That is the first clue as to why linguists later enter its story.

The whole chapter in one sentence: logic began as the rules of correct speech, the Stoics turned it into calculating with truth, Boole turned truth into the number 1 and falsehood into 0, and Shannon built circuits out of it. At each stop you will see where you meet the idea in code today.

“Contrariwise,” continued Tweedledee, “if it was so, it might be; and if it were so, it would be; but as it isn’t, it ain’t. That’s logic.”— Lewis Carroll, Through the Looking-Glass, 1871

III

FormulaThe route of the chapter.

THE ROUTE OF THE CHAPTER

speech ⟶ statement ⟶ {0, 1} ⟶ circuit

Logic began with orators and ended up in the processor.

STOP I · 4TH CENTURY BCE · ATHENS

Aristotle: when does a conclusion really follow?

I

QuestionDoes it follow, or does it just sound good?

How can you tell that a conclusion really follows, and doesn’t merely sound convincing?

In Athens in the 5th and 4th centuries BCE, everything was decided by speech: in the popular assembly, in court, where people defended themselves, and in the agora. The Sophists taught for money how to win an argument, not how to be right. Plato reproached them for it, and his student Aristotle asked a more precise question: are there rules by which one can mechanically tell that an argument is valid, regardless of who makes it and how nicely?

Three questions logic grew out of

  • How can you tell whether a conclusion really follows from the premises?
  • How do you derive a particular conclusion from general claims?
  • How do you tell a valid argument from one that only seems convincing?
II

PersonPlato’s student, Alexander’s teacher.

Aristotle (384–322 BCE) wrote down his answer in works that his students later called the Organon – “the tool”. For him logic was not a science about the world but a tool for all the other sciences. That is exactly how a programmer uses it today.

4TH C. BCEAristotle: Organon. Six logical works, among them the Categories, On Interpretation and the Prior Analytics, where he first described the syllogism.
4TH C. BCEAristotle: Metaphysics. In Book IV he defends the law of non-contradiction as “the most certain of all principles” and formulates the law of the excluded middle.
III

IdeaValidity is a matter of form.

Aristotle’s discovery: whether an argument is valid does not depend on what we are talking about, but on its form. So he began writing letters instead of words – the very first use of variables in the history of logic, two thousand years before algebra.

The syllogism: the first algorithm of reasoning

click the cards

Click the first premise.

The flying cat: truth is not the same as validity

All cats can fly. Felix is a cat. ⟹ Felix can fly. The premise and the conclusion are nonsense, and yet the argument is logically valid: its form is the same as with Socrates. If the premises held, the conclusion would have to hold. Logic does not check whether the input words are true, but whether the inner logical structure works.

The flying cat

toggle the premises
All cats can fly.
Felix is a cat.
⟹ Felix can fly.

Garbage in, garbage out: a correct program with bad data gives a bad result. And conversely, a correct result does not yet mean that the program is correct:

The fraudulent syllogism

look for a counterexample
All cats are mammals.
Felix is a mammal.
⟹ Felix is a cat.

The conclusion is true. But does it follow from the premises?

The laws Aristotle considered the firmest

In the Metaphysics (Book IV) Aristotle argues that the most certain of all principles is the law of non-contradiction: nothing can both be and not be in the same sense. Right next to it he formulates the law of the excluded middle: of any thing, one must either affirm something or deny it; there is nothing in between. These two laws are the root of two-valued logic – and so of the boolean type, which has exactly two values and nothing in between.

FOR THE CURIOUS: TRY IT!

Build the table for p ∨ ¬p. What comes out in the result column? And what is the negation of the sentence “Every prime greater than 2 is odd”?

Careful: it is not “Every… is even”. Aristotle distinguished contraries (both sentences can be false at once) from contradictories (exactly one is true).

Solution

The result column is all ones; it is a tautology. The negation: “Some prime greater than 2 is even.”

A curiosity: in On Interpretation Aristotle himself hesitated over whether the law of the excluded middle also applies to the future. Is the statement “There will be a sea battle tomorrow” already true or false today?

A third value: Łukasiewicz and NULL – in the 20th century Jan Łukasiewicz took up this doubt with three-valued logic, a forerunner of NULL in SQL

Around 1920 the Polish logician Jan Łukasiewicz (1878–1956) took Aristotle’s sea battle seriously. To truth (1) and falsehood (0) he added a third value ½: “not yet decided”. For such a statement the law of the excluded middle does not hold: if p = ½, then p ∨ ¬p is not true either.

The arithmetic is simple: negation is 1 − p (½ stays ½), “and” takes the smaller of the two values, “or” the larger.

p ∧ qq = 1q = ½q = 0
p = 11½0
p = ½½½0
p = 0000

SQL databases use a very similar logic (Kleene’s variant of 1938, which differs only for implication). NULL means “we don’t know the value”. That is why NULL = NULL gives not TRUE but UNKNOWN, and a WHERE clause lets through only rows whose result is TRUE. A classic trap: WHERE age >= 18 OR age < 18 does not return students whose age is missing.

IV

FormulaThe form of an argument and the two firmest laws.

SYLLOGISM

All M are P.  S is M.  ⟹  S is P.

¬(p ∧ ¬p)  ·  p ∨ ¬p

Whether an argument is valid depends not on what we talk about, but on its form.

STOP II · 3RD CENTURY BCE · ATHENS, THE STOA

The Stoics: a statement is what is true or false

the Stoics and Chrysippus

I

QuestionOf which sentence can you say “it holds”?

“It is raining.” – “Is it raining?” – “Let it rain!” Three sentences about the same thing. Of which of them does it make sense to ask whether it holds?

The Stoics’ answer

Only of the first. A question, a command or a wish has no truth value, and so none of them is a statement. The statement thus did not arise from grammar but from truth: it is the kind of utterance about which it makes sense to ask “does it hold?”.

II

PersonChrysippus of Soli and the crows on the roofs.

Aristotle worked with terms (humans, mortals). The Stoics in the 3rd century BCE, above all Chrysippus of Soli (c. 279–206 BCE), began working with whole sentences. They introduced the concept of the axíōma, which corresponds to our “statement”, and defined it precisely by truth: a statement is something that is either true or false.

The Stoics also studied how the truth of a compound sentence depends on the truth of its parts: “and”, “or”, “if… then”. They argued so fiercely about implication that the poet Callimachus is said to have written that even the crows on the roofs were cawing about which implication was the right one. The winner was the definition of Philo of Megara: the sentence “if A, then B” is false only when A holds and B does not. That is exactly the third column of today’s table, 2200 years older than the table itself.

We know the remark about Callimachus’s crows only from later authors (Sextus Empiricus). The Stoic logical works have not survived; we know about Chrysippus mainly from Diogenes Laertius (Lives of the Eminent Philosophers, Book VII).

III

IdeaCalculating with the truth of whole sentences.

ABif A, then B
111
100
011
001
FOR THE CURIOUS: WHAT DO YOU THINK?

Is the statement (2 > 4) ⇒ (2 divides 4) true? And why, in the sentence “If a number is divisible by 6, it is divisible by 3”, is divisibility by six a sufficient condition and divisibility by three a necessary one? Find a number that shows the converse does not hold.

Solution

True: this is the case 0 ⇒ 1, which Philo does not forbid. A counterexample: 3 is divisible by three but not by six.

Chrysippus also set down five basic rules of inference. The most famous of them we know today as modus ponens: If A, then B. A holds. ⟹ B holds.

FOR THE CURIOUS: TRY IT!

The Stoics knew that from “if A, then B” follows “if not B, then not A” (the contrapositive). Check with a table that p ⇒ q and ¬q ⇒ ¬p always have the same value. Then take the contrapositive of the definition of an injective function: ∀x1, x2 ∈ D(f): (f(x1) = f(x2) ⇒ x1 = x2).

Solution

The columns are identical. The contrapositive: ∀x1, x2 ∈ D(f): (x1 ≠ x2 ⇒ f(x1) ≠ f(x2)), that is, different inputs give different outputs.

The liar paradox: when a statement has no truth value

As early as the 4th century BCE, the paradox “This statement is false” was attributed to Eubulides of Miletus. If it is true, it is false; if it is false, it is true. Chrysippus is said to have written several works about it. The paradox shows the limit of the definition of a statement: not every declarative sentence is a statement.

The liar’s switch

give the sentence a value

“This statement is false.”

?

The liar in the 20th century: Gödel and Turing – in modern form the paradox leads to Gödel’s theorems and the halting problem

Kurt Gödel (1931) built the liar out of numbers. Instead of “this statement is false” he constructed, within arithmetic, a sentence that says “this statement cannot be proved”. If it could be proved, the system would be proving a falsehood. So it must be true, but unprovable. That is the first incompleteness theorem: every consistent system that can handle arithmetic contains true statements that cannot be proved in it. The second theorem adds that such a system cannot prove even its own consistency.

Alan Turing (1936) carried the same trick over to programs. Imagine a function halts(program) that reliably tells for any program whether it will finish. Then we write the liar:

function liar() {
    if (halts(liar)) while (true) {}  // should I finish? then I won’t
    else return;                      // should I not finish? then I will
  }

Whatever halts(liar) answers, liar does the opposite. So such a function cannot exist. That is why no tool can find all infinite loops in code in the general case, and linters only warn “maybe”.

IV

FormulaModus ponens and Philo’s implication.

MODUS PONENS

[(A ⇒ B) ∧ A]  ⇒  B

A ⇒ B is false only for A = 1, B = 0

A statement is the kind of utterance about which it makes sense to ask: does it hold?

STOP III · 1854 · CORK, IRELAND

George Boole: logic as algebra

Leibniz and George Boole

I

QuestionCalculemus!

Can the laws of correct reasoning be written down as algebra?

Gottfried Wilhelm Leibniz (1646–1716) dreamed of a characteristica universalis, a language in which concepts would be written as signs, and of a calculus ratiocinator, a calculus of reasoning. Disputes would then no longer be settled by quarrelling: two scholars would sit down and say Calculemus! – “let us calculate!”. Leibniz also described the binary system in detail (1703), with its two digits 0 and 1. But he did not yet connect logic and the binary system. That was done a century and a half later by a self-taught man from Lincoln.

II

PersonA shoemaker’s son who wanted to describe thought the way Newton described motion.

George Boole (1815–1864) was the son of a shoemaker from Lincoln; he taught himself mathematics and from the age of 16 worked as a teacher to support his family. Without a university degree he became a professor in Cork, Ireland. In 1847 he published a slim book, The Mathematical Analysis of Logic, and in 1854 his main work, An Investigation of the Laws of Thought. Hence the year 1854 for this chapter.

Boole’s aim was not to build a computer. He wanted to describe how people think as precisely as Newton described motion. He found that arguments can be written down and manipulated like equations.

George Boole 1815–1864, Lincoln – Cork

  1. 1815Born in Lincoln into a shoemaker’s family.
  2. 1831At 16 he begins teaching to support his family.
  3. 1847The Mathematical Analysis of Logic.
  4. 1849Professor of mathematics at Queen's College, Cork.
  5. 1854An Investigation of the Laws of Thought.
  6. 1864Dies of pneumonia at the age of 49.
1847George Boole: The Mathematical Analysis of Logic. A slim first book, written in a few weeks as an entry into the dispute between De Morgan and Hamilton.
1854George Boole: An Investigation of the Laws of Thought. His main work. In chapters 2 and 3 he derives x2 = x and from it the pair 0 and 1.

Alongside Boole worked Augustus De Morgan (1806–1871), who gave his name to the laws ¬(A ∧ B) ⇔ (¬A ∨ ¬B) and ¬(A ∨ B) ⇔ (¬A ∧ ¬B) – the ones a programmer uses every time they rewrite !(a && b) as !a || !b.

FOR THE CURIOUS: TRY IT!

Rewrite this so that the negation does not stand in front of the bracket: ¬((4 > 2) ∧ (4 < 2)). Is the original statement true, or its negation?

Solution

(4 ≤ 2) ∨ (4 ≥ 2). The negation is true, the original statement (4 > 2) ∧ (4 < 2) is false.

III

IdeaWhere 0 and 1 came from.

Boole did not reason about statements but about classes of things. For him the letter x might mean “white things”, y “sheep”. The product xy was then the intersection: “white sheep”. 1 was the whole universe of discourse, everything we are talking about, and 0 the empty class, nothing.

Then he noticed something odd. White white things are still just white things, so xx = x, that is

x2 = x.

In ordinary algebra this equation has only two solutions: x = 0 and x = 1. From this Boole drew a conclusion that changed history: the algebra of thought is ordinary algebra restricted to the numbers 0 and 1. In his second book he then interpreted 1 as “always”, that is truth, and 0 as “never”, that is falsehood.

From the same equation Boole also derived Aristotle’s law of non-contradiction: x − x2 = 0, or x(1 − x) = 0. In words: nothing can both have the property x and not have it (1 − x). The oldest law of logic fell out of algebra as a by-product.

Boole’s sheep

multiply classes
1 (everything) x white things y sheep

Click x and the white things will be coloured in.

FOR THE CURIOUS: WHAT DO YOU THINK?

Is there an integer that does not change when you square it? Write the question in symbols and find all such numbers.

Solution

(∃x ∈ ℤ)(x2 = x). Exactly 0 and 1 satisfy it – Boole’s pair. All of propositional logic rests on the numbers that do not change when you multiply them by themselves.

IV

FormulaAn equation with only two solutions.

THE LAWS OF THOUGHT

x2 = x  ⟺  x ∈ {0, 1}

x(1 − x) = 0

Truth is 1, falsehood is 0 – and “and” is ordinary multiplication.

STOP IV · 1879–1921

Truth tables: calculate them, don’t memorise them

Frege, Peirce, Wittgenstein, Post

I

QuestionWhere did the tables come from?

If truth is 1 and falsehood 0, can the tables for “not”, “and”, “or” and “if” be calculated instead of learned by heart?

Boole did not draw tables; he calculated with equations. The table as a method arrived only several decades later.

II

PersonFour people and one table.

  • Gottlob Frege (1879, Begriffsschrift) described precisely when an implication is true by listing all four cases – still in words.
  • Charles S. Peirce drew, around 1893 in an unpublished manuscript, a matrix that is today’s truth table for implication. It turned up only among his papers after his death.
  • Ludwig Wittgenstein (Tractatus, 1921) and, independently, Emil Post (1921) published the tables and showed that with them one can decide for any propositional formula whether it is a tautology. Wittgenstein in effect defined a tautology as a formula whose result column is all truths.
1879Gottlob Frege: Begriffsschrift (Concept Script). Fewer than a hundred pages, the first formal language with quantifiers.
1921Ludwig Wittgenstein: Tractatus logico-philosophicus. From section 4.31 on: truth tables and the definition of a tautology.

Frege distrusted natural language: he considered it imprecise and ambiguous, and so he created a language of his own. How logic and language carried on is told on the separate page Language and logic.

III

IdeaCalculate as if they were numbers.

Once truth is 1 and falsehood 0, we can look at connectives as arithmetic operations: we put in two numbers, 0 or 1, and get 0 or 1 back. The task: find a formula that gives 1 exactly in those rows where the compound statement is true. Step by step:

  1. Negation. We need an operation that turns 1 into 0 and 0 into 1. Subtracting from one does it: 1 − 1 = 0 and 1 − 0 = 1. So ¬p = 1 − p.
  2. Conjunction “p and q”. It should hold only when both parts hold. Let’s try the product: 1 · 1 = 1, 1 · 0 = 0, 0 · 1 = 0, 0 · 0 = 0. A single zero wipes out the whole product, just as a single false part brings down the whole “and”. So p ∧ q = p · q.
  3. Disjunction “p or q”. It should hold when at least one part holds. The first idea is the sum p + q. It works in three rows, but for p = q = 1 it gives 2, and there is no 2 in our world. We fix it by subtracting the common part once: p + q − pq. (Boole himself wrote just x + y and meant the exclusive “or”; the inclusive version was championed mainly by W. S. Jevons.)
  4. Implication “if p, then q”. According to Philo it is false in a single case: p = 1 and q = 0. We write this “forbidden” case as the product p(1 − q), which is 1 only when p = 1 and at the same time q = 0. The implication holds when the forbidden case has not occurred, so we negate it: p ⇒ q = 1 − p(1 − q).
  5. Equivalence “p if and only if q”. It should hold when p and q have the same value. The difference p − q is 0 when they agree and +1 or −1 when they disagree. Squaring removes the sign: (p − q)2 is 0 when they agree and 1 when they disagree. All that remains is to flip the result: p ⇔ q = 1 − (p − q)2.

The truth calculator

toggle p and q
p = q =
    pq1 − pp · qp + q − pq1 − p(1 − q)1 − (p − q)2

    Out comes exactly the familiar truth table, this time not learned but calculated. So the table is an algorithm: go through all 2n combinations and look. It is the first decision procedure in logic – and brute force in its purest form.

    FOR THE CURIOUS: TRY IT!

    How many rows will the table for three statements p, q, r have? (Hint: each of them is a solution of x2 = x.) And check without a table, just by calculating, that (p ∧ q) ⇒ p always holds. Use p · p = p.

    Solution

    23 = 8 rows. And by calculation:

    1 − pq(1 − p) = 1 − pq + p2q = 1 − pq + pq = 1,

    so it is a tautology.

    IV

    FormulaImplication as arithmetic.

    CONNECTIVES AS ARITHMETIC OPERATIONS

    p ⇒ q  =  1 − p(1 − q)

    ¬p = 1 − p  ·  p ∧ q = pq  ·  p ∨ q = p + q − pq

    The table is an algorithm: go through all 2n rows and look.

    STOP V · 1937 · MIT

    Claude Shannon: from tables to circuits

    I

    QuestionFrom philosophy to engineering.

    For eighty years Boolean algebra was a curiosity for philosophers. Can you build a machine out of it?

    II

    PersonThe master’s thesis that changed the world.

    In 1937 the twenty-one-year-old Claude Shannon wrote his master’s thesis at MIT, A Symbolic Analysis of Relay and Switching Circuits. He showed that switches connected in series behave like ∧, and switches connected in parallel like ∨. On = 1, off = 0. From that moment any logical argument could be built from wires. Every processor is a pile of Boolean equations.

    MIT, 1937 (IN A JOURNAL 1938)Claude E. Shannon: A Symbolic Analysis of Relay and Switching Circuits. The master’s thesis of a twenty-one-year-old student, often called the most influential master’s thesis of the 20th century.
    III

    IdeaIn series is “and”, in parallel is “or”.

    Two switches and a light bulb

    click the switches
    Circuit 1
    A B
    ABbulb
    Circuit 2
    A B
    ABbulb

    Try all four combinations in both circuits.

    FOR THE CURIOUS: LOGIC IN A DATABASE
    SELECT name, year FROM Student
      WHERE age >= 18 AND (year = 1 OR year = 2);

    Write the condition as A(x) ∧ (Y1(x) ∨ Y2(x)). Which students does the query select? And what happens if you leave out the brackets?

    Solution

    Adult students in their 1st and 2nd year. Without brackets AND takes precedence: (A ∧ Y1) ∨ Y2, so under-age 2nd-year students get in too. The same problem we solve with commas in speech.

    IV

    FormulaTwo switches, two connectives.

    LOGIC CIRCUITS

    in series:  a · b = a ∧ b

    in parallel:  a + b − ab = a ∨ b

    Every processor is a pile of Boolean equations.

    What we have seen

    From the rules of correct speech to the zero and one in a processor.

    1. IAristotle: the validity of an argument depends on its form, not its content; the syllogism, the law of non-contradiction and the law of the excluded middle.
    2. IIThe Stoics: a statement is something that is either true or false; connectives, Philo’s implication, modus ponens.
    3. IIIBoole: x2 = x, so truth is 1 and falsehood is 0.
    4. IVTables: connectives as arithmetic operations and the truth table as an algorithm.
    5. VShannon: a series circuit is ∧, a parallel one is ∨; logic made of wires.

    TWO THOUSAND YEARS OF REASONING IN TWO LINES

    x2 = x  ⟺  x ∈ {0, 1}

    p ⇒ q  =  1 − p(1 − q)

    What Aristotle looked for in speech, Chrysippus in truth and Boole in algebra, we now write as !p || q.

    Why logic was needed

    A summary for programmers.

    EraProblemLogic’s answerWhere you meet it in code
    4th c. BCEThe better speaker wins, not the truth.The syllogism: validity by form.Inference rules, type systems.
    3rd c. BCEWhen is a compound sentence true?Statements, connectives, Philo’s implication.&&, ||, !, if conditions.
    1854Can thinking be calculated?Boolean algebra, 0 and 1.The boolean type, bitwise operations.
    1879–1921How do we write it without ambiguity?Quantifiers, truth tables.every(), some(), testing.
    1937How do we build it?Logic circuits.AND/OR/NOT gates in a processor.
    A SEPARATE CHAPTER ☞ Language and logic What role did linguists play: from the Stoic grammarians through Frege and Carnap to Chomsky’s grammars and Montague?

    Sources and further reading

    • Stanford Encyclopedia of Philosophy: Aristotle's Logic, Ancient Logic, George Boole, Frege's Logic, The Algebra of Logic Tradition.
    • Aristotle: Prior Analytics (the syllogism), Metaphysics IV (non-contradiction, excluded middle), On Interpretation 9 (the sea battle).
    • Diogenes Laertius: Lives of the Eminent Philosophers, Book VII (Stoic logic, Philo, Chrysippus).
    • G. Boole: An Investigation of the Laws of Thought (1854), ch. II–III – freely available on Project Gutenberg.
    • I. H. Anellis: The Genesis of the Truth-Table Device, Russell 24 (2004) – on Peirce’s table of 1893.
    • C. E. Shannon: A Symbolic Analysis of Relay and Switching Circuits, MIT, 1937/1938.
    • P. Nahin: The Logician and the Engineer (2012) – a popular book on Boole and Shannon.

    END OF THE CHAPTER ON LOGIC

    Back to contents