Foundations to Frontier
Tests
A. Mathematical Foundations › A1 Prerequisites and Mathematical Thinking

Logic, Quantifiers and Proof Techniques

How to tell a promise kept from a promise broken, what "for all" and "there exists" really mean, and how mathematicians make arguments that leave no doubt.

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.

In robotics

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.

📝 Quick check (Level 0)
0/3 answered
  1. 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. 2. To prove 'Every bird can fly' is false, what do you need?
  3. 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 pp and qq, and combine them with connectives:

Symbol Name Read as True when…
¬p\neg p negation not p p is false
p∧qp \land q conjunction p and q both are true
p∨qp \lor q disjunction p or q at least one is true
p→qp \to q implication if p then q not (p true and q false)
p↔qp \leftrightarrow q 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 22=42^2 = 4 rows:

pp qq p∧qp \land q p∨qp \lor q p→qp \to q
T T T T T
T F F T F
F T F T T
F F F F T

In p→qp \to q, pp is the hypothesis and qq is the conclusion. When the hypothesis is false, the implication is automatically true. This is called being vacuously true.

Converse and contrapositive

From p→qp \to q (“if it’s a dog, it has four legs”) you can make:

  • the converse q→pq \to p: “if it has four legs, it’s a dog”. ❌ Not the same: a cat has four legs.
  • the contrapositive ¬q→¬p\neg q \to \neg p: “if it doesn’t have four legs, it’s not a dog”. ✅ Always means the same thing as the original.

Compare them yourself:

Truth-table comparer
Compare with
pqp → q¬q → ¬p (contrapositive)
TTTT
TFFF
FTTT
FFTT
✅ Logically equivalent: they agree in every row.

Quantifiers

  • ∀\forall means “for all”: ∀x∈R, x2≥0\forall x \in \mathbb{R},\ x^2 \ge 0 says every real number has a non-negative square.
  • ∃\exists means “there exists”: ∃x∈R, x2=2\exists x \in \mathbb{R},\ x^2 = 2 says some real number squares to 2.

Negating swaps the quantifier and negates what’s inside:

¬(∀x, P(x))≡∃x, ¬P(x)¬(∃x, P(x))≡∀x, ¬P(x)\neg(\forall x,\ P(x)) \equiv \exists x,\ \neg P(x) \qquad \neg(\exists x,\ P(x)) \equiv \forall x,\ \neg P(x)

“Not every bird flies” means “some bird doesn’t fly”.

Why AI cares

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 ∀\forall and ∃\exists.

📝 Quick check (Level 1)
0/3 answered
  1. 1. p is false and q is true. What is p → q?
  2. 2. Which statement means the same as 'If x > 5 then x > 3'?
  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 (≡\equiv) if they have the same truth value in every row of the truth table. The most useful equivalences:

Name Equivalence
Implication p→q≡¬p∨qp \to q \equiv \neg p \lor q
Contrapositive p→q≡¬q→¬pp \to q \equiv \neg q \to \neg p
De Morgan ¬(p∧q)≡¬p∨¬q,¬(p∨q)≡¬p∧¬q\neg(p \land q) \equiv \neg p \lor \neg q, \quad \neg(p \lor q) \equiv \neg p \land \neg q
Distributive p∧(q∨r)≡(p∧q)∨(p∧r)p \land (q \lor r) \equiv (p \land q) \lor (p \land r)
Biconditional p↔q≡(p→q)∧(q→p)p \leftrightarrow q \equiv (p \to q) \land (q \to p)
Negated implication ¬(p→q)≡p∧¬q\neg(p \to q) \equiv p \land \neg q

These are the same laws as for sets in A1-1. ∧,∨,¬\land, \lor, \neg behave like ∩,∪,c\cap, \cup, {}^c, because x∈A∩Bx \in A \cap B means x∈A∧x∈Bx \in A \land x \in B.

A tautology is true in every row (like p∨¬pp \lor \neg p). A contradiction is false in every row (like p∧¬pp \land \neg p).

Nested quantifiers: order matters

∀x ∃y: y>xvs.∃y ∀x: y>x\forall x\ \exists y:\ y > x \qquad\text{vs.}\qquad \exists y\ \forall x:\ y > x

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 ∀\forall and ∃\exists changes the meaning.

