Skip to content
The Lumenary
Grades 6–8Ages 12–14 65 min

Linear equations and inequalities

Do the same to both sides — but only moves you can undo. Why that rule works, why multiplying by zero breaks it, and why an inequality flips when you multiply by a negative number.

Formally verified · 19 LeanComputationally tested · 1 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review

Your guides: Chloe, Margaret, Gideon

MotivationH

Two tanks

At a school in Lilongwe, two rainwater tanks stand side by side. In the morning the first holds 500500 litres and is being used to water the vegetable garden, losing 2020 litres a minute. The second holds 100100 litres and is being filled from the roof gutters at 3030 litres a minute. When will the two tanks hold the same amount?

After tt minutes the first tank holds 500−20t500 - 20t litres and the second 100+30t100 + 30t litres. We want the value of tt that makes

500−20t=100+30t.500 - 20t = 100 + 30t.

We could guess: after 55 minutes the tanks hold 400400 and 250250 litres; after 1010 minutes, 300300 and 400400. So the answer lies somewhere between. Guessing works here, but it is slow, it is hopeless when the answer is 3711\tfrac{37}{11}, and it can never tell us that there is no answer. This lesson develops a method that always works — and proves why it works.

IntuitionH

Keeping the balance

An equation is like a balance in equilibrium: the two sides weigh the same. If we take the same amount off both pans, or double both pans, the balance stays level. Try it: each box weighs xx units, and the goal is to get one box alone on one side.

x on both sides

Get one x alone. Every legal move keeps the scale level.

xxx1x111111111
  • x (unknown weight)
  • 1 (unit weight)

3x + 1 = x + 9

Do the same thing to both sides. Try to get x on its own.

The scale is still level: both sides changed by the same amount.

Your steps

  1. 3x + 1 = x + 9
Make your own equation

Left side

Number of x's3
Number of 1s1

Right side

Number of x's1
Number of 1s9
DefinitionsH

Equations, solutions and equivalence

Definition— equation and solution

An equation in a variable xx is a statement that two algebraic expressions are equal, such as 3x+1=x+93x + 1 = x + 9. A solution is a value of xx that makes the statement true. The solution set is the set of all solutions. To solve an equation means to find its solution set — all of the solutions, and nothing else.

Definition— equivalent equations

Two equations are equivalent if they have exactly the same solutions.

Definition— linear equation

A linear equation in xx is one that can be written as ax+b=cx+dax + b = cx + d for numbers a,b,c,da, b, c, d: the variable appears only to the first power, multiplied by numbers.

So 5−2x=115 - 2x = 11 and x3+12=x−14\tfrac{x}{3} + \tfrac{1}{2} = \tfrac{x - 1}{4} are linear; x2=2xx^2 = 2x and 1x=3\tfrac{1}{x} = 3 are not.

Definition— inequality

An inequality compares two expressions with <<, ≤\leq, >> or ≥\geq. Its solutions are the values of the variable that make it true. For example, the solutions of x+2>5x + 2 > 5 are all the numbers greater than 33 — infinitely many.

Throughout, the variable can be any rational number (see rational numbers) unless we say otherwise. This matters: 2x=12x = 1 has the solution 12\tfrac{1}{2} among the rational numbers but no solution among the integers.

ProofH

Why the balance method works

Theorem— moves that give equivalent equations

For all numbers pp, qq and cc:

  1. p=qp = q if and only if p+c=q+cp + c = q + c;
  2. if c≠0c \neq 0, then p=qp = q if and only if cp=cqcp = cq.

Consequently, adding the same number to both sides of an equation, or multiplying both sides by the same non-zero number, gives an equivalent equation.

Proof

  1. If p=qp = q, then p+cp + c and q+cq + c are the same number, so they are equal. Conversely, if p+c=q+cp + c = q + c, add −c-c to both sides: p=(p+c)+(−c)=(q+c)+(−c)=qp = (p + c) + (-c) = (q + c) + (-c) = q.
  2. If p=qp = q, then cp=cqcp = cq. Conversely, if cp=cqcp = cq and c≠0c \neq 0, multiply both sides by 1c\tfrac{1}{c}, which exists because c≠0c \neq 0: p=1c(cp)=1c(cq)=qp = \tfrac{1}{c}(cp) = \tfrac{1}{c}(cq) = q.

For an equation in xx, apply this to each value of xx separately, with pp and qq the values of the two sides: xx makes the old equation true exactly when it makes the new one true.

∎

Subtracting cc is adding −c-c, and dividing by c≠0c \neq 0 is multiplying by 1c\tfrac{1}{c}, so these moves are covered too. We may also add an expression such as −x-x to both sides: for each value of xx, that just adds a number.

The proof shows exactly where c≠0c \neq 0 is used: to undo the multiplication. Multiplying by 00 cannot be undone. The equation x=3x = 3 has one solution, but 0⋅x=0⋅30 \cdot x = 0 \cdot 3 is true for every xx — multiplying by zero has thrown the information away.

So solving an equation is building a chain of equivalent equations, ending with one whose solutions we can read off. Because every link is an "if and only if", the last equation has exactly the same solutions as the first. Checking the answer by substitution is still a good habit: it catches arithmetic slips.

