Stage 06 · Step 27 of 50
Numbers, checked.
01The idea
A number written as a fraction still has an exact value. Lean can check concrete calculations without decimal rounding.
norm_num proves many such numerical facts.
02In maths
Three quarters plus one quarter equals one, in the rational numbers.
Picture it
Swipe sideways to see the whole picture.
(3 : ℚ) tells Lean to use rational numbers, which are exact fractions: no decimals, no rounding. norm_num does the fraction arithmetic and proves the equation.03In Lean
This code comes directly from the file checked by Lean.
module
import Mathlib.Tactic.NormNum
example : (3 : ℚ) / 4 + 1 / 4 = 1 := by
norm_num
The rational numbers include exact fractions. The symbol ℚ denotes their type. Type it with \Q.
The symbol ℤ denotes the integers; type it with \Z. A type annotation tells Lean which arithmetic we mean.
The tactic norm_num proves many concrete numerical equalities and inequalities. Its capabilities depend on the imported extensions.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ 3 / 4 + 1 / 4 = 1
After line 5: example : (3 : ℚ) / 4 + 1 / 4 = 1 := by
⊢ 3 / 4 + 1 / 4 = 1
After line 6: norm_num
no goals
05Lean says
no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
module
import Mathlib.Tactic.NormNum
example : (3 : ℚ) / 4 + 1 / 4 = 2 := by
norm_num
unsolved goals ⊢ False
The fractions add to one, not two.
The fix: Correct the numerical statement before using norm_num.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Prove the stated integer multiplication.
Show a hint
The type is the integers.
One more hint
norm_num checks the numerical equality.
- A little stretch
Prove the fraction addition over the rational numbers.
Show a hint
The denominators describe exact fractions.
One more hint
Use norm_num rather than a decimal approximation.
module
import Mathlib.Tactic.NormNum
example : (7 : ℤ) * 8 = 56 := by
sorry
example : (2 : ℚ) / 3 + 1 / 6 = 5 / 6 := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
module
import Mathlib.Tactic.NormNum
example : (7 : ℤ) * 8 = 56 := by
norm_num
example : (2 : ℚ) / 3 + 1 / 6 = 5 / 6 := by
norm_num
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.