The definition of a limit is the most important nested-quantifier sentence in ML maths. lim⁡x→af(x)=L\lim_{x \to a} f(x) = L means:

∀ε>0  ∃δ>0  ∀x:  0<∣x−a∣<δ ⇒ ∣f(x)−L∣<ε\forall \varepsilon > 0\ \ \exists \delta > 0\ \ \forall x:\ \ 0 < |x - a| < \delta \ \Rightarrow\ |f(x) - L| < \varepsilon

Read it as a game: you choose any tolerance ε\varepsilon, and I must reply with a δ\delta that works. You’ll meet this again in calculus (A3).

The main proof techniques

Technique To prove p→qp \to q… Use when
Direct assume pp, derive qq step by step there’s a clear path forward
Contrapositive assume ¬q\neg q, derive ¬p\neg p the negation is easier to work with
Contradiction assume p∧¬qp \land \neg q, derive something impossible proving something doesn’t exist
Cases split into exhaustive cases, prove each even/odd, positive/negative
Induction prove for n=1n = 1, then n⇒n+1n \Rightarrow n+1 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 nn is odd, then n2n^2 is odd. Odd means n=2k+1n = 2k + 1 for some integer kk. Then n2=4k2+4k+1=2(2k2+2k)+1n^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1, which is odd. ∎

Contrapositive example. If n2n^2 is even, then nn is even. The contrapositive is “if nn is odd, then n2n^2 is odd”, which we just proved. ∎

Induction example. For all n≥1n \ge 1, 1+2+⋯+n=n(n+1)21 + 2 + \dots + n = \frac{n(n+1)}{2}.

  • Base case: n=1n=1 gives 1=1⋅221 = \frac{1 \cdot 2}{2}. ✅
  • Inductive step: assume it holds for nn. Then 1+⋯+n+(n+1)=n(n+1)2+(n+1)=(n+1)(n+2)21 + \dots + n + (n+1) = \frac{n(n+1)}{2} + (n+1) = \frac{(n+1)(n+2)}{2}, which is the formula for n+1n+1. ∎

Induction is like dominoes: knock over the first one, and show each one knocks over the next.

Logic in code

Python’s all() is ∀\forall and any() is ∃\exists over a finite set. Because a formula with nn variables has only 2n2^n rows, a computer can check equivalence by brute force.

🐍 Exercise 1: check equivalences by brute force
Write implies(p, q), then equivalent(f, g, n), which returns True if two n-variable formulas agree on all 2ⁿ inputs. Hint: itertools.product([True, False], repeat=n).
🐍 Exercise 2: find the counterexample
n² + n + 41 is prime for many n. Write is_prime(n) and first_counterexample(), which returns the smallest n ≥ 0 where n² + n + 41 is NOT prime.
Common mistake

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.

📝 Quick check (Level 2)
0/4 answered
  1. 1. What is ¬(p → q) equivalent to?
  2. 2. Which sentence is true over the real numbers?
  3. 3. You want to prove '√2 is irrational'. Which technique fits best?
  4. 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 p,  p→qp,\ \ p \to q qq
Modus tollens ¬q,  p→q\neg q,\ \ p \to q ¬p\neg p
Hypothetical syllogism p→q,  q→rp \to q,\ \ q \to r p→rp \to r
Disjunctive syllogism p∨q,  ¬pp \lor q,\ \ \neg p qq
Universal instantiation ∀x P(x)\forall x\, P(x) P(c)P(c) for any particular cc
Existential generalization P(c)P(c) ∃x P(x)\exists x\, P(x)

Two common fallacies look similar but are invalid: affirming the consequent (q, p→qq,\ p \to q, so pp) and denying the antecedent (¬p, p→q\neg p,\ p \to q, so ¬q\neg q).

Classic proofs

Theorem

2\sqrt{2} is irrational.

Proof (contradiction). Suppose 2=a/b\sqrt 2 = a/b with integers a,ba, b and the fraction in lowest terms. Then a2=2b2a^2 = 2b^2, so a2a^2 is even. By the Level 2 result, aa is even: a=2ca = 2c. Then 4c2=2b24c^2 = 2b^2, so b2=2c2b^2 = 2c^2 and bb is even too. Now aa and bb are both even, so the fraction wasn’t in lowest terms. Contradiction. ∎

Theorem (Euclid, c. 300 BC)