Theorem— the three outcomes for ax = b

For numbers aa and bb, the equation ax=bax = b has

  • exactly one solution, x=bax = \tfrac{b}{a}, if a≠0a \neq 0;
  • no solution, if a=0a = 0 and b≠0b \neq 0;
  • every number as a solution, if a=0a = 0 and b=0b = 0.

Proof

If a≠0a \neq 0, multiplying both sides by 1a\tfrac{1}{a} gives the equivalent equation x=bax = \tfrac{b}{a}, whose only solution is ba\tfrac{b}{a}. If a=0a = 0, the left side 0⋅x0 \cdot x is 00 for every xx, so the equation says 0=b0 = b: never true if b≠0b \neq 0, always true if b=0b = 0.

∎

Every linear equation can be brought into this form. Subtracting cx+bcx + b from both sides of ax+b=cx+dax + b = cx + d gives the equivalent equation

(a−c) x=d−b.(a - c)\,x = d - b.

Theorem— no linear equation has exactly two solutions

If two different numbers x1≠x2x_1 \neq x_2 both solve ax+b=cx+dax + b = cx + d, then every number solves it.

Proof

Both numbers solve the standard form: (a−c)x1=d−b(a - c)x_1 = d - b and (a−c)x2=d−b(a - c)x_2 = d - b. Subtracting, (a−c)(x1−x2)=0(a - c)(x_1 - x_2) = 0. Since x1−x2≠0x_1 - x_2 \neq 0, we can divide by it, so a−c=0a - c = 0, and then d−b=(a−c)x1=0d - b = (a - c)x_1 = 0. So the standard form reads 0⋅x=00 \cdot x = 0, which every number satisfies.

∎

A linear equation therefore has exactly one solution, no solution, or infinitely many — nothing in between.

Worked examplesH

Worked examples

Example— The variable on both sides

Solve 3x+1=x+93x + 1 = x + 9.

3x+1=x+92x+1=9subtract x from both sides2x=8subtract 1x=4multiply by 12\begin{aligned} 3x + 1 &= x + 9 &&\\ 2x + 1 &= 9 &&\text{subtract } x \text{ from both sides}\\ 2x &= 8 &&\text{subtract } 1\\ x &= 4 &&\text{multiply by } \tfrac{1}{2} \end{aligned}

Check: 3⋅4+1=133 \cdot 4 + 1 = 13 and 4+9=134 + 9 = 13. ✓

Example— The two tanks

500−20t=100+30t500 - 20t = 100 + 30t. Add 20t20t to both sides: 500=100+50t500 = 100 + 50t. Subtract 100100: 400=50t400 = 50t. Divide by 5050: t=8t = 8. After 88 minutes both tanks hold 340340 litres (500−160=100+240500 - 160 = 100 + 240).

Example— Negative coefficients and brackets

  • 5−2x=115 - 2x = 11. Subtract 55: −2x=6-2x = 6. Divide by −2-2: x=−3x = -3. Check: 5−2(−3)=5+6=115 - 2(-3) = 5 + 6 = 11. ✓
  • 2(x−3)−(x−5)=72(x - 3) - (x - 5) = 7. Expand carefully — the minus sign in front of the second bracket multiplies both terms: 2x−6−x+5=72x - 6 - x + 5 = 7, so x−1=7x - 1 = 7 and x=8x = 8. Check: 2⋅5−3=72 \cdot 5 - 3 = 7. ✓

Example— Fractions

Solve x3+12=x−14\dfrac{x}{3} + \dfrac{1}{2} = \dfrac{x - 1}{4}.

Multiply both sides by 1212, the least common multiple of 33, 22 and 44 — and multiply every term:

12⋅x3+12⋅12=12⋅x−14⟹4x+6=3x−3⟹x=−9.12 \cdot \frac{x}{3} + 12 \cdot \frac{1}{2} = 12 \cdot \frac{x - 1}{4} \quad\Longrightarrow\quad 4x + 6 = 3x - 3 \quad\Longrightarrow\quad x = -9.

Check: −93+12=−52\tfrac{-9}{3} + \tfrac{1}{2} = -\tfrac{5}{2} and −104=−52\tfrac{-10}{4} = -\tfrac{5}{2}. ✓

Example— No solution, and every number a solution

  • 2(x+3)=2x+52(x + 3) = 2x + 5 expands to 2x+6=2x+52x + 6 = 2x + 5. Subtracting 2x2x leaves 6=56 = 5, which is false whatever xx is. No solution.
  • 3(x−2)+x=4x−63(x - 2) + x = 4x - 6 expands to 4x−6=4x−64x - 6 = 4x - 6. Subtracting 4x4x leaves −6=−6-6 = -6, true whatever xx is. Every number is a solution: the equation is an identity.

When the variable disappears, do not panic — read the statement that remains.

Example— Modelling: three consecutive numbers

Three consecutive integers add up to 9696. What are they? Call the smallest nn; the others are n+1n + 1 and n+2n + 2. Then n+(n+1)+(n+2)=96n + (n + 1) + (n + 2) = 96, so 3n+3=963n + 3 = 96, 3n=933n = 93 and n=31n = 31. The numbers are 31,32,3331, 32, 33 — and indeed they add to 9696. Choosing what the variable stands for is the most important step in modelling.

