Module 01

Discrete Mathematics and Logic

How can we describe, formalize, and prove mathematically that an algorithm is correct?

lessons
22
duration
37 h 45 min
concepts
137
available in English
22 / 22
completed by you
0 of 22

Where it fits

Leads to

Overview

Explore the language of logic, sets, and relations; proof techniques, with structural induction and loop invariants as central tools; combinatorics and recurrences; graph and tree theory; Boolean algebra; satisfiability; and the limits of computation. The approach is constructive: each idea becomes code that verifies, counts, encodes, or proves, and the module ends at the frontier of AI-assisted formal verification.

Why it matters

This is the language used in proofs throughout the curriculum, from generalization bounds to convergence and the correctness of search and training algorithms. Invariants and induction help debug implementations, from a BPE tokenizer to AlphaZero's MCTS, through reasoning; combinatorics and recurrences provide exact cost analyses. SAT, Hoare logic, and Rice's theorem underpin static analysis and verification, with direct applications to application security. Formal proof with large language models is also an active area of research.

Lessons 22

  1. 01Propositional logic: syntax, semantics and entailmentA dense review of propositional logic as a formal language: syntax as trees, semantics through valuations, equivalence, satisfiability, and logical consequence. Conclude with CNF and DNF normal forms and their cost as preparation for SAT.Review75 min
  2. 02Predicate logic and formal specificationReview first-order logic: terms, quantifiers, free and bound variables, structures, and Tarski interpretation. The practical focus is writing precise specifications with preconditions and postconditions and checking them in finite models.Review90 min
  3. 03Sets, functions and cardinalityReview naive set theory, functions and their properties, images and preimages. Develop infinite cardinality and Cantor's diagonal argument, which reappears in the halting problem's undecidability.Review75 min
  4. 04Proof techniques and natural deductionReview proof techniques—direct proof, contraposition, contradiction, cases, existence, and counterexample—as goal-oriented strategies. Formalize them as natural deduction rules and state propositional soundness and completeness, bridging proof and truth.Review95 min
  5. 05Mathematical induction and the well-ordering principleThe three forms of induction (weak, strong and well-ordering), their equivalence, and the art of strengthening the hypothesis, exactly as when finding a loop invariant. A constructive inductive proof is a recursive algorithm.Core90 min
  6. 06Relations: equivalences, orders and well-foundednessBinary relations as mathematical objects and Boolean matrices: properties, transitive closure, equivalences and partitions, congruence modulo n, partial orders, linear extensions and well-founded relations. Lattices provide a foundation for fixed points and static analysis.Core105 min
  7. 07Inductive definitions, structural induction and fixed pointsProgram data such as lists, trees, formulas and ASTs are defined inductively and their properties proved by structural induction. Well-founded induction generalizes this, and an inductive set is the least fixed point of a monotone operator (Knaster–Tarski), the same idea behind termination of data-flow analysis.Core105 min
  8. 08Algorithm correctness: loop invariants and terminationProving an algorithm correct: distinguish partial and total correctness, build inductive loop invariants and variants over well-founded orders, and apply them to binary search, partitioning, insertion sort, extended Euclid, fast exponentiation and modular arithmetic.Core110 min
  9. 09Hoare logic, weakest preconditions and machine-assisted verificationFrom informal invariants to formal calculation: Hoare triples and inference rules, Dijkstra's weakest precondition, and automatic verification conditions discharged by a solver. We sketch logical soundness against semantics and introduce Dafny, separation logic and LLM-proposed invariants. GPUAdvanced115 min
  10. 10Counting: rules, binomial coefficients, pigeonhole and inclusion-exclusionA rigorous review of counting: sum and product rules, bijections, ordered selections, permutations and combinations with and without repetition, stars and bars, the binomial theorem, double counting, pigeonhole and inclusion–exclusion. Each formula is checked against explicit enumeration.Review110 min
  11. 11Permutations: cycle structure, parity and counting under symmetryPermutations as objects: cycles, composition, sign and the symmetric group. Group actions and Burnside's lemma count configurations up to symmetry, as in AlphaGo Zero's board-symmetry data augmentation. Fisher–Yates shuffling is proved correct.Core100 min
  12. 12Recurrences: modelling and solvingModel a recursive algorithm or counting problem with a recurrence and solve it by unrolling, substitution with induction, recursion trees, characteristic polynomials, particular solutions and matrix form. The master theorem is deferred to m08.Core105 min
  13. 13Generating functions and analytic combinatoricsGenerating functions turn counting problems into algebra on power series. Study ordinary and exponential generating functions, Catalan, Stirling and Bell numbers, integer partitions, the Flajolet-Sedgewick symbolic method, and asymptotics from the dominant singularity.Advanced120 min
  14. 14Graphs: concepts, connectivity and traversalsA rigorous introduction to graphs: definitions, degrees, representations, isomorphism, paths and connectivity, including strong connectivity in directed graphs; directed acyclic graphs and partial orders; breadth-first and depth-first traversal trees; and certificates for bipartite and Eulerian graphs.Core110 min
  15. 15Trees: characterizations, counting and structureTrees as a central structure in computer science: equivalent characterizations, rooted and binary trees, traversals and reconstruction, spanning trees, Cayley's formula through the Prüfer bijection, and the matrix-tree theorem. The lesson concludes with the height bound for decision trees, used in m08 to derive the comparison-sorting lower bound.Core100 min
  16. 16Matchings, colouring, planarity and Ramsey theoryClassical structural results with certificates in both directions: Hall's and König's theorems for matchings, graph coloring and chromatic number, planar graphs and Euler's formula, and Ramsey theory with Erdős's probabilistic bound. The four-color theorem bridges to computer-assisted proof.Advanced100 min
  17. 17Boolean algebra, Boolean functions and circuitsBoolean algebra as an algebraic structure and Boolean functions as objects: canonical forms, functional completeness, circuits and their complexity (Shannon's counting argument), two-level minimization, and reduced ordered binary decision diagrams (ROBDDs), a canonical representation widely used in verification.Core105 min
  18. 18Satisfiability: CNF, the Tseitin transformation and problem encodingsSAT as a problem and modeling language: certificates, linear-size Tseitin conversion to CNF, encodings of practical problems (coloring, Sudoku, bounded-horizon planning), cardinality constraints, the polynomial cases 2-SAT and Horn-SAT, and bounded verification of programs and circuits. This bridges to the SAT and SMT solvers of m10. GPUCore110 min
  19. 19Resolution and DPLL: proving unsatisfiabilityHow to prove a formula has no solution: the resolution rule, its soundness and refutational completeness, and DPLL, whose failed runs are tree-like resolution refutations. The lesson studies limitations (Haken's exponential pigeonhole bound) and the random 3-SAT phase transition, preparing for CDCL in m10. GPUAdvanced115 min
  20. 20Finite automata and regular languagesFinite automata model computation with bounded memory. This lesson develops DFAs, NFAs and the subset construction, regular expressions and Kleene's theorem, the pumping lemma and Myhill-Nerode, minimization and the Chomsky hierarchy, then builds a regular-expression engine without backtracking.Core105 min
  21. 21Computability: Turing machines, undecidability and Rice's theoremExplore what can be computed using Turing machines, universal interpretation, diagonalization, reductions, Rice's theorem, and the limits of static analysis and logic.Core115 min
  22. 22Formal proof: Curry-Howard, proof assistants and AIConnect natural deduction and typed λ-calculus to proof assistants, trusted kernels, Lean 4, language-model proof search, autoformalization, and learning-guided solvers.Research110 min

Module capstone

Bounded program verifier with a custom SAT solver

Build an end-to-end verifier for a minimal imperative language with fixed-width integers: a parser, precondition, postcondition, and invariant annotations, verification-condition generation using weakest preconditions, Boolean circuit translation through bit-blasting of addition, comparison, and small multiplication, Tseitin transformation to DIMACS CNF, and the module’s DPLL solver. It returns either a concrete counterexample execution trace or a refutation certificate checked by an independent resolution verifier. Validate it on the module algorithms, including binary search with Bloch’s overflow example, extended Euclid, fast exponentiation, and Dutch national flag partitioning. Compare performance with sympy and locally with PySAT, and discuss properties excluded by Rice’s theorem and how k-induction turns bounded verification into proof.

Check what you already know

  • Use a truth table or equivalences to decide whether a logical consequence is valid and convert a formula to CNF
  • Correctly negate formulas with alternating quantifiers and write the complete postcondition of a sorting algorithm
  • Use diagonalization to prove that no surjection from A onto P(A) exists
  • Identify the incorrect step in a proof and derive a formula in natural deduction
  • Use induction to prove an inequality that requires strengthening the inductive hypothesis
  • Prove that lexicographic order on N × N is well-founded and compute a modular inverse
  • Use structural induction to prove a property of binary trees and compute a least fixed point by iteration
  • Give an inductive invariant and a variant function for the extended Euclidean algorithm
  • Compute the weakest precondition of a program containing assignments and conditionals
  • Count surjections or derangements using inclusion-exclusion
  • Count colorings of a board up to symmetry using Burnside's lemma
  • Solve a linear recurrence with repeated roots and verify it by induction
  • Derive the generating function for the Catalan numbers and its asymptotic behavior
  • Prove that a graph is bipartite if and only if it has no odd cycles
  • Count labeled trees with Prüfer codes and spanning trees with Kirchhoff's theorem
  • Apply Hall's theorem and use Euler's formula to prove that K5 is nonplanar
  • Construct an ROBDD and explain how variable ordering affects its size
  • Encode a combinatorial problem in CNF using the Tseitin transformation and cardinality constraints
  • Refute a set of clauses by resolution and run DPLL by hand
  • Prove that a language is not regular and convert an NFA to a DFA
  • Prove the undecidability of the halting problem and apply Rice's theorem
  • Explain the Curry-Howard correspondence and the role of the trusted kernel in a proof assistant

References

  • Discrete Mathematics and Its ApplicationsKenneth H. Rosen, 2019
  • Mathematics for Computer ScienceEric Lehman, F. Thomson Leighton, Albert R. Meyer, 2017
  • MIT 6.042J Mathematics for Computer Science (Spring 2015)Albert R. Meyer, Adam Chlipala, 2015
  • Concrete Mathematics: A Foundation for Computer ScienceRonald L. Graham, Donald E. Knuth, Oren Patashnik, 1994
  • Logic in Computer Science: Modelling and Reasoning about SystemsMichael Huth, Mark Ryan, 2004
  • Introduction to the Theory of ComputationMichael Sipser, 2012
  • Graph TheoryReinhard Diestel, 2025
  • Handbook of SatisfiabilityArmin Biere, Marijn Heule, Hans van Maaren, Toby Walsh (eds.), 2021
  • The Art of Computer Programming, Volume 4B: Combinatorial Algorithms, Part 2Donald E. Knuth, 2022