There are infinitely many prime numbers.

Proof. Suppose there were finitely many: p1,…,pkp_1, \dots, p_k. Let N=p1p2⋯pk+1N = p_1 p_2 \cdots p_k + 1. Dividing NN by any pip_i leaves remainder 1, so no pip_i divides NN. But every integer above 1 has a prime factor, so NN has a prime factor that isn’t on the list. Contradiction. ∎

Bernoulli's inequality

For every integer n≥1n \ge 1 and every real x≥−1x \ge -1: (1+x)n≥1+nx(1 + x)^n \ge 1 + nx.

Proof (induction on nn). Base: n=1n = 1 gives equality. Step: assume (1+x)n≥1+nx(1+x)^n \ge 1 + nx. Since 1+x≥01 + x \ge 0, multiplying both sides by it keeps the inequality:

(1+x)n+1≥(1+nx)(1+x)=1+(n+1)x+nx2≥1+(n+1)x.(1+x)^{n+1} \ge (1+nx)(1+x) = 1 + (n+1)x + nx^2 \ge 1 + (n+1)x.

The last step uses nx2≥0nx^2 \ge 0. ∎ 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 1,…,n1, \dots, n, not just nn.

Every integer n≥2n \ge 2 is a product of primes. If nn is prime, we’re done. Otherwise n=abn = ab with 2≤a,b<n2 \le a, b < n. By strong induction both aa and bb are products of primes, so nn 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 n=0n=0: 1=2−11 = 2 - 1. Step: assume the sum up to 2n2^n is 2n+1−12^{n+1} - 1. Adding 2n+12^{n+1} gives 2⋅2n+1−1=2n+2−12 \cdot 2^{n+1} - 1 = 2^{n+2} - 1. ∎ (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: ∃ε>0 ∀δ>0 ∃x: 0<∣x−a∣<δ ∧ ∣f(x)−L∣≥ε\exists \varepsilon > 0\ \forall \delta > 0\ \exists x:\ 0 < |x-a| < \delta \ \land\ |f(x) - L| \ge \varepsilon. In words: there’s some tolerance such that, however close you look, some point still misses LL 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.

📝 Quick check (Level 3)
0/3 answered
  1. 1. 'If it's a robot, it has sensors. This has sensors. So it's a robot.' This argument is…
  2. 2. In Euclid's proof, is N = p₁p₂⋯pₖ + 1 itself always prime?
  3. 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: □\square “always”, ◊\lozenge “eventually”, and U\mathcal{U} “until”. A rover mission can be written as:

□ ¬collision ∧ ◊ sample_site ∧ □(low_battery→◊ charging)\square\, \neg \text{collision} \ \land\ \lozenge\, \text{sample\_site} \ \land\ \square(\text{low\_battery} \to \lozenge\, \text{charging})

“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.

Open 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

  1. G. Boole (1854). An Investigation of the Laws of Thought. Walton and Maberly.
  2. G. Frege (1879). Begriffsschrift. Louis Nebert. (The first full system of predicate logic.)
  3. K. Gödel (1930). “Die Vollständigkeit der Axiome des logischen Funktionenkalküls.” Monatshefte für Mathematik und Physik, 37.
  4. K. Gödel (1931). “Über formal unentscheidbare Sätze der Principia Mathematica und verwandter Systeme I.” Monatshefte für Mathematik und Physik, 38.
  5. A. Turing (1936). “On computable numbers, with an application to the Entscheidungsproblem.” Proceedings of the London Mathematical Society, s2-42.
  6. G. Pólya (1945). How to Solve It. Princeton University Press.
  7. S. Cook (1971). “The complexity of theorem-proving procedures.” STOC.
  8. A. Pnueli (1977). “The temporal logic of programs.” FOCS.
  9. H. Kautz and B. Selman (1992). “Planning as satisfiability.” ECAI.
  10. H. Kress-Gazit, G. Fainekos, G. Pappas (2009). “Temporal-logic-based reactive mission and motion planning.” IEEE Transactions on Robotics, 25(6).
  11. G. Katz, C. Barrett, D. Dill, K. Julian, M. Kochenderfer (2017). “Reluplex: An efficient SMT solver for verifying deep neural networks.” CAV.
  12. D. Velleman (2019). How to Prove It: A Structured Approach, 3rd ed. Cambridge University Press.