# Five ways to get "2 + 2 = 5" past a build

## The question

Can a Lean file that ends in "Build completed successfully" still say something false, such as 2 + 2 = 5, and what catches each way of doing it?

## Why it matters

A build that ends in success is often taken as the whole check. These files show what that message does and does not establish.

## What answering it would help with

Seeing each way side by side lets reviewers choose which checks to run and which things to read.

## What our research shows

**The answer in one line:** yes, in five ways. Four of them are caught by reading something (the axiom report, a warning, the statement, the definitions) and one is caught only by replaying the stored proof through the kernel again.

Each section below shows a short Lean file, the real output Lean printed for it, and the check that catches it. Everything was run, and run again after edits to the comments of six files and to one declaration name, with Lean 4.34.1 (commit 5045d005) on one Windows PC. The output shown is from the second run. The seven files are in the book's demos folder, and each section below prints its file in full. Three tools are used throughout:

- **The build command** runs Lean on the file. If it ends with "Build completed successfully", Lean accepted the file.
- **The axiom report** is a line inside each file. During the build, Lean prints the assumptions that theorem rests on.
- **leanchecker** replays every stored declaration through the kernel again. Its fresh mode also replays everything the file imports.

The commands, run from the lean folder of this book, are:

```
lake build Demo.Honest
lake env leanchecker Demo.Honest
lake env leanchecker --fresh Demo.Honest
```

leanchecker prints nothing when it accepts a file and stops with a message when it rejects one. The output shown below is what Lean printed, without timings.

### An honest file

```lean
-- A true statement with an ordinary proof. Every check should accept this file.
theorem Demo.honest : 2 + 2 = 4 := rfl

#print axioms Demo.honest
```

```
ℹ Built Demo.Honest
info: ../demos/Demo/Honest.lean:4:0: 'Demo.honest' does not depend on any axioms
Build completed successfully (2 jobs).
```

Both leanchecker runs accept. The theorem rests on no axioms, the build passes and both re-checks accept. This is what a clean result looks like.

### An added axiom

```lean
-- Added axiom: an extra axiom. Lean accepts any axiom you declare; that is what axioms are.
-- The build passes. `#print axioms` lists the extra axiom, so the claim is visibly conditional on it.
axiom Demo.bad : 2 + 2 = 5

theorem Demo.two_plus_two_is_five : 2 + 2 = 5 := Demo.bad

#print axioms Demo.two_plus_two_is_five
```

```
ℹ Built Demo.AddedAxiom
info: ../demos/Demo/AddedAxiom.lean:7:0: 'Demo.two_plus_two_is_five' depends on axioms: [Demo.bad]
Build completed successfully (2 jobs).
```

Both leanchecker runs accept.

**What happened.** Lean accepted the file. An axiom is a starting assumption, and Lean lets anyone declare one. The build passes, and leanchecker accepts too, because adding an axiom is not an error: nothing was bypassed.

**How it is caught.** The axiom report says the theorem depends on the added axiom. Anything other than the three standard axioms is a reason to stop and read. The nanoda check described in chapter 4 was set to permit only the three standard axioms, and it refused this file on that rule (output below).

So this "certificate" for 2 + 2 = 5 is valid in exactly one sense: if you grant the added axiom, the theorem follows. The axiom report says so in plain view.

### An unfinished proof (sorry)

```lean
-- Unfinished proof: `sorry` stands in for a missing proof.
-- The build passes with a warning. `#print axioms` lists `sorryAx`.
theorem Demo.two_plus_two_is_five_sorry : 2 + 2 = 5 := by sorry

