Stage 06 · Step 27 of 50

Numbers, checked.

Needs Mathlib12 minutesLean 4.36.0

01The idea

A number written as a fraction still has an exact value. Lean can check concrete calculations without decimal rounding.

Tacto · Your guide for this idea
Tacto pointing

norm_num proves many such numerical facts.

02In maths

Three quarters plus one quarter equals one, in the rational numbers.

Picture it

Three quarters plus one quarter is exactly oneA bar representing one whole is cut into four equal quarters. Three are teal and are bracketed as 3 / 4; the last is gold and is bracketed as 1 / 4. Together they fill the bar, so the sum equals 1. Below, the goal card 3 / 4 + 1 / 4 = 1 is closed by norm_num, leaving no goals. A note asks why we write (3 : ℚ): in whole numbers, Nat, 3 / 4 would round down to 0.one whole, cut into quarters1/41/41/41/4= 13 / 41 / 4THE GOAL, IN ℚ⊢ 3 / 4 + 1 / 4 = 1norm_numno goalsWhy (3 : ℚ)? In whole numbers (Nat), 3 / 4 would round down to 0.

Swipe sideways to see the whole picture.

Three quarters and one quarter fill the whole bar, so the sum is exactly 1. Writing (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.

E27.leanTry it live (opens official Lean editor)
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.

After line 5
⊢ 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

Captured from Lean 4.36.0
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Prove the stated integer multiplication.

  2. A little stretch

    Prove the fraction addition over the rational numbers.

Exercises/E27.leanTry it live (opens official Lean editor)
module

import Mathlib.Tactic.NormNum

example : (7 : ℤ) * 8 = 56 := by
  sorry

example : (2 : ℚ) / 3 + 1 / 6 = 5 / 6 := by
  sorry

08A quick check

1. What does ℚ denote?

Read the answer and explanation

Rational numbers. Rational numbers include fractions of integers with nonzero denominators. Type ℚ with \Q.

2. Does rational arithmetic here use approximate floating-point values?

Read the answer and explanation

No. The rational-number type represents these values exactly.

One more idea in your toolkit.

Take your time. Progress is yours to mark.