Level 0: Foundation
★☆☆☆☆ Introductory⏱ 6 minGeneral audience. No mathematics required.True or false?
A statement is a sentence that is either true or false. “The sky is blue” is a statement. “Close the door!” is not, because it isn’t true or false. It’s an order.
We can glue statements together with three little words:
- AND: “I have a pencil AND an eraser” is true only if I have both.
- OR: “I’ll have juice OR milk” is true if I have at least one (maybe both).
- NOT: flips true to false and false to true.
When is a promise broken?
Your friend says: “If it rains, I’ll bring an umbrella.” Think about the four possible days:
| Weather | Umbrella? | Promise kept? |
|---|---|---|
| 🌧️ Rain | ☂️ Yes | ✅ Kept |
| 🌧️ Rain | ❌ No | ❌ Broken! |
| ☀️ Sunny | ☂️ Yes | ✅ Kept (they just like umbrellas) |
| ☀️ Sunny | ❌ No | ✅ Kept |
The promise is only broken in one situation: it rains and there’s no umbrella. On a sunny day, the promise can’t be broken at all. This is exactly how mathematicians understand “if… then…”.
“Every” and “some”
- “Every cat has whiskers.” To show this is false, you only need to find one cat without whiskers.
- “Some dogs are brown.” To show this is true, you only need to find one brown dog.
What is a proof?
Checking a few examples isn’t enough. Try this rule: take a number, multiply it by itself, add the number, and add 41. For 0 you get 41, for 1 you get 43, for 2 you get 47. All of these are prime numbers. It works for 3, 4, 5 … all the way to 39! Surely it always works?
It doesn’t. At 40 you get 1681, which is 41 × 41. Forty examples in a row, and the rule still fails. A proof is an argument that covers every case, so no surprise can ever break it.
A robot’s safety rule might be: “If a person is closer than 1 metre, then stop.” Engineers write rules like this as logic so a computer can check that the robot follows them in every situation, not just the ones they tested.
- 1. Mum says: 'If you finish your homework, you can play.' You did NOT finish, and you did NOT play. Did Mum break her promise?
- 2. To prove 'Every bird can fly' is false, what do you need?
- 3. A rule worked for 1,000 examples in a row. Is it proven?
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.Propositions and connectives
We name statements with letters like and , and combine them with connectives:
| Symbol | Name | Read as | True when… |
|---|---|---|---|
| negation | not p | p is false | |
| conjunction | p and q | both are true | |
| disjunction | p or q | at least one is true | |
| implication | if p then q | not (p true and q false) | |
| biconditional | p if and only if q | p and q have the same truth value |
A truth table lists every possible combination. With two letters there are rows:
| T | T | T | T | T |
| T | F | F | T | F |
| F | T | F | T | T |
| F | F | F | F | T |
In , is the hypothesis and is the conclusion. When the hypothesis is false, the implication is automatically true. This is called being vacuously true.
Converse and contrapositive
From (“if it’s a dog, it has four legs”) you can make:
- the converse : “if it has four legs, it’s a dog”. ❌ Not the same: a cat has four legs.
- the contrapositive : “if it doesn’t have four legs, it’s not a dog”. ✅ Always means the same thing as the original.
Compare them yourself:
| p | q | p → q | ¬q → ¬p (contrapositive) |
|---|---|---|---|
| T | T | T | T |
| T | F | F | F |
| F | T | T | T |
| F | F | T | T |
Quantifiers
- means “for all”: says every real number has a non-negative square.
- means “there exists”: says some real number squares to 2.
Negating swaps the quantifier and negates what’s inside:
“Not every bird flies” means “some bird doesn’t fly”.
A data scientist writing WHERE age > 18 AND country = ‘IN’ in SQL is using logic. A decision tree is a stack of if–then rules. Python’s all() and any() are and .
- 1. p is false and q is true. What is p → q?
- 2. Which statement means the same as 'If x > 5 then x > 3'?
- 3. What is the negation of '∀x, x² ≥ 0'?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Logical equivalence
Two formulas are logically equivalent () if they have the same truth value in every row of the truth table. The most useful equivalences:
| Name | Equivalence |
|---|---|
| Implication | |
| Contrapositive | |
| De Morgan | |
| Distributive | |
| Biconditional | |
| Negated implication |
These are the same laws as for sets in A1-1. behave like , because means .
A tautology is true in every row (like ). A contradiction is false in every row (like ).
Nested quantifiers: order matters
The first says “for every number there’s a bigger one”, which is true. The second says “there’s one number bigger than all numbers”, which is false. Swapping and changes the meaning.
The definition of a limit is the most important nested-quantifier sentence in ML maths. means:
Read it as a game: you choose any tolerance , and I must reply with a that works. You’ll meet this again in calculus (A3).
The main proof techniques
| Technique | To prove … | Use when |
|---|---|---|
| Direct | assume , derive step by step | there’s a clear path forward |
| Contrapositive | assume , derive | the negation is easier to work with |
| Contradiction | assume , derive something impossible | proving something doesn’t exist |
| Cases | split into exhaustive cases, prove each | even/odd, positive/negative |
| Induction | prove for , then | statements about all natural numbers |
| Counterexample | find one case where it fails | disproving a “for all” claim |
| Construction | build the object explicitly | proving “there exists” |
Direct proof example. If is odd, then is odd. Odd means for some integer . Then , which is odd. ∎
Contrapositive example. If is even, then is even. The contrapositive is “if is odd, then is odd”, which we just proved. ∎
Induction example. For all , .
- Base case: gives . ✅
- Inductive step: assume it holds for . Then , which is the formula for . ∎
Induction is like dominoes: knock over the first one, and show each one knocks over the next.
Logic in code
Python’s all() is and any() is over a finite set. Because a formula with variables has only rows, a computer can check equivalence by brute force.
Code can find a counterexample, which disproves a claim. Code can check an identity on every case only when there are finitely many cases. For infinitely many cases, like “for all integers n”, you need a proof.
- 1. What is ¬(p → q) equivalent to?
- 2. Which sentence is true over the real numbers?
- 3. You want to prove '√2 is irrational'. Which technique fits best?
- 4. In an induction proof, what do you assume in the inductive step?
Level 3: Advanced
★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.Rules of inference
A proof is a chain of steps, each justified by a valid rule:
| Rule | From… | Conclude… |
|---|---|---|
| Modus ponens | ||
| Modus tollens | ||
| Hypothetical syllogism | ||
| Disjunctive syllogism | ||
| Universal instantiation | for any particular | |
| Existential generalization |
Two common fallacies look similar but are invalid: affirming the consequent (, so ) and denying the antecedent (, so ).
Classic proofs
is irrational.
Proof (contradiction). Suppose with integers and the fraction in lowest terms. Then , so is even. By the Level 2 result, is even: . Then , so and is even too. Now and are both even, so the fraction wasn’t in lowest terms. Contradiction. ∎
There are infinitely many prime numbers.
Proof. Suppose there were finitely many: . Let . Dividing by any leaves remainder 1, so no divides . But every integer above 1 has a prime factor, so has a prime factor that isn’t on the list. Contradiction. ∎
For every integer and every real : .
Proof (induction on ). Base: gives equality. Step: assume . Since , multiplying both sides by it keeps the inequality:
The last step uses . ∎ You’ll use this to analyse convergence of optimization algorithms (A6).
Strong induction and well-ordering
In strong induction, the inductive step may assume the statement for all values , not just .
Every integer is a product of primes. If is prime, we’re done. Otherwise with . By strong induction both and are products of primes, so is too. ∎
Induction is equivalent to the well-ordering principle: every non-empty set of natural numbers has a smallest element. A proof can say “take the smallest counterexample” and then show an even smaller one exists, which is a contradiction.
Proving algorithms correct: loop invariants
A loop invariant is a statement that is true before the loop, stays true after each iteration, and gives the answer when the loop ends. It’s induction applied to code.
For binary search on a sorted list, the invariant is “if the target is in the list, it’s between lo and hi”. It holds at the start. Each step keeps it true, because we only discard the half that can’t contain the target. The range shrinks every step, so the loop ends. When it does, either we’ve found the target or the range is empty, which means the target isn’t there. This style of reasoning is used to verify flight software.
Exercise 3.1: Prove that for all n ≥ 0, 1 + 2 + 4 + … + 2ⁿ = 2ⁿ⁺¹ − 1
Base : . Step: assume the sum up to is . Adding gives . ∎ (This is why a binary number with n + 1 ones equals 2ⁿ⁺¹ − 1.)
Exercise 3.2: Negate the limit definition. What does “f(x) does not tend to L” mean?
Swap each quantifier and negate the inside: . In words: there’s some tolerance such that, however close you look, some point still misses by at least that much.
Exercise 3.3: Find the flaw: “All horses are the same colour”
The “proof” uses induction on the number of horses. A group of n + 1 horses is split into the first n and the last n. Each group has one colour by induction, and the groups overlap, so all n + 1 horses share a colour. The flaw: when n + 1 = 2, the two groups (one horse each) don’t overlap, so the step from 1 to 2 fails. Every later step depends on it. Lesson: check that your inductive step works for the smallest case.
- 1. 'If it's a robot, it has sensors. This has sensors. So it's a robot.' This argument is…
- 2. In Euclid's proof, is N = p₁p₂⋯pₖ + 1 itself always prime?
- 3. Which is equivalent to ordinary induction on ℕ?
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.The limits of proof
Logic studies itself, and it found surprising limits:
- Completeness (Gödel, 1930). In first-order logic, every statement that is true in every possible model has a formal proof. Valid means provable.
- Incompleteness (Gödel, 1931). Any consistent formal system strong enough to do arithmetic contains true statements it can’t prove, and it can’t prove its own consistency.
- Undecidability (Turing, 1936). No algorithm can decide, for every program, whether it eventually halts. The proof is the same diagonal trick as Cantor’s (A1-1).
For an engineer, this means there’s no universal program that can verify every other program. Verification tools succeed by restricting what they analyse.
Logic as computation: SAT
A formula is satisfiable if some assignment of true/false makes it true. Cook (1971) proved that SAT is NP-complete: if you could solve SAT quickly in general, you could solve every problem whose answers are quick to check. Yet modern SAT and SMT solvers routinely handle millions of variables in practice, and they’re now core research tools:
- Planning as satisfiability. Kautz and Selman (1992) encoded “is there a plan of length T?” as a SAT problem, a technique still used in robot task planning (U7).
- Verifying neural networks. Reluplex (Katz et al., 2017) extended an SMT solver to prove properties of ReLU networks, such as “for all inputs in this region, the aircraft collision-avoidance network gives a safe advisory”. It was demonstrated on the ACAS Xu airborne collision-avoidance networks (M2).
Logic for robot behaviour: temporal logic
Ordinary logic talks about one moment. Linear Temporal Logic (LTL), introduced by Pnueli (1977) to reason about programs, adds operators over time: “always”, “eventually”, and “until”. A rover mission can be written as:
“Never collide, eventually reach the sample site, and whenever the battery is low, eventually recharge.” Kress-Gazit, Fainekos and Pappas (2009) showed how to synthesise robot controllers directly from such specifications, with a guarantee that the controller satisfies them. Signal Temporal Logic extends this to continuous signals, and its “robustness” score is now used as a reward or loss in robot learning.
Machines that check proofs
Proof assistants like Lean, Coq (now Rocq) and Isabelle check every inference step mechanically, so a checked proof leaves no doubt. NASA Langley’s formal methods group uses the PVS proof assistant to verify aircraft separation and collision-avoidance algorithms. A very active research direction combines LLMs with proof assistants: the language model proposes proof steps and the checker guarantees correctness. DeepMind’s AlphaProof (2024) used this approach with Lean to solve International Mathematical Olympiad problems.
Is P equal to NP? It’s one of the Clay Millennium Prize problems. Closer to robotics: how do we write formal specifications for learned components, like a perception network, where “correct” is hard to even state? Scaling verification to large networks is an open research area.
References
- G. Boole (1854). An Investigation of the Laws of Thought. Walton and Maberly.
- G. Frege (1879). Begriffsschrift. Louis Nebert. (The first full system of predicate logic.)
- K. Gödel (1930). “Die Vollständigkeit der Axiome des logischen Funktionenkalküls.” Monatshefte für Mathematik und Physik, 37.
- K. Gödel (1931). “Über formal unentscheidbare Sätze der Principia Mathematica und verwandter Systeme I.” Monatshefte für Mathematik und Physik, 38.
- A. Turing (1936). “On computable numbers, with an application to the Entscheidungsproblem.” Proceedings of the London Mathematical Society, s2-42.
- G. Pólya (1945). How to Solve It. Princeton University Press.
- S. Cook (1971). “The complexity of theorem-proving procedures.” STOC.
- A. Pnueli (1977). “The temporal logic of programs.” FOCS.
- H. Kautz and B. Selman (1992). “Planning as satisfiability.” ECAI.
- H. Kress-Gazit, G. Fainekos, G. Pappas (2009). “Temporal-logic-based reactive mission and motion planning.” IEEE Transactions on Robotics, 25(6).
- G. Katz, C. Barrett, D. Dill, K. Julian, M. Kochenderfer (2017). “Reluplex: An efficient SMT solver for verifying deep neural networks.” CAV.
- D. Velleman (2019). How to Prove It: A Structured Approach, 3rd ed. Cambridge University Press.