#print axioms Demo.two_plus_two_is_five_sorry
```

```
⚠ Built Demo.UsesSorry
warning: ../demos/Demo/UsesSorry.lean:3:8: declaration uses `sorry`
info: ../demos/Demo/UsesSorry.lean:5:0: 'Demo.two_plus_two_is_five_sorry' depends on axioms: [sorryAx]
Build completed successfully (2 jobs).
```

Both leanchecker runs accept.

**What happened.** The word sorry tells Lean "pretend this step is proved". The build passes, with a warning, and leanchecker accepts, because Lean stored the placeholder as a special axiom.

**How it is caught.** By the warning, and by the axiom report, which lists the special axiom. A build log that is searched only for the word "error" will miss it, so read warnings and the axiom report, not only error lines. Nanoda refused this too, under the same three-axiom rule.

### A true theorem about a different meaning

Here nothing is wrong with the proof. The kernel, the axiom report and both re-checks are all clean. What is different is what the sentence means. There are three variants.

#### A number system with one number

```lean
-- One-number system: a true theorem about a different meaning.
-- `Fin 1` is a number system with exactly one number, 0. Every number written in it is read modulo 1,
-- so 2 + 2 and 5 both mean 0. The proof is by `decide`, in core Lean, with standard axioms only.
-- Build, axiom report and re-check are all clean. Only reading the statement shows what it says.
theorem Demo.small_number_system : (2 + 2 : Fin 1) = 5 := by decide

#print axioms Demo.small_number_system
#check (5 : Fin 1)
#eval (5 : Fin 1)
#eval (4 : Fin 1)
```

```
ℹ Built Demo.SmallerNumberSystem
info: ../demos/Demo/SmallerNumberSystem.lean:7:0: 'Demo.small_number_system' depends on axioms: [propext]
info: ../demos/Demo/SmallerNumberSystem.lean:8:0: 5 : Fin 1
info: ../demos/Demo/SmallerNumberSystem.lean:9:0: 0
info: ../demos/Demo/SmallerNumberSystem.lean:10:0: 0
Build completed successfully (2 jobs).
```

Both leanchecker runs accept.

**What happened.** The numbers below 1 are only the number 0. Writing 5 in that system means 5 modulo 1, which is 0, and the output confirms it: evaluating 5 prints 0, and so does evaluating 4. Both sides of 2 + 2 = 5 are 0, so the proof by computation succeeds. The axiom report shows one of the three standard axioms.

**How it is caught.** Only by reading the statement: the number-system annotation in it is the whole difference between this and ordinary arithmetic. Neither the kernel nor the axiom report is able to say "this is not the sum you meant". Nanoda accepted the exported proof too, which is correct: the proof is valid.

#### The same symbols, a different plus sign

```lean
-- Different plus sign: the same symbols, a different meaning.
-- A local instance changes what `+` does on natural numbers inside this namespace:
-- it adds and then adds one more. Under that reading `2 + 2 = 5` is true by `rfl`.
-- The build and the axiom report are clean. Only reading the definitions in scope shows the change.
-- `#synth Add Nat` asks Lean which addition it would use here: the local one, not the core one.
namespace Demo

local instance : Add Nat := ⟨fun a b => Nat.succ (Nat.add a b)⟩

theorem redefined_plus : 2 + 2 = 5 := rfl

#print axioms redefined_plus
#eval 2 + 2
#synth Add Nat

end Demo

-- Outside the namespace the core addition is back, and the arithmetic is unchanged.
#synth Add Nat
theorem Demo.ordinary_plus : Nat.add 2 2 = 4 := rfl
```

```
ℹ Built Demo.RedefinedPlus
info: ../demos/Demo/RedefinedPlus.lean:12:0: 'Demo.redefined_plus' does not depend on any axioms
info: ../demos/Demo/RedefinedPlus.lean:13:0: 5
info: ../demos/Demo/RedefinedPlus.lean:14:0: instAddNat_demo
info: ../demos/Demo/RedefinedPlus.lean:19:0: instAddNat
Build completed successfully (2 jobs).
```

Both leanchecker runs accept.

**What happened.** Inside the namespace, a local definition changes what the plus sign means on natural numbers: add, then add one more. Under that meaning 2 + 2 = 5 is true by direct computation, and evaluating 2 + 2 prints 5. The axiom list is empty. Outside the namespace, the core addition is back.

**How it is caught.** By reading the definitions that are in scope. The two lookups of which addition Lean would use show it: inside the namespace Lean would use the local one, and outside it uses the core one. This is why a careful review covers notation, local definitions and options, not only the theorem line.

#### A definition that lets 1 be prime

```lean
-- Faulty definition: a definition that does not mean what its name suggests.
-- `MyPrime` forgets the condition 2 ≤ n, so 1 counts as "prime".
-- Build, axioms and re-check all pass. Only a reader of the definition catches it.
def MyPrime (n : Nat) : Prop := ∀ d : Nat, d ∣ n → d = 1 ∨ d = n

