Stage 06 · Step 28 of 50
Follow the inequalities.
01The idea
Two short routes can make one longer route. Inequalities can chain in the same way.
linarith combines linear facts to establish the target inequality.
02In maths
For rational x and y, if x ≤ y and y ≤ 7, then x ≤ 7.
Picture it
Swipe sideways to see the whole picture.
x is at or before y, and y is at or before 7, then x is at or before 7: two short hops make one long route. Behind the scenes, linarith adds up the facts you have until the goal drops out. Here the sum x + y ≤ y + 7 becomes x ≤ 7 once the y on each side cancels.03In Lean
This code comes directly from the file checked by Lean.
module
import Mathlib.Tactic.Linarith
example (x y : ℚ) (h₁ : x ≤ y) (h₂ : y ≤ 7) : x ≤ 7 := by
linarith
An inequality compares values using an order relation. The symbol ≤ means “less than or equal”; type it with \le.
The tactic linarith searches for a suitable linear consequence of the arithmetic hypotheses.
Here the variables are rational numbers. Unlike omega, linarith also supports common ordered-field settings such as the reals.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
x y : ℚ h₁ : x ≤ y h₂ : y ≤ 7 ⊢ x ≤ 7
After line 5: example (x y : ℚ) (h₁ : x ≤ y) (h₂ : y ≤ 7) : x ≤ 7 := by
x y : ℚ h₁ : x ≤ y h₂ : y ≤ 7 ⊢ x ≤ 7
After line 6: linarith
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.Linarith
example (x : ℚ) (h : x ≤ 3) : x < 3 := by
linarith
linarith failed to find a contradiction x : ℚ h : x ≤ 3 a✝ : 3 ≤ x ⊢ False failed
The non-strict assumption includes the boundary value three.
The fix: Keep a non-strict conclusion, or supply a genuinely stronger hypothesis.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Derive the bound on x from x plus three being at most eight.
Show a hint
Subtracting three gives the expected bound.
One more hint
linarith can derive the needed linear consequence.
- A little stretch
Solve for x using the two supplied linear equalities.
Show a hint
Use the value of y in the first equation.
One more hint
Give both hypotheses to linarith through the context.
module
import Mathlib.Tactic.Linarith
example (x : ℚ) (h : x + 3 ≤ 8) : x ≤ 5 := by
sorry
example (x y : ℚ) (h₁ : 2*x + y = 8) (h₂ : y = 2) : x = 3 := 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.Linarith
example (x : ℚ) (h : x + 3 ≤ 8) : x ≤ 5 := by
linarith
example (x y : ℚ) (h₁ : 2*x + y = 8) (h₂ : y = 2) : x = 3 := by
linarith
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.