ProofH

Inequalities, and why they flip

Inequalities are solved with the same moves — with one twist. We use the basic facts about order: p<qp < q means that q−pq - p is positive; the sum and the product of two positive numbers are positive; and the product of a positive and a negative number is negative.

Theorem— moves for inequalities

For all numbers pp, qq and cc:

  1. p<qp < q if and only if p+c<q+cp + c < q + c;
  2. if c>0c > 0, then p<qp < q if and only if cp<cqcp < cq;
  3. if c<0c < 0, then p<qp < q if and only if cp>cqcp > cq — the inequality reverses.

The same holds with ≤\leq in place of <<.

Proof

  1. (q+c)−(p+c)=q−p(q + c) - (p + c) = q - p, so one difference is positive exactly when the other is.
  2. If c>0c > 0 and q−p>0q - p > 0, then cq−cp=c(q−p)cq - cp = c(q - p) is a product of positive numbers, so it is positive: cp<cqcp < cq.
  3. If c<0c < 0 and q−p>0q - p > 0, then −c>0-c > 0, so (−c)(q−p)>0(-c)(q - p) > 0. But (−c)(q−p)=cp−cq(-c)(q - p) = cp - cq. So cp−cq>0cp - cq > 0, which says cq<cpcq < cp.

Each move can be undone (by adding −c-c, or multiplying by 1c\tfrac{1}{c}, which has the same sign as cc), which gives the "if and only if".

∎

Here is the picture behind part 3. Multiplying by −1-1 reflects the number line in 00: 2<52 < 5, but −2>−5-2 > -5, because the reflection swaps left and right. Multiplying by any negative number is a stretch followed by this reflection.

Example— Solving an inequality

Solve 7−3x≤197 - 3x \leq 19.

7−3x≤19−3x≤12subtract 7x≥−4divide by −3, which reverses the inequality\begin{aligned} 7 - 3x &\leq 19 &&\\ -3x &\leq 12 &&\text{subtract } 7\\ x &\geq -4 &&\text{divide by } -3 \text{, which reverses the inequality} \end{aligned}

Check with test values: x=0x = 0 gives 7≤197 \leq 19, true; x=−4x = -4 gives 19≤1919 \leq 19, true; x=−5x = -5 gives 22≤1922 \leq 19, false. ✓

−8−6−4−202
The solution set of 7 − 3x ≤ 19 is x ≥ −4: the filled dot shows that −4 itself is included, and the arrow shows that every larger number is a solution too.

Example— Modelling: how many notebooks?

Mariam, a student in Fez, has 200200 dirhams. She needs a book costing 4545 dirhams and wants as many notebooks as possible at 1212 dirhams each. With nn notebooks she needs 45+12n≤20045 + 12n \leq 200, so 12n≤15512n \leq 155 and n≤12.91…n \leq 12.91\ldots But nn counts notebooks, so it is a whole number: the solutions are n=0,1,…,12n = 0, 1, \ldots, 12, and she can buy at most 1212. (Thirteen would cost 45+156=20145 + 156 = 201 dirhams — one too many!)

Formal mathematicsF

Equivalent equations in Lean

In Lean we work with the rational numbers Rat. "Two equations are equivalent" becomes a statement with ↔ ("if and only if") that holds for every x. First the two basic moves; each proof undoes the move, just as in the human proof:

add_both_sidesLean 4Proved here from basic factsFormally verified
/-- Adding the same number `c` to both sides gives an equivalent equation:
`p = q ↔ p + c = q + c`. Forwards, equal numbers plus `c` are equal. Backwards, the move can
be **undone**: subtract `c` again, `p = (p + c) − c = (q + c) − c = q`. -/
theorem add_both_sides (p q c : Rat) : p = q ↔ p + c = q + c := by
  constructor
  · intro h
    rw [h]
  · intro h
    calc p = p + c - c := Rat.add_sub_cancel.symm
      _ = q + c - c := by rw [h]
      _ = q := Rat.add_sub_cancel
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
mul_both_sidesLean 4Proved here from basic factsFormally verified
/-- Multiplying both sides by a **non-zero** number `c` gives an equivalent equation:
`p = q ↔ c·p = c·q`. Backwards, the move is undone by dividing by `c`, which is only possible
because `c ≠ 0` (`Rat.mul_div_cancel`). -/
theorem mul_both_sides (p q c : Rat) (hc : c ≠ 0) : p = q ↔ c * p = c * q := by
  constructor
  · intro h
    rw [h]
  · intro h
    calc p = c * p / c := by rw [Rat.mul_comm, Rat.mul_div_cancel hc]
      _ = c * q / c := by rw [h]
      _ = q := by rw [Rat.mul_comm, Rat.mul_div_cancel hc]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor

Without the hypothesis c ≠ 0 the second move fails, and Lean can prove that it fails:

mul_zero_not_reversibleLean 4Proved here from basic factsFormally verified
/-- Why `c ≠ 0` is needed: multiplying both sides by `0` cannot be undone. `0 · 0 = 0 · 1` is
true, but `0 = 1` is false, so "`0·p = 0·q` implies `p = q`" fails. -/
theorem mul_zero_not_reversible : ¬ ∀ p q : Rat, 0 * p = 0 * q → p = q := by
  intro h
  have h01 : (0 : Rat) = 1 := h 0 1 (by rw [Rat.zero_mul, Rat.zero_mul])
  exact absurd h01 (by decide)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor

