Task
Let's start with a very simple task. Imagine we're given the following fact.
Our task is to prove that
Here,
Maths
It seems trivially obvious that if
The challenge we'll often face writing proofs in Lean is getting inside intuitively easy tasks to think about them in a more structured way.
How can we justify
Let's now try to write down these thoughts in a structured way.
That wasn't too difficult.
Code
Let's now look at a Lean program that proves
-- 01 - First Proof
import Mathlib.Tactic
example {a : ℕ} (h1: a = 4) : a > 1 := by
calc
a = 4 := by rw [h1]
_ > 1 := by norm_num
This is our first look at Lean code, so we'll only make some initial observations, and allow ourselves to become familiar with Lean code gradually over the coming chapters.
The proof starts on the line beginning with example. This rather long line states the theorem we want to prove.
- The {a : ℕ} tells Lean the variable a is a natural number.
- Next we have (h1 : a = 4) which is the given fact. It's given a label h1 so we can refer to it later by name.
- After that we have the statement we want to prove, a > 1.
- Finally there is a := by which signals to Lean that we're about to prove that statement.
- We state that a = 4, and justify it by referring to the given fact, previously labelled h1.
- We complete the proof by saying this is > 1, and justify it by the ordering of natural numbers. We'll talk more about norm_num below.
Tactics
That last line of the Lean proof justified
The natural numbers are described by the Peano axioms. On top of these axioms, we can define addition, then the “greater than”
We did not go that deep in our maths proof!
For a large body of fundamental results, there's no need to prove them every time we use them. Maths would be very tedious if we had to prove something like
The same idea applies to Lean proofs.
Many of those fundamental results and common methods have been written in Lean and packaged up as tactics, ready for us to use. So norm_num is a tactic that includes knowledge about the order created by the “greater than” relation on natural numbers. It also includes knowledge about how to do arithmetic like
Exercise
The Lean program above proves
The norm_num tactic understands “less than”, as well as “greater than”.