theorem Demo.one_is_prime : MyPrime 1 := by
  intro d h
  exact Or.inl (Nat.dvd_one.mp h)

#print axioms Demo.one_is_prime
```

```
ℹ Built Demo.WrongDefinition
info: ../demos/Demo/WrongDefinition.lean:10:0: 'Demo.one_is_prime' depends on axioms: [propext]
Build completed successfully (2 jobs).
```

Both leanchecker runs accept.

**What happened.** The definition of "prime" leaves out the usual condition that a prime is at least 2, so 1 qualifies. The proof is correct for the definition as written. Build, axiom report (one standard axiom) and both re-checks are clean.

**How it is caught.** Only by someone reading the definition and noticing the missing condition.

### Switching the kernel's check off

```lean
-- Kernel check off: a false "theorem" that skips the kernel check, for teaching only.
-- It adds `False`, "proved" by `True.intro`, while the option `debug.skipKernelTC`
-- tells Lean not to send the declaration to the kernel type checker.
-- `lake build` accepts this file and `#print axioms` reports no axioms.
-- `leanchecker` replays the declaration through the kernel and rejects it.
import Lean
open Lean Elab Command

set_option debug.skipKernelTC true in
run_cmd liftCoreM <| addDecl (Declaration.thmDecl
  { name := `Demo.unchecked, levelParams := [], type := mkConst ``False, value := mkConst ``True.intro })

#print axioms Demo.unchecked

-- Anything follows from `False`, so this "proves" a plainly wrong equation.
theorem Demo.wrong : 2 + 2 = 5 := Demo.unchecked.elim

#print axioms Demo.wrong
```

```
ℹ Built Demo.SkipKernelTC
info: ../demos/Demo/SkipKernelTC.lean:13:0: 'Demo.unchecked' does not depend on any axioms
info: ../demos/Demo/SkipKernelTC.lean:18:0: 'Demo.wrong' does not depend on any axioms
Build completed successfully (2 jobs).
```

```
$ lake env leanchecker Demo.SkipKernelTC
leanchecker found a problem in Demo.SkipKernelTC
uncaught exception: while replaying declaration 'Demo.unchecked':
(kernel) declaration type mismatch, 'Demo.unchecked' has type
  True
but it is expected to have type
  False
```

The fresh run stops with the same message, without its opening line.

**What happened.** The kernel-skip option tells Lean to store a declaration without sending it to the kernel. The file uses it to store a "theorem" whose statement is False and whose proof is a proof of True. Anything follows from False, so the next line proves 2 + 2 = 5. The build passes, and the axiom report says both theorems "do not depend on any axioms".

**How it is caught.** leanchecker replays the stored declaration through the kernel and stops with a type mismatch: it has type True but should have type False. Both the plain run and the fresh run reject the file. The kernel was not fooled; it was never asked at build time, and the re-check asked it.

With the option left out, the kernel refuses the same declaration at build time, as it should. The option can also be set in the build file of a project, in which case no Lean file mentions it, so a search of the Lean files alone finds nothing; search the build files too. Lean's reference manual describes use of this option as dishonest, not as a mistake. An ordinary false proof is not let through by this option: Lean's front end still checks terms as they are written, and the file needs a direct call that adds a declaration from meta-code (Lean code that writes Lean code) to get the false declaration stored.

### What a second kernel said

Chapter 4 describes the setup. For each file, the theorem was exported from the Lean 4.35.0 build of the same file and checked with nanoda, a kernel written separately in Rust, set to permit only the three standard axioms.

```
nanoda_bin 0.4.19
Honest: export Demo.honest, check with nanoda
Checked 38 declarations with no errors
AddedAxiom: export Demo.two_plus_two_is_five, check with nanoda
Error: export file declares unpermitted axiom "Demo.bad"
UsesSorry: export Demo.two_plus_two_is_five_sorry, check with nanoda
Error: export file declares unpermitted axiom "sorryAx"
SmallerNumberSystem: export Demo.small_number_system, check with nanoda
Checked 294 declarations with no errors
RedefinedPlus: export Demo.redefined_plus, check with nanoda
Checked 38 declarations with no errors
WrongDefinition: export Demo.one_is_prime, check with nanoda
Checked 198 declarations with no errors
SkipKernelTC: export Demo.wrong, check with nanoda
thread 'main' panicked at src\tc.rs:955:71:
assertion failed: self.def_eq(u, v)
```

- **The honest file and the three different-meaning files:** accepted. The proofs are valid, so a second kernel agrees. It cannot say the statements mean something else.
- **The added axiom and the unfinished proof:** refused because the export contains an axiom outside the permitted three. That is the axiom report doing its job in a second tool.
- **Kernel check switched off:** nanoda did not accept. It stopped with an internal assertion failure about two terms being equal (exit code 101) and printed no success line. This is a program stopping, not a polished verdict; the book reads it as "not accepted" and no more. It is consistent with the type mismatch leanchecker reports.

### All together

| Demo | Build | Axiom report | leanchecker, fresh | nanoda | Caught by |
|---|---|---|---|---|---|
| Honest file | passes | none | accepts | accepts | nothing needed |
| Added axiom | passes | the added axiom | accepts | refuses (axiom rule) | the axiom report |
| Unfinished proof | passes, warning | the special placeholder axiom | accepts | refuses (axiom rule) | warning and axiom report |
| One-number system | passes | one standard axiom | accepts | accepts | reading the statement |
| Different plus sign | passes | none | accepts | accepts | reading the definitions |
| Faulty definition | passes | one standard axiom | accepts | accepts | reading the definition |
| Kernel check off | passes | none | **rejects** | does not accept | the re-check through the kernel |

Only the last row is caught by an automatic re-check of the proof. Three rows are caught only by a person.

### Yesterday, today, tomorrow

**Yesterday.** The Lean reference manual already lists axioms, sorry and the kernel-skip option, and says what each check protects against. Three demonstrations in this chapter, the honest file, the kernel-skip file and the faulty-definition file, come from an earlier draft by Sonny, run earlier; all seven were run again for this book, and once more after small edits.

**Today.** Sonny re-ran all seven files, and again after edits to their comments and one declaration name, and pasted what Lean printed. Four different checks catch the five ways: the axiom report, the build warning, a person reading, and a re-check through the kernel.

**Tomorrow.** Other ways to mislead can be added in the same form: a short file, the real output, and the check that catches it. A run with lean4lean, which could not be used here, would add a second separately written kernel.

## Check it yourself

Every command and its expected output is in [the check guide](../VERIFY.md), one recipe per demonstration. The seven files are in the demos folder, and their fingerprints are in the certificates folder.

## Where to go next

- If the kernel itself has a bug, which of these checks still help? See [Kernel bugs, and why a second checker helps](04-kernel-bugs-and-second-checkers.md).
- What does a "Lean-verified" label leave unsaid even when every check passes? See [What "Lean-verified" does not mean](02-what-it-does-not-mean.md).