Multiplying or dividing by an expression that can be zero is just as dangerous: it can add a solution, or lose one.

extra_solutionLean 4Proved here from basic factsFormally verified
/-- Multiplying both sides by an *expression that can be zero* can add solutions. The
equation `x = 3` has only the solution `3`, but after multiplying both sides by `x − 2` the
new equation `(x − 2)·x = (x − 2)·3` is also solved by `x = 2`. -/
theorem extra_solution : ∃ x : Rat, (x - 2) * x = (x - 2) * 3 ∧ x ≠ 3 :=
  ⟨2, by grind, by decide⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
square_eq_double_iffLean 4Proved here from basic factsFormally verified
/-- Dividing by an expression that can be zero can *lose* solutions: `x² = 2x` has the two
solutions `0` and `2`, but "dividing by `x`" leaves only `x = 2`. Proof: `x² − 2x = x(x − 2)`,
and a product is zero exactly when a factor is (`Rat.mul_eq_zero`). -/
theorem square_eq_double_iff (x : Rat) : x * x = 2 * x ↔ x = 0 ∨ x = 2 := by
  constructor
  · intro h
    have hfac : x * (x - 2) = 0 := by grind
    rcases Rat.mul_eq_zero.mp hfac with h0 | h2
    · exact Or.inl h0
    · right
      grind
  · rintro (rfl | rfl) <;> grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
solve_both_sidesLean 4Proved here from basic factsFormally verified
/-- The worked example `3x + 1 = x + 9`, solved by a chain of equivalent equations, exactly as
in the lesson: subtract `x + 1` from both sides, then multiply both sides by `1/2`. Every step
is an `↔`, so the final answer `x = 4` is not just *a* solution: it is the only one. -/
theorem solve_both_sides (x : Rat) : 3 * x + 1 = x + 9 ↔ x = 4 :=
  calc (3 * x + 1 = x + 9)
        ↔ (3 * x + 1) + (-x - 1) = (x + 9) + (-x - 1) := add_both_sides _ _ _
    _ ↔ 2 * x = 8 := by
        rw [show (3 * x + 1) + (-x - 1) = 2 * x by grind,
          show (x + 9) + (-x - 1) = (8 : Rat) by grind]
    _ ↔ (1 / 2) * (2 * x) = (1 / 2) * 8 := mul_both_sides _ _ _ (by grind)
    _ ↔ x = 4 := by
        rw [show (1 / 2 : Rat) * (2 * x) = x by grind, show (1 / 2 : Rat) * 8 = 4 by grind]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
solve_fractionsLean 4Proved here from basic factsFormally verified
/-- An equation with fractions: `x/3 + 1/2 = (x − 1)/4`. Multiplying both sides by `12`, the
least common multiple of the denominators, clears the fractions: `4x + 6 = 3x − 3`, so
`x = −9`. -/
theorem solve_fractions (x : Rat) : x / 3 + 1 / 2 = (x - 1) / 4 ↔ x = -9 :=
  calc (x / 3 + 1 / 2 = (x - 1) / 4)
        ↔ 12 * (x / 3 + 1 / 2) = 12 * ((x - 1) / 4) := mul_both_sides _ _ _ (by decide)
    _ ↔ 4 * x + 6 = 3 * x - 3 := by
        rw [show 12 * (x / 3 + 1 / 2) = 4 * x + 6 by grind,
          show 12 * ((x - 1) / 4) = 3 * x - 3 by grind]
    _ ↔ x = -9 := by
        constructor <;> intro h <;> grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor

Now the general theory: every linear equation has a standard form, the three outcomes for ax=bax = b, and the theorem that two solutions force infinitely many.

to_standard_formLean 4Proved here from basic factsFormally verified
/-- Every linear equation `a·x + b = c·x + d` is equivalent to one of the form `A·x = B`:
subtract `c·x + b` from both sides to get `(a − c)·x = d − b`. -/
theorem to_standard_form (a b c d x : Rat) :
    a * x + b = c * x + d ↔ (a - c) * x = d - b := by
  rw [add_both_sides (a * x + b) (c * x + d) (-(c * x) - b)]
  rw [show a * x + b + (-(c * x) - b) = (a - c) * x by grind,
    show c * x + d + (-(c * x) - b) = d - b by grind]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
ax_eq_b_trichotomyLean 4Proved here from basic factsFormally verified
/-- The three possible outcomes for `a·x = b`:
* if `a ≠ 0` there is exactly one solution, `x = b / a`;
* if `a = 0` and `b ≠ 0` there is no solution (`0·x` is always `0`);
* if `a = 0` and `b = 0` every number is a solution. -/
theorem ax_eq_b_trichotomy (a b : Rat) :
    (a ≠ 0 → ∀ x, a * x = b ↔ x = b / a) ∧
    (a = 0 → b ≠ 0 → ∀ x, a * x ≠ b) ∧
    (a = 0 → b = 0 → ∀ x, a * x = b) := by
  refine ⟨?_, ?_, ?_⟩
  · intro ha x
    constructor
    · intro h
      calc x = a * x / a := by rw [Rat.mul_comm, Rat.mul_div_cancel ha]
        _ = b / a := by rw [h]
    · intro h
      rw [h, Rat.mul_comm, Rat.div_mul_cancel ha]
  · intro ha hb x h
    rw [ha, Rat.zero_mul] at h
    exact hb h.symm
  · intro ha hb x
    rw [ha, hb, Rat.zero_mul]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
