Skip to content
The Lumenary

Each worksheet prints cleanly on A4 or Letter. Answer keys are on a separate page.

The Lumenary · Early undergraduate

Formalising mathematics in Lean and Mathlib

Name: ______________________

Date: ______________________

You will learn to

  • Formalise definitions and proofs about sets, functions and quantifiers in Lean, such as the facts that a composite of injections is injective and that images preserve unions
  • Use structures, type classes and Mathlib's algebraic hierarchy to state and prove results about every monoid or group at once
  • Search Mathlib for existing results, and explain the trade-off between citing a library lemma and proving a result from scratch
  • Recognise the conventions and hidden hypotheses that formalisation exposes, such as x/0=0x/0 = 0 and truncated subtraction on N\N
  • Explain what a machine check guarantees — and what it does not — using the kernel, #print axioms, and the need for definitions to match standard usage
  1. 1.

    With f : α → β and g : β → γ, which Lean statement says that a composite of injective functions is injective?

    • A.Injective g → Injective f → Injective (g ∘ f)
    • B.Injective (g ∘ f) → Injective g
    • C.∃ f g, Injective (g ∘ f)
    • D.Injective g ∧ Injective f
  2. 2.

    To prove that g∘fg \circ f is injective, we assume g(f(x))=g(f(y))g(f(x)) = g(f(y)) and must show x=yx = y. Which fact do we use first?

    • A.Injectivity of gg, to get f(x)=f(y)f(x) = f(y)
    • B.Injectivity of ff, to get x=yx = y directly
    • C.Surjectivity of gg
    • D.Associativity of composition
  3. 3.

    Which function f:N→Nf : \N \to \N gives sets S,TS, T with f(S∩T)≠f(S)∩f(T)f(S \cap T) \ne f(S) \cap f(T)?

    • A.f(n)=0f(n) = 0 for all nn
    • B.f(n)=n+1f(n) = n + 1
    • C.f(n)=2nf(n) = 2n
    • D.f(n)=nf(n) = n
  4. 4.

    Which of these statements about natural numbers are true? (Choose all that apply.)

    • A.∀n ∃m  n<m\forall n\ \exists m\ \ n < m
    • B.∃m ∀n  n<m\exists m\ \forall n\ \ n < m
    • C.∃m ∀n  m≤n\exists m\ \forall n\ \ m \le n
    • D.∀n ∃m  m<n\forall n\ \exists m\ \ m < n
  5. 5.

    In Lean, with natural numbers, what is the value of (5 : ℕ) - 8 + 8?

  6. 6.

    In Mathlib, (7 : ℝ) / 0 = 0 is a theorem (div_zero). What follows?

    • A.Nothing false: laws such as a / b * b = a require the hypothesis b ≠ 0, so the convention cannot be used to cancel a zero.
    • B.7 = 0, by multiplying both sides by 0.
    • C.Lean's logic is inconsistent.
    • D.Real analysis defines division by zero.
  7. 7.

    #print axioms limit_unique reports [propext, Classical.choice, Quot.sound]. What does this tell you?

    • A.The proof is complete (no sorry) and uses only Lean's three standard axioms, including choice.
    • B.The proof is incomplete, because it depends on axioms.
    • C.The proof is constructive.
    • D.limit_unique was itself assumed as an axiom.
  8. 8.

    In the proof that a group in which every xx satisfies x2=1x^2 = 1 is commutative, we write ab=(ab)−1=b−1a−1=baab = (ab)^{-1} = b^{-1}a^{-1} = ba. Which group law justifies the middle equality?

    • A.The inverse of a product is the product of the inverses in reverse order (Mathlib's mul_inv_rev).
    • B.Commutativity of multiplication.
    • C.x−1=xx^{-1} = x for all xx.
    • D.Uniqueness of the identity element.
  9. 9.

    Write find_counterexample(a, b) that searches all functions ff from {0,…,a−1}\{0, \dots, a-1\} to {0,…,b−1}\{0, \dots, b-1\} (as tuples of values) and all pairs of subsets S,TS, T of the domain, and returns the first (f, S, T) with f(S∩T)≠f(S)∩f(T)f(S \cap T) \ne f(S) \cap f(T) (with S, T as Python sets), or None if there is none. Use itertools.

    Computational — Practice

Code: Apache-2.0 · Content: CC BY-SA 4.0