Example

Audit a Lean file that compiles

A file with an axiom of its own and a sorry compiles cleanly; the audit questions find both, and refute the axiom.

A file that compiles has shown less than it seems. The chapter’s audit asks: what does it state, what does each declaration rest on, is it bound to the claimed statement, and does the statement mean the claim? This core-Lean file is the kind of thing that might arrive with a paper: it compiles, with an axiom of its own and a gap.

Run it

Save this as audit.lean and run lean audit.lean with Lean 4.35.0 (core Lean only, no Mathlib), or paste it into the Lean 4 web editor at live.lean-lang.org .

-- Auditing someone else's proof: the questions to ask of a file that compiles (core Lean 4).
-- Imagine this arrived attached to a paper.

axiom helpful_fact : ∀ n : Nat, n * n ≥ n + 1                  -- 4. an axiom of its own (false at n = 1)

theorem lemma_ok (n : Nat) : n ≤ n * n + n := by omega
theorem lemma_gap (n : Nat) : n * n ≥ n := sorry                  -- a gap
theorem main_result (n : Nat) (h : 1 < n) : n < n * n := by
  have := helpful_fact n
  omega

-- 3. What does it state? Read the statements, not the names.
#check @main_result
-- 4. What does each declaration rest on?
#print axioms lemma_ok
#print axioms lemma_gap
#print axioms main_result
-- 5. Is it bound to the claimed statement, "every n > 1 is less than its square"?
example : ∀ n : Nat, 1 < n → n < n * n := main_result
-- The axiom is false: the audit can refute it independently.
example : ¬ (∀ n : Nat, n * n ≥ n + 1) := fun h => absurd (h 1) (by decide)

Expected outcome

audit.lean:7:8: warning: declaration uses `sorry`
audit.lean:8:31: warning: Variable name `h` is not explicitly referenced.

Hint: The binding can be removed (if unused) or named `_` (if used implicitly). Alternatively, prefix the name with `_` to silence this warning:
  [apply] _h

Note: This linter can be disabled with `set_option linter.unusedVariables false`
main_result : ∀ (n : Nat), 1 < n → n < n * n
'lemma_ok' depends on axioms: [propext, Quot.sound]
'lemma_gap' depends on axioms: [sorryAx]
'main_result' depends on axioms: [helpful_fact, propext, Quot.sound]

main_result states exactly the claim and binds to it, but #print axioms shows it rests on helpful_fact, an axiom the file declares. Lean’s own warning shows the hypothesis h is not even used: the result follows from the axiom alone. And the axiom is false at n = 1, which the last line proves. So the file proves nothing about the claim. lemma_gap rests on sorryAx.

Mechanism and limitations

Documented: Chapter 26 of the book sets out the mathematics; this program is a self-contained demonstration of it, not one of the laboratory’s recorded investigations.

Observed: the output above, produced by running the program exactly as shown.

Not shown:

  • A constructed example; Part I, chapter 5 applies the same audit to a real published artifact.
  • Finding the axiom is mechanical; deciding that it is false, or acceptable, is not.

Related worked example: Chapter 6 .

Challenge this result

Copy this into the AI assistant of your choice, or work through it yourself. Check any finding against the recorded evidence.

Apply the chapter's audit checklist to this file. For each question, give the
evidence from Lean's output. Then rewrite `main_result` without the axiom, prove
it, and say what `#print axioms` should report afterwards.

Chapter: https://programmer.ie/books/math/26-chapter/
Example: https://programmer.ie/examples/math/26-chapter/
Program: https://github.com/ernanhughes/math/blob/main/notebooks/math/programs/26-auditing.lean
Distinguish what the record shows from what you infer. If you cannot open a link, ask me for the material; do not invent it.

Canonical source and the program .

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.