two_solutions_allLean 4Proved here from basic factsFormally verified
/-- A linear equation never has exactly two solutions: if two *different* numbers solve
`a·x + b = c·x + d`, then every number does. In standard form `(a − c)·x = d − b`; two
solutions give `(a − c)(x₁ − x₂) = 0` with `x₁ − x₂ ≠ 0`, so `a − c = 0`, then `d − b = 0`. -/
theorem two_solutions_all (a b c d x₁ x₂ : Rat) (hne : x₁ ≠ x₂)
    (h₁ : a * x₁ + b = c * x₁ + d) (h₂ : a * x₂ + b = c * x₂ + d) :
    ∀ x, a * x + b = c * x + d := by
  rw [to_standard_form] at h₁ h₂
  have hprod : (a - c) * (x₁ - x₂) = 0 := by grind
  have hac : a - c = 0 := by
    rcases Rat.mul_eq_zero.mp hprod with h | h
    · exact h
    · exact absurd (by grind) hne
  intro x
  rw [to_standard_form]
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
no_solution_exampleLean 4Proved here from basic factsFormally verified
/-- `2(x + 3) = 2x + 5` has no solution: expanding gives `2x + 6 = 2x + 5`, and subtracting
`2x` from both sides leaves the false statement `6 = 5`. -/
theorem no_solution_example : ¬ ∃ x : Rat, 2 * (x + 3) = 2 * x + 5 := by
  intro ⟨x, h⟩
  have h65 : (6 : Rat) = 5 := by grind
  exact absurd h65 (by decide)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
identity_exampleLean 4Proved here from basic factsFormally verified
/-- `3(x − 2) + x = 4x − 6` is true for every `x`: expanding the left side gives
`3x − 6 + x = 4x − 6`. Every number is a solution. -/
theorem identity_example (x : Rat) : 3 * (x - 2) + x = 4 * x - 6 := by
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
tanks_meetLean 4Proved here from basic factsFormally verified
/-- The two rainwater tanks of the lesson: one holds `500 − 20t` litres after `t` minutes,
the other `100 + 30t`. They hold the same amount exactly when `t = 8`. -/
theorem tanks_meet (t : Rat) : 500 - 20 * t = 100 + 30 * t ↔ t = 8 := by
  constructor
  · intro h
    grind
  · intro h
    rw [h]
    grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor

For inequalities, the first two moves are already in core Lean's library, so we simply apply them. The reversal for negative numbers is proved here, following the human proof line by line:

ineq_add_both_sidesLean 4Applies a library theoremFormally verified
/-- Adding the same number to both sides of an inequality keeps it true, and in the same
direction: `p < q ↔ p + c < q + c`. This applies core Lean's `Rat.add_lt_add_right`. -/
theorem ineq_add_both_sides (p q c : Rat) : p < q ↔ p + c < q + c :=
  Rat.add_lt_add_right.symm
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
ineq_mul_posLean 4Applies a library theoremFormally verified
/-- Multiplying both sides of an inequality by a **positive** number keeps its direction:
for `c > 0`, `p < q ↔ c·p < c·q`. This applies core Lean's `Rat.mul_lt_mul_left`. -/
theorem ineq_mul_pos (p q c : Rat) (hc : 0 < c) : p < q ↔ c * p < c * q :=
  (Rat.mul_lt_mul_left hc).symm
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
ineq_mul_negLean 4Proved here from basic factsFormally verified
/-- Multiplying both sides of an inequality by a **negative** number reverses it:
if `c < 0` and `p < q` then `c·q < c·p`. The human proof: `q − p` is positive and `−c` is
positive, so their product `(−c)(q − p) = c·p − c·q` is positive, which says `c·q < c·p`. -/
theorem ineq_mul_neg (p q c : Rat) (hc : c < 0) (h : p < q) : c * q < c * p := by
  have h1 : 0 < q - p := (Rat.lt_iff_sub_pos p q).mp h
  have h2 : 0 < -c := by grind
  have h3 : 0 < -c * (q - p) := Rat.mul_pos h2 h1
  have h4 : -c * (q - p) = c * p - c * q := by grind
  rw [h4] at h3
  exact (Rat.lt_iff_sub_pos (c * q) (c * p)).mpr h3
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
ineq_mul_neg_iffLean 4Proved here from basic factsFormally verified
/-- The reversal is an equivalence: for `c < 0`, `p < q ↔ c·q < c·p`. Backwards: if `p < q`
failed, then `q = p` (so `c·q = c·p`) or `q < p` (so `c·p < c·q` by `ineq_mul_neg`); either
way `c·q < c·p` would be impossible. -/
theorem ineq_mul_neg_iff (p q c : Rat) (hc : c < 0) : p < q ↔ c * q < c * p := by
  constructor
  · exact ineq_mul_neg p q c hc
  · intro h
    by_cases hpq : p < q
    · exact hpq
    · exfalso
      rcases Rat.le_iff_lt_or_eq.mp (Rat.not_lt.mp hpq) with hlt | heq
      · -- `q < p`, so `c·p < c·q`, contradicting `c·q < c·p`.
        have h' : c * p < c * q := ineq_mul_neg q p c hc hlt
        grind
      · -- `q = p`, so `c·q < c·p` would say `c·p < c·p`.
        rw [heq] at h
        exact Rat.lt_irrefl h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
ineq_exampleLean 4Proved here from basic factsFormally verified
/-- The worked example `7 − 3x ≤ 19`: subtracting `7` gives `−3x ≤ 12`, and dividing by `−3`
**reverses** the inequality, giving `x ≥ −4`. Here `grind` checks the linear arithmetic of both
directions. -/
theorem ineq_example (x : Rat) : 7 - 3 * x ≤ 19 ↔ -4 ≤ x := by
  constructor <;> intro h <;> grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor
notebooksLean 4Proved here from basic factsFormally verified
/-- Whole-number solutions: with `200` dirhams, a `45`-dirham book and `n` notebooks at `12`
dirhams each are affordable exactly when `n ≤ 12`, since `45 + 12n ≤ 200 ↔ 12n ≤ 155` and
`155 / 12 ≈ 12.9`. (`omega` decides such statements about whole numbers.) -/
theorem notebooks (n : Nat) : 45 + 12 * n ≤ 200 ↔ n ≤ 12 := by
  omega
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearEquations.leanTry it in the Lean web editor

Some short steps above are finished by the tactics grind (which rearranges sums and products and decides linear arithmetic over the rationals) and omega (which decides linear arithmetic over whole numbers). They are decision procedures: they check the step completely, they do not guess. What is formalised: every theorem of this lesson, for the rational numbers.

ComputationC

Solving, counting and testing by computer

Linear equations: exact solutions and inequality flipsPythonExact computationExhaustive finite checkExperimental evidenceComputationally tested
"""Solving linear equations exactly, and testing the rules for inequalities.

Part 1 solves every equation a*x + b = c*x + d from the lesson exactly, with
Python's Fraction type, by reducing it to the standard form (a - c)x = d - b,
and checks each answer by substituting it back. Part 2 counts, over ALL
equations with small integer coefficients, how many test values satisfy
each one: always 0, 1 or all of them, never exactly 2 - as the lesson's
theorem predicts. Part 3 tests the rule "multiplying an inequality by a
negative number reverses it" on random fractions, and compares the right
and the wrong ("forgot to flip") answers to 7 - 3x <= 19.
"""

import random
from fractions import Fraction as F

#: (description, a, b, c, d) meaning a*x + b = c*x + d.
LESSON_EQUATIONS = [
    ("3x + 1 = x + 9", 3, 1, 1, 9),
    ("500 - 20t = 100 + 30t", -20, 500, 30, 100),
    ("x/3 + 1/2 = (x - 1)/4", F(1, 3), F(1, 2), F(1, 4), F(-1, 4)),
    ("5 - 2x = 11", -2, 5, 0, 11),
    ("2(x + 3) = 2x + 5", 2, 6, 2, 5),
    ("3(x - 2) + x = 4x - 6", 4, -6, 4, -6),
]

def solve_linear(a, b, c, d):
    """Solve a*x + b = c*x + d exactly.

    Returns ("one", x), ("none", None) or ("all", None), following the
    standard form (a - c) x = d - b.
    """
    coeff, rhs = F(a) - F(c), F(d) - F(b)
    if coeff != 0:
        return "one", rhs / coeff
    if rhs != 0:
        return "none", None
    return "all", None

def satisfies(a, b, c, d, x):
    """Does x satisfy a*x + b = c*x + d (exact arithmetic)?"""
    return F(a) * x + b == F(c) * x + d

def solution_counts(coeffs, values):
    """For every (a, b, c, d) with entries in coeffs, count solutions in values.

    Returns a dict {number of solving values: number of equations}.
    """
    counts = {}
    for a in coeffs:
        for b in coeffs:
            for c in coeffs:
                for d in coeffs:
                    k = sum(1 for x in values if satisfies(a, b, c, d, x))
                    counts[k] = counts.get(k, 0) + 1
    return counts

def flip_trials(trials, seed=2024):
    """Random p < q and c < 0 (fractions). Count how often c*q < c*p holds."""
    rng = random.Random(seed)
    flipped = 0
    for _ in range(trials):
        p, q = sorted(F(rng.randint(-99, 99), rng.randint(1, 9)) for _ in "pq")
        if p == q:
            q += 1
        c = -F(rng.randint(1, 99), rng.randint(1, 9))
        flipped += c * q < c * p
    return flipped

def inequality_table(values):
    """Values x with 7 - 3x <= 19, and the two candidate answers."""
    true_set = [x for x in values if 7 - 3 * x <= 19]
    right = [x for x in values if x >= -4]
    wrong = [x for x in values if x <= -4]
    return true_set, right, wrong

def main():
    print("1. Exact solutions via the standard form (a - c)x = d - b")
    for text, a, b, c, d in LESSON_EQUATIONS:
        kind, x = solve_linear(a, b, c, d)
        if kind == "one":
            ok = "checks" if satisfies(a, b, c, d, x) else "FAILS"
            result = f"solution {x}   (substituting back: {ok})"
        elif kind == "none":
            result = "no solution: reduces to 0x = " + str(F(d) - F(b))
        else:
            result = "every number is a solution: 0x = 0"
        print(f"   {text:<24} {result}")
    print()
    values = range(-5, 6)
    counts = solution_counts(range(-3, 4), values)
    print("2. All 2401 equations ax + b = cx + d with a, b, c, d in -3..3:")
    print("   how many of the 11 values -5..5 solve each equation?")
    for k in sorted(counts):
        print(f"   {k:>2} solving value(s): {counts[k]:>4} equations")
    print("   Never 2 to 10: two solutions force every number to be one.")
    print()
    trials = 10_000
    flipped = flip_trials(trials)
    print(f"3. {trials} random fractions p < q and c < 0:")
    print(f"   c*q < c*p (reversed) in {flipped} cases;"
          f" c*p < c*q in {trials - flipped}.")
    true_set, right, wrong = inequality_table(range(-8, 3))
    print("   7 - 3x <= 19 for x in -8..2 is true at", true_set)
    print("   answer x >= -4 picks", right)
    print("   answer x <= -4 (forgot to flip) picks", wrong)
    print()
    print("Epistemic status: part 1 is exact rational arithmetic, and each")
    print("answer is checked by substitution. Part 2 is an exhaustive check of")
    print("2401 equations on 11 values - finite evidence for the lesson's theorem,")
    print("which proves it for all equations and all numbers. Part 3 is a random")
    print("experiment; only the proof shows the reversal rule always holds.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Part 2 is a nice example of a computation and a proof working together. The computer checked 24012401 equations on 1111 values each and never found an equation with between 22 and 1010 solving values — exactly as the theorem predicts. The computation alone covers only those equations and values; the theorem covers them all. In part 3, notice how badly the "forgot to flip" answer does: it shares only the boundary point x=−4x = -4 with the true solution set.

Explore

Explore: equations as meeting points

The two sides of ax+b=cx+dax + b = cx + d are two straight lines, y=ax+by = ax + b and y=cx+dy = cx + d. A solution is an xx where the lines are at the same height: where they meet. Move the sliders and watch the three outcomes appear.

Where do the two sides agree?

Starts at 3x + 1 = x + 9, solved by x = 4.

solution
  • left side y = ax + b
  • right side y = cx + d
  • left side y = ax + b: y = 4
  • right side y = cx + d: y = 10

Things to try:

  • Make a=ca = c but b≠db \neq d: the lines are parallel and never meet — no solution.
  • Make a=ca = c and b=db = d: the lines lie on top of each other — every xx is a solution.
  • Can you make two straight lines meet in exactly two points? (The theorem says no.)

And on the balance: what happens here, where the same number of boxes sits on each side?

Balance the equation

Can you make this scale level?

x11x11111
  • x (unknown weight)
  • 1 (unit weight)

x + 2 = x + 5

This scale can never balance: both sides have the same number of x's but different numbers of 1s. The equation has no solution.

Your steps

  1. x + 2 = x + 5
Make your own equation

Left side

Number of x's1
Number of 1s2

Right side

Number of x's1
Number of 1s5
Exercises

Exercises

1. Linear equations and inequalities

Warm-upHuman

Solve 5x−7=2x+85x - 7 = 2x + 8.

2. Linear equations and inequalities

CoreHuman

Solve x+23=x−12\dfrac{x + 2}{3} = \dfrac{x - 1}{2}.

3. Linear equations and inequalities

CoreHuman

Which of these equations have no solution? (Choose all that apply.)

Choose all that apply

4. Linear equations and inequalities

CoreHuman

Ravi starts with the equation x=5x = 5. He multiplies both sides by 00, gets 0=00 = 0, and concludes that every number is a solution. What went wrong?

Choose one

5. Linear equations and inequalities

CoreHuman

Solve 4−2x>104 - 2x > 10.

Choose one

6. Linear equations and inequalities

CoreHuman

In Manila, one phone-repair shop charges 150150 pesos plus 8080 pesos per hour of work. Another charges 5050 pesos plus 100100 pesos per hour. For how many hours of work do the two shops charge the same?

7. Linear equations and inequalities

CoreHuman

Ama has 5050 cedis. She buys a bus ticket for 88 cedis and wants to spend the rest on mangoes at 44 cedis each. What is the largest number of mangoes she can buy?

8. Linear equations and inequalities

CoreFormal

Which Lean statement correctly says "multiplying both sides of an inequality by a negative number reverses it"?

Choose one

9. Linear equations and inequalities

StretchComputational

Write solve_linear(a, b, c, d) for the equation ax+b=cx+dax + b = cx + d with integer coefficients. Return the solution as a Fraction if there is exactly one, the string "none" if there is no solution, and "all" if every number is a solution.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

10. Linear equations and inequalities

StretchHuman

Kwame claims he has found a linear equation ax+b=cx+dax + b = cx + d whose solutions are exactly x=1x = 1 and x=2x = 2. Which argument shows this is impossible?

Choose one
Common misconceptionsH

Common misconceptions

Misconception

"Multiplying both sides by the same thing is always safe." Only if the thing cannot be zero. Multiplying x=3x = 3 by 00 gives 0=00 = 0, true for every xx. Multiplying by an expression that can be zero can add solutions: (x−2)x=(x−2)⋅3(x - 2)x = (x - 2) \cdot 3 is also solved by x=2x = 2. Dividing by such an expression can lose them: "dividing" x2=2xx^2 = 2x by xx gives x=2x = 2 and loses the solution x=0x = 0. Safe moves are the ones you can undo.

Misconception

Forgetting to reverse the inequality. Dividing −3x≤12-3x \leq 12 by −3-3 gives x≥−4x \geq -4, not x≤−4x \leq -4. Test a value to check: x=0x = 0 satisfies 7−3x≤197 - 3x \leq 19, so the answer must include 00.

Misconception

Doing the move to only one term. From 2x+3=112x + 3 = 11, dividing "both sides" by 22 gives x+32=112x + \tfrac{3}{2} = \tfrac{11}{2}, not x+3=112x + 3 = \tfrac{11}{2}. A move applies to a whole side. Likewise, when clearing fractions, multiply every term by the common denominator.

Misconception

"−(x−5)=−x−5-(x - 5) = -x - 5." The minus sign multiplies both terms in the bracket: −(x−5)=−x+5-(x - 5) = -x + 5.

Misconception

"00 as an answer means no solution." The equation 4x=04x = 0 has the solution x=0x = 0. "No solution" means that no number works, as in 0⋅x=50 \cdot x = 5.

ViewpointsH

Other ways of seeing

Geometry— Meeting points and reflections

Solving ax+b=cx+dax + b = cx + d is finding where two lines in the coordinate plane cross. Two lines either cross once, never (parallel), or coincide — which is the geometric face of the theorem "one, none or infinitely many". The flip of an inequality is geometry too: x↦−xx \mapsto -x is the reflection of the number line in 00, and a reflection turns "left of" into "right of". The next lesson, linear relationships, builds on these pictures.

Algebra— Why we need inverses

The proof that the moves work used two things: every number cc has an additive inverse −c-c, and every non-zero number has a multiplicative inverse 1c\tfrac{1}{c}. A number system with both is called a field; the rational numbers are one. In the integers, 22 has no multiplicative inverse, and 2x=12x = 1 has no integer solution. In clock arithmetic with 77 hours, though, 3⋅5=153 \cdot 5 = 15 leaves remainder 11, so 55 acts as 13\tfrac{1}{3}, and the "linear equation" 3x=13x = 1 is solved by x=5x = 5. The trails below explore this.

Logic— Implies versus if and only if

Each step of a solution should be an equivalence (⇔\Leftrightarrow), not just an implication (⇒\Rightarrow). Squaring both sides, or multiplying by an expression that can be zero, is only an implication: every solution of the old equation solves the new one, but the new one may have extra solutions (logicians would say the new equation is weaker). That is why such steps must always be followed by a check in the original equation. Lean makes the difference visible: our worked example is proved with ↔, so its answer is both necessary and sufficient.

Wonder Trails

Wonder Trails

History & global context

History and global context

  • The Rhind papyrus (Egypt, copied by the scribe Ahmes around 1550 BCE) contains linear problems such as Problem 24: "a quantity and its seventh, added together, become 19". It was solved by false position: guess 77, which gives 7+1=87 + 1 = 8; since 88 must become 1919, scale the guess by 198\tfrac{19}{8}, giving 16+12+1816 + \tfrac{1}{2} + \tfrac{1}{8}.
  • Chapter 7 of the Chinese Nine Chapters on the Mathematical Art (compiled by about the 1st century CE), "Excess and deficit", solves linear problems by a method of double false position: two guesses, one too big and one too small, determine the answer exactly.
  • In 9th-century Baghdad, al-Khwārizmī named two of the operations of this lesson. Al-jabr ("restoring") adds equal amounts to both sides to remove a subtracted term; al-muqābala ("balancing") cancels equal terms from both sides. Brahmagupta in India (628 CE) also gave a general rule for solving linear equations.
  • The equals sign was introduced by the Welsh mathematician Robert Recorde in The Whetstone of Witte (1557), "bicause noe .2. thynges, can be moare equalle" than two parallel lines. The signs << and >> appear in Thomas Harriot's Artis analyticae praxis, published in 1631 after his death.
Further reading

Further reading

  • I. M. Gelfand and A. Shen, Algebra (1993) — equations, inequalities and much more, through problems.
  • Victor J. Katz, A History of Mathematics: An Introduction (3rd edition, 2009) — Egyptian, Chinese, Indian and Islamic methods for linear problems.
  • Arnold Buffum Chace, The Rhind Mathematical Papyrus (1927–1929) — a translation with commentary, including the false-position problems.
  • Kangshen Shen, John N. Crossley and Anthony W.-C. Lun, The Nine Chapters on the Mathematical Art: Companion and Commentary (1999).