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

Linear relationships and simultaneous equations

Constant rates of change draw straight lines; two lines meet once, never, or everywhere — and that explains every pair of simultaneous equations.

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

Your guides: Chloe, Margaret, Gideon

MotivationH

When do the thermometers agree?

Most of the world measures temperature in degrees Celsius; a few countries, including the United States, use degrees Fahrenheit. Water freezes at 0 ∘C0\,^\circ\mathrm{C}, which is 32 ∘F32\,^\circ\mathrm{F}, and boils (at sea level) at 100 ∘C100\,^\circ\mathrm{C}, which is 212 ∘F212\,^\circ\mathrm{F}. A warm afternoon in Accra at 25 ∘C25\,^\circ\mathrm{C} is 77 ∘F77\,^\circ\mathrm{F}.

Celsius CC002525100100
Fahrenheit FF32327777212212

Here is a puzzle: is there a temperature at which both thermometers show the same number? At 0 ∘C0\,^\circ\mathrm{C} the Fahrenheit number is bigger by 3232; at 100 ∘C100\,^\circ\mathrm{C}, bigger by 112112. The gap grows as it gets warmer — so perhaps it shrinks as it gets colder, and vanishes somewhere below zero?

More than 1,500 years ago, a Chinese textbook, the Sunzi Suanjing, posed a famous puzzle of the same kind: pheasants and rabbits share a cage; there are 3535 heads and 9494 feet. How many of each? Both puzzles ask for two unknown numbers satisfying two conditions at once. By the end of this lesson you will solve them in three different ways — and know exactly when such a puzzle has one answer, none, or infinitely many.

IntuitionH

Constant rate of change

A taxi in Lima charges a fixed 55 soles plus 22 soles per kilometre.

distance xx (km)0011223344
fare yy (soles)55779911111313

Each extra kilometre adds the same amount, 22 soles. The fare changes at a constant rate of 22 soles per kilometre, and the formula is y=2x+5y = 2x + 5. Plot the table and the points line up perfectly: a constant rate of change draws a straight line. The rate, 22, tells us how steep the line is; the starting value, 55, tells us where it crosses the vertical axis.

y = mx + b

Each step of 1 to the right changes y by exactly m.

start
  • y = mx + b
  • y = mx + b: y = 7
DefinitionsH

Slope, linear functions and systems

Definition— slope

The slope of the line through two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) with x1≠x2x_1 \neq x_2 is

m=y2−y1x2−x1=riserun.m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{\text{rise}}{\text{run}}.

It is the change in yy per unit change in xx: a rate of change. A vertical line (x1=x2x_1 = x_2) has no slope — its run is 00, and we cannot divide by 00.

Definition— linear function

A linear function has the form f(x)=mx+bf(x) = mx + b for fixed numbers mm and bb (see functions). Its graph, drawn in the coordinate plane, is the line y=mx+by = mx + b, with slope mm and yy-intercept bb (the height where it crosses the yy-axis, at x=0x = 0).

Definition— proportional relationship

A relationship is proportional if y=kxy = kx for a constant kk, the constant of proportionality (see ratios and proportional reasoning). Proportional relationships are the linear functions with b=0b = 0: their graphs pass through the origin.

Definition— system of equations

A system of equations is a collection of equations in the same unknowns. A solution of the system is a choice of values that satisfies every equation at once. Equations solved together are also called simultaneous equations.

Worked examplesH

Worked examples

Example— Slopes from two points

  • Through (2,1)(2, 1) and (6,9)(6, 9): m=9−16−2=84=2m = \dfrac{9 - 1}{6 - 2} = \dfrac{8}{4} = 2. The line rises 22 for every 11 to the right.
  • Through (−1,4)(-1, 4) and (3,−4)(3, -4): m=−4−43−(−1)=−84=−2m = \dfrac{-4 - 4}{3 - (-1)} = \dfrac{-8}{4} = -2. A negative slope: the line falls.
  • Through (1,3)(1, 3) and (5,3)(5, 3): m=04=0m = \dfrac{0}{4} = 0. A horizontal line: yy does not change.
  • Through (3,1)(3, 1) and (3,6)(3, 6): the run is 00. This is the vertical line x=3x = 3; its slope is undefined.

You may take the points in either order, as long as you subtract in the same order on top and bottom: 1−92−6=−8−4=2\dfrac{1 - 9}{2 - 6} = \dfrac{-8}{-4} = 2 as well.

Example— A line from its slope and one point

Find the line with slope 33 through (2,5)(2, 5). It has the form y=3x+by = 3x + b, and the point must satisfy it: 5=3⋅2+b5 = 3 \cdot 2 + b, so b=−1b = -1. The line is y=3x−1y = 3x - 1.

In general, the line with slope mm through (x1,y1)(x_1, y_1) is y=mx+(y1−mx1)y = mx + (y_1 - m x_1), which can also be written in point–slope form: y−y1=m(x−x1)y - y_1 = m(x - x_1).

Example— A line through two points: Celsius to Fahrenheit

The points (0,32)(0, 32) and (100,212)(100, 212) give the slope m=212−32100−0=180100=95m = \dfrac{212 - 32}{100 - 0} = \dfrac{180}{100} = \dfrac{9}{5}, and the intercept is 3232. So

F=95 C+32.F = \tfrac{9}{5}\,C + 32.

Check with the third point: 95⋅25+32=45+32=77\tfrac{9}{5} \cdot 25 + 32 = 45 + 32 = 77. ✓ The slope says that each degree Celsius is 1.81.8 degrees Fahrenheit.

Example— Recognising linear relationships in tables

In a table whose xx-values go up in equal steps, a relationship is linear exactly when the yy-values go up (or down) by equal steps too.

  • Rice at 6060 rupees per kilogram: 1↦601 \mapsto 60, 2↦1202 \mapsto 120, 5↦3005 \mapsto 300. Linear and proportional: y=60xy = 60x.
  • The taxi: 0↦50 \mapsto 5, 1↦71 \mapsto 7, 2↦92 \mapsto 9. Linear but not proportional: doubling the distance does not double the fare (22 km costs 99 soles, not 2⋅7=142 \cdot 7 = 14).
  • The area of a square: 1↦11 \mapsto 1, 2↦42 \mapsto 4, 3↦93 \mapsto 9, 4↦164 \mapsto 16. The steps are 3,5,73, 5, 7: not linear.
ProofH

Why a line has one slope

The examples suggest two facts: on a line, the slope does not depend on which two points we pick; and a constant rate of change always gives a formula y=mx+by = mx + b. Here are the proofs.

Theorem— the slope of y = mx + b is m

For any two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) on the line y=mx+by = mx + b with x1≠x2x_1 \neq x_2, the slope between them is mm.

Proof

Since both points are on the line, y1=mx1+by_1 = m x_1 + b and y2=mx2+by_2 = m x_2 + b. So the rise is

y2−y1=(mx2+b)−(mx1+b)=mx2−mx1=m(x2−x1),y_2 - y_1 = (m x_2 + b) - (m x_1 + b) = m x_2 - m x_1 = m(x_2 - x_1),

and dividing by the run x2−x1≠0x_2 - x_1 \neq 0 gives exactly mm.

∎

Theorem— constant rate of change means linear

Suppose a function ff has a constant rate of change mm: for all x1x_1 and x2x_2,   f(x2)−f(x1)=m(x2−x1)\;f(x_2) - f(x_1) = m(x_2 - x_1). Then f(x)=mx+bf(x) = mx + b for every xx, where b=f(0)b = f(0).

Proof

Take x1=0x_1 = 0 and x2=xx_2 = x: f(x)−f(0)=m(x−0)=mxf(x) - f(0) = m(x - 0) = mx, so f(x)=mx+f(0)f(x) = mx + f(0).

∎

run 5rise 3run 2.5rise 1.5
Two slope triangles on the same line. The big one has run 5 and rise 3; the small one has run 2.5 and rise 1.5. They are similar triangles — the same shape at different sizes — so rise ÷ run is 3/5 for both.

The picture gives the geometric reason: slope triangles drawn on one line are similar (their angles match because the line has one direction), and similar triangles have proportional sides (see similarity). The algebraic proof above needs no picture at all.

Theorem— proportional means through the origin

The linear relationship y=mx+by = mx + b is proportional — that is, mx+b=kxmx + b = kx for all xx, for some constant kk — if and only if b=0b = 0.

Proof

If mx+b=kxmx + b = kx for every xx, put x=0x = 0: b=0b = 0. Conversely, if b=0b = 0 then y=mxy = mx, which is proportional with k=mk = m.

∎

Worked examplesH

Simultaneous equations: three methods

Each linear equation in two unknowns xx and yy, such as x+y=35x + y = 35, has infinitely many solutions — all the points of a line. A system of two such equations asks for the points on both lines: where they meet.

Example— Graphing: pheasants and rabbits

Let xx be the number of pheasants and yy the number of rabbits. Counting heads and feet (two feet per pheasant, four per rabbit):

x+y=35,2x+4y=94.x + y = 35, \qquad 2x + 4y = 94.

Solving each for yy: y=35−xy = 35 - x and y=23.5−0.5xy = 23.5 - 0.5x. The lines meet at (23,12)(23, 12).

Two conditions, one meeting point

Move the sliders and trace along the curves to read off values.

(23, 12)
  • heads: x + y = 35
  • feet: 2x + 4y = 94
  • heads: x + y = 35: y = 34
  • feet: 2x + 4y = 94: y = 23

A graph shows the answer at a glance, but reading it is only as accurate as the drawing — a meeting point at (23.4,11.7)(23.4, 11.7) would look much the same. Algebra gives exact answers.

Example— Elimination: pheasants and rabbits again

Multiply the first equation by 22, giving 2x+2y=702x + 2y = 70, and subtract it from the second:

(2x+4y)−(2x+2y)=94−70,so2y=24andy=12.(2x + 4y) - (2x + 2y) = 94 - 70, \quad\text{so}\quad 2y = 24 \quad\text{and}\quad y = 12.

Then x=35−12=23x = 35 - 12 = 23. Check both equations: 23+12=3523 + 12 = 35 heads, and 2⋅23+4⋅12=46+48=942 \cdot 23 + 4 \cdot 12 = 46 + 48 = 94 feet. ✓ Elimination works because, if both equations hold, any combination of them holds too.

Example— Substitution: when do the thermometers agree?

We want F=95C+32F = \tfrac{9}{5}C + 32 and F=CF = C at the same time. Substitute the second equation into the first:

C=95C+32  ⟹  −45C=32  ⟹  C=−40.C = \tfrac{9}{5}C + 32 \;\Longrightarrow\; -\tfrac{4}{5}C = 32 \;\Longrightarrow\; C = -40.

So −40 ∘C=−40 ∘F-40\,^\circ\mathrm{C} = -40\,^\circ\mathrm{F} — a temperature reached in the coldest winters of places such as Yakutsk in Siberia.

Example— No solution, and infinitely many

  • x+y=3x + y = 3 and 2x+2y=102x + 2y = 10. Doubling the first gives 2x+2y=62x + 2y = 6, which contradicts 2x+2y=102x + 2y = 10. No solution: as y=3−xy = 3 - x and y=5−xy = 5 - x, the graphs are parallel lines.
  • x+2y=4x + 2y = 4 and 2x+4y=82x + 4y = 8. The second equation is just the first one doubled: both describe the same line. Infinitely many solutions: for every number tt, the point (4−2t,t)(4 - 2t, t) works.
ProofH

One, none, or infinitely many

Theorem— where two lines meet

Consider the lines y=m1x+b1y = m_1 x + b_1 and y=m2x+b2y = m_2 x + b_2.

  1. If m1≠m2m_1 \neq m_2, they meet in exactly one point, at x=b2−b1m1−m2x = \dfrac{b_2 - b_1}{m_1 - m_2}.
  2. If m1=m2m_1 = m_2 and b1≠b2b_1 \neq b_2, they never meet: they are parallel.
  3. If m1=m2m_1 = m_2 and b1=b2b_1 = b_2, they are the same line.

Proof

A meeting point needs m1x+b1=m2x+b2m_1 x + b_1 = m_2 x + b_2, that is, (m1−m2)x=b2−b1(m_1 - m_2)x = b_2 - b_1. This is a linear equation in xx of the form ax=bax = b, and the lesson on linear equations showed it has exactly one solution if m1−m2≠0m_1 - m_2 \neq 0, none if m1=m2m_1 = m_2 and b2−b1≠0b_2 - b_1 \neq 0, and every xx as a solution if both are zero. When there is exactly one xx, there is exactly one meeting point (x,m1x+b1)(x, m_1 x + b_1).

∎

Vertical lines x=cx = c are not of the form y=mx+by = mx + b, but they are easy: two different vertical lines are parallel, and a vertical line meets every non-vertical line exactly once. The next theorem covers all lines at once, vertical or not, and in fact all linear equations.

Theorem— two solutions give infinitely many

If two different points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) both satisfy a linear equation ax+by=eax + by = e, then for every number tt so does the point

Pt=((1−t)x1+tx2,  (1−t)y1+ty2),P_t = \big((1 - t)x_1 + t x_2,\; (1 - t)y_1 + t y_2\big),

and different values of tt give different points.

Proof

Substitute PtP_t and regroup:

a((1−t)x1+tx2)+b((1−t)y1+ty2)=(1−t)(ax1+by1)+t(ax2+by2)=(1−t)e+te=e.a\big((1 - t)x_1 + t x_2\big) + b\big((1 - t)y_1 + t y_2\big) = (1 - t)(a x_1 + b y_1) + t(a x_2 + b y_2) = (1 - t)e + te = e.

If Ps=PtP_s = P_t with s≠ts \neq t, then subtracting coordinates gives (s−t)(x2−x1)=0(s - t)(x_2 - x_1) = 0 and (s−t)(y2−y1)=0(s - t)(y_2 - y_1) = 0, so x1=x2x_1 = x_2 and y1=y2y_1 = y_2, contradicting that the points are different.

∎

The points PtP_t make up the line through the two points (P0P_0 is the first point, P1P_1 the second, P1/2P_{1/2} the midpoint). Now apply the theorem to every equation of a system at once: if a system of linear equations — with any number of equations — has two different solutions, every PtP_t solves all of them. So:

A system of linear equations has exactly one solution, no solution, or infinitely many. Never exactly two, or three.

Note

Going further: the general formula. For the system ax+by=eax + by = e, cx+dy=fcx + dy = f, multiply the first equation by dd, the second by bb, and subtract: the yy-terms cancel and (ad−bc) x=ed−bf(ad - bc)\,x = ed - bf. Eliminating xx in the same way gives (ad−bc) y=af−ec(ad - bc)\,y = af - ec. So if the number ad−bcad - bc is not zero, the system has exactly one solution,

x=ed−bfad−bc,y=af−ecad−bc.x = \frac{ed - bf}{ad - bc}, \qquad y = \frac{af - ec}{ad - bc}.

The number ad−bcad - bc is called the determinant of the system; when both equations describe genuine lines, it is zero exactly when the two lines are parallel or the same. You will meet it again in linear algebra.

Formal mathematicsF

Lines and systems in Lean

In Lean, slope is a small definition, and "the point (x,y)(x, y) is on the line y=mx+by = mx + b" is just the equation y = m * x + b. We work with the rational numbers Rat.

slopeLean 4Formally verified
/-- The slope of the line through `(x₁, y₁)` and `(x₂, y₂)`: rise over run,
`(y₂ − y₁) / (x₂ − x₁)`. It is meaningful only when `x₁ ≠ x₂`; the theorems below always
assume that. (Lean's `Rat` sets `a / 0 = 0`, which is a convention, not a slope.) -/
def slope (x₁ y₁ x₂ y₂ : Rat) : Rat := (y₂ - y₁) / (x₂ - x₁)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
slope_symmLean 4Proved here from basic factsFormally verified
/-- The order of the two points does not matter, as long as we subtract in the same order on
top and bottom: `(y₂ − y₁)/(x₂ − x₁) = (y₁ − y₂)/(x₁ − x₂)`. -/
theorem slope_symm (x₁ y₁ x₂ y₂ : Rat) (h : x₁ ≠ x₂) :
    slope x₁ y₁ x₂ y₂ = slope x₂ y₂ x₁ y₁ := by
  have h₁ : x₂ - x₁ ≠ 0 := fun h0 => h (by grind)
  have h₂ : x₁ - x₂ ≠ 0 := fun h0 => h (by grind)
  unfold slope
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor

The central fact — the slope between any two points of a line is the same — is proved exactly as on paper: first the rise is mm times the run, then divide.

rise_eq_slope_mul_runLean 4Proved here from basic factsFormally verified
/-- On the line `y = m·x + b`, the rise between two points is `m` times the run:
`(m·x₂ + b) − (m·x₁ + b) = m·(x₂ − x₁)`. The intercept `b` cancels and the distributive law
does the rest. -/
theorem rise_eq_slope_mul_run (m b x₁ x₂ : Rat) :
    (m * x₂ + b) - (m * x₁ + b) = m * (x₂ - x₁) := by
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
slope_of_lineLean 4Proved here from basic factsFormally verified
/-- The slope between **any** two points of the line `y = m·x + b` is `m`. This is why a line
has one well-defined slope: the rise is `m·(run)`, so rise ÷ run is `m` for every choice of
points. -/
theorem slope_of_line (m b x₁ x₂ : Rat) (h : x₁ ≠ x₂) :
    slope x₁ (m * x₁ + b) x₂ (m * x₂ + b) = m := by
  have hrun : x₂ - x₁ ≠ 0 := fun h0 => h (by grind)
  unfold slope
  rw [rise_eq_slope_mul_run]
  exact Rat.mul_div_cancel hrun
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
linear_of_constant_rateLean 4Proved here from basic factsFormally verified
/-- The converse: a relationship with a **constant rate of change** `m` — every rise is `m`
times its run — is linear, `f(x) = m·x + b` with `b = f(0)`. Take the two points `0` and `x`. -/
theorem linear_of_constant_rate (f : Rat → Rat) (m : Rat)
    (h : ∀ x₁ x₂, f x₂ - f x₁ = m * (x₂ - x₁)) : ∀ x, f x = m * x + f 0 := by
  intro x
  have hx := h 0 x
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor

Finding a line from a point and a slope, or from two points, and the test for proportionality:

line_through_pointLean 4Proved here from basic factsFormally verified
/-- The line with slope `m` passes through `(x₁, y₁)` exactly when its intercept is
`b = y₁ − m·x₁`. So a slope and one point determine the line: `y = m·x + (y₁ − m·x₁)`, which
is the same as the point–slope form `y − y₁ = m·(x − x₁)`. -/
theorem line_through_point (m b x₁ y₁ : Rat) : m * x₁ + b = y₁ ↔ b = y₁ - m * x₁ := by
  constructor
  · intro h
    grind
  · intro h
    rw [h]
    grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
line_through_two_pointsLean 4Proved here from basic factsFormally verified
/-- Two points with different `x`-coordinates determine a line: with `m` the slope between
them and `b = y₁ − m·x₁`, the line `y = m·x + b` passes through both points. The second point
works because `m·(x₂ − x₁) = y₂ − y₁` (`Rat.div_mul_cancel`). -/
theorem line_through_two_points (x₁ y₁ x₂ y₂ : Rat) (h : x₁ ≠ x₂) :
    slope x₁ y₁ x₂ y₂ * x₁ + (y₁ - slope x₁ y₁ x₂ y₂ * x₁) = y₁ ∧
      slope x₁ y₁ x₂ y₂ * x₂ + (y₁ - slope x₁ y₁ x₂ y₂ * x₁) = y₂ := by
  have hrun : x₂ - x₁ ≠ 0 := fun h0 => h (by grind)
  have hm : slope x₁ y₁ x₂ y₂ * (x₂ - x₁) = y₂ - y₁ := by
    unfold slope
    exact Rat.div_mul_cancel hrun
  constructor
  · grind
  · calc slope x₁ y₁ x₂ y₂ * x₂ + (y₁ - slope x₁ y₁ x₂ y₂ * x₁)
        = slope x₁ y₁ x₂ y₂ * (x₂ - x₁) + y₁ := by grind
      _ = (y₂ - y₁) + y₁ := by rw [hm]
      _ = y₂ := by grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
proportional_iffLean 4Proved here from basic factsFormally verified
/-- A linear relationship `y = m·x + b` is **proportional** (`y = k·x` for some constant `k`)
exactly when `b = 0`, i.e. when its graph passes through the origin. Forwards: put `x = 0`. -/
theorem proportional_iff (m b : Rat) : (∃ k, ∀ x, m * x + b = k * x) ↔ b = 0 := by
  constructor
  · intro ⟨k, hk⟩
    have h0 := hk 0
    grind
  · intro hb
    exact ⟨m, fun x => by rw [hb]; grind⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
comp_linearLean 4Proved here from basic factsFormally verified
/-- Doing one linear function after another gives a linear function: applying
`x ↦ m₂·x + b₂` and then `x ↦ m₁·x + b₁` gives `x ↦ (m₁·m₂)·x + (m₁·b₂ + b₁)`.
The slopes multiply. -/
theorem comp_linear (m₁ b₁ m₂ b₂ x : Rat) :
    m₁ * (m₂ * x + b₂) + b₁ = (m₁ * m₂) * x + (m₁ * b₂ + b₁) := by
  calc m₁ * (m₂ * x + b₂) + b₁ = m₁ * (m₂ * x) + m₁ * b₂ + b₁ := by rw [Rat.mul_add]
    _ = (m₁ * m₂) * x + (m₁ * b₂ + b₁) := by grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor

Where two lines meet:

lines_meet_onceLean 4Proved here from basic factsFormally verified
/-- Two lines with **different** slopes meet in exactly one point: `m₁·x + b₁ = m₂·x + b₂`
holds exactly when `x = (b₂ − b₁)/(m₁ − m₂)`. (Subtract, then divide by `m₁ − m₂ ≠ 0`.) -/
theorem lines_meet_once (m₁ b₁ m₂ b₂ x : Rat) (h : m₁ ≠ m₂) :
    m₁ * x + b₁ = m₂ * x + b₂ ↔ x = (b₂ - b₁) / (m₁ - m₂) := by
  have hd : m₁ - m₂ ≠ 0 := fun h0 => h (by grind)
  constructor
  · intro heq
    have hx : (m₁ - m₂) * x = b₂ - b₁ := by grind
    calc x = (m₁ - m₂) * x / (m₁ - m₂) := by rw [Rat.mul_comm, Rat.mul_div_cancel hd]
      _ = (b₂ - b₁) / (m₁ - m₂) := by rw [hx]
  · intro hx
    have hmul : (m₁ - m₂) * x = b₂ - b₁ := by
      rw [hx, Rat.mul_comm, Rat.div_mul_cancel hd]
    grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
parallel_never_meetLean 4Proved here from basic factsFormally verified
/-- Two different lines with the **same** slope never meet: if `b₁ ≠ b₂` then
`m·x + b₁ ≠ m·x + b₂` for every `x` — the gap between them is always `b₂ − b₁`. -/
theorem parallel_never_meet (m b₁ b₂ x : Rat) (h : b₁ ≠ b₂) : m * x + b₁ ≠ m * x + b₂ := by
  intro heq
  exact h (Rat.add_left_cancel (m * x) heq)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
chickens_rabbitsLean 4Proved here from basic factsFormally verified
/-- The *Sunzi Suanjing* puzzle: chickens and rabbits in a cage have `35` heads and `94` legs.
Elimination: subtract twice the heads equation from the legs equation to get `2r = 24`, so
`r = 12` rabbits and `c = 23` chickens. -/
theorem chickens_rabbits (c r : Rat) (h₁ : c + r = 35) (h₂ : 2 * c + 4 * r = 94) :
    c = 23 ∧ r = 12 := by
  have h2r : 2 * r = 24 :=
    calc 2 * r = (2 * c + 4 * r) - 2 * (c + r) := by grind
      _ = 94 - 2 * 35 := by rw [h₂, h₁]
      _ = 24 := by grind
  have hr : r = 12 := by grind
  have hc : c = 23 := by grind
  exact ⟨hc, hr⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
celsius_fahrenheitLean 4Proved here from basic factsFormally verified
/-- The temperature at which the Celsius and Fahrenheit scales show the same number: the
system `F = (9/5)·C + 32`, `F = C`. Substituting the second into the first leaves
`(9/5)·C + 32 = C`, whose only solution is `C = −40`. -/
theorem celsius_fahrenheit (c : Rat) : 9 / 5 * c + 32 = c ↔ c = -40 := by
  constructor
  · intro h
    grind
  · intro h
    rw [h]
    grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
parallel_systemLean 4Proved here from basic factsFormally verified
/-- A system with no solution: `x + y = 3` and `2x + 2y = 10`. Doubling the first equation
gives `2x + 2y = 6`, so a solution would make `6 = 10`. (The graphs are parallel lines.) -/
theorem parallel_system : ¬ ∃ x y : Rat, x + y = 3 ∧ 2 * x + 2 * y = 10 := by
  intro ⟨x, y, h₁, h₂⟩
  have h610 : (6 : Rat) = 10 :=
    calc (6 : Rat) = 2 * (x + y) := by rw [h₁]; grind
      _ = 2 * x + 2 * y := by grind
      _ = 10 := h₂
  exact absurd h610 (by decide)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
same_line_systemLean 4Proved here from basic factsFormally verified
/-- A system with infinitely many solutions: `x + 2y = 4` and `2x + 4y = 8` describe the same
line, and for every number `t` the point `(4 − 2t, t)` solves both. -/
theorem same_line_system (t : Rat) :
    (4 - 2 * t) + 2 * t = 4 ∧ 2 * (4 - 2 * t) + 4 * t = 8 := by
  constructor <;> grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor

The general results: a unique solution when ad−bc≠0ad - bc \neq 0, and "two solutions give infinitely many".

cramerLean 4Proved here from basic factsFormally verified
/-- A system `a·x + b·y = e`, `c·x + d·y = f` with `a·d − b·c ≠ 0` has exactly one solution.
Eliminating `y` (multiply the equations by `d` and `b` and subtract) gives
`(a·d − b·c)·x = e·d − b·f`; eliminating `x` gives `(a·d − b·c)·y = a·f − e·c`. -/
theorem cramer (a b c d e f : Rat) (h : a * d - b * c ≠ 0) :
    ∃ x y, (a * x + b * y = e ∧ c * x + d * y = f) ∧
      ∀ x' y', a * x' + b * y' = e → c * x' + d * y' = f → x' = x ∧ y' = y := by
  refine ⟨(e * d - b * f) / (a * d - b * c), (a * f - e * c) / (a * d - b * c), ⟨?_, ?_⟩, ?_⟩
  · grind
  · grind
  · intro x' y' h₁ h₂
    have hx : (a * d - b * c) * x' = e * d - b * f := by grind
    have hy : (a * d - b * c) * y' = a * f - e * c := by grind
    constructor
    · calc x' = (a * d - b * c) * x' / (a * d - b * c) := by
            rw [Rat.mul_comm, Rat.mul_div_cancel h]
        _ = (e * d - b * f) / (a * d - b * c) := by rw [hx]
    · calc y' = (a * d - b * c) * y' / (a * d - b * c) := by
            rw [Rat.mul_comm, Rat.mul_div_cancel h]
        _ = (a * f - e * c) / (a * d - b * c) := by rw [hy]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
between_solutionsLean 4Proved here from basic factsFormally verified
/-- If two points solve the linear equation `a·x + b·y = e`, so does every point
`((1 − t)·x₁ + t·x₂, (1 − t)·y₁ + t·y₂)` on the line through them:
the left side becomes `(1 − t)·e + t·e = e`. Applied to each equation of a system, this shows
that a system with two solutions has a whole line of solutions. -/
theorem between_solutions (a b e x₁ y₁ x₂ y₂ t : Rat)
    (h₁ : a * x₁ + b * y₁ = e) (h₂ : a * x₂ + b * y₂ = e) :
    a * ((1 - t) * x₁ + t * x₂) + b * ((1 - t) * y₁ + t * y₂) = e :=
  calc a * ((1 - t) * x₁ + t * x₂) + b * ((1 - t) * y₁ + t * y₂)
      = (1 - t) * (a * x₁ + b * y₁) + t * (a * x₂ + b * y₂) := by grind
    _ = (1 - t) * e + t * e := by rw [h₁, h₂]
    _ = e := by grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor
between_points_distinctLean 4Proved here from basic factsFormally verified
/-- Different values of `t` give different points, as long as the two starting points differ.
So "two different solutions" really does give **infinitely many**: one for each number `t`. -/
theorem between_points_distinct (x₁ y₁ x₂ y₂ s t : Rat) (hne : (x₁, y₁) ≠ (x₂, y₂))
    (hst : s ≠ t) :
    ((1 - s) * x₁ + s * x₂, (1 - s) * y₁ + s * y₂) ≠
      ((1 - t) * x₁ + t * x₂, (1 - t) * y₁ + t * y₂) := by
  intro heq
  simp only [Prod.mk.injEq] at heq
  obtain ⟨hx, hy⟩ := heq
  have hst' : s - t ≠ 0 := fun h0 => hst (by grind)
  have hx' : (s - t) * (x₂ - x₁) = 0 := by grind
  have hy' : (s - t) * (y₂ - y₁) = 0 := by grind
  have ex : x₂ - x₁ = 0 := (Rat.mul_eq_zero.mp hx').resolve_left hst'
  have ey : y₂ - y₁ = 0 := (Rat.mul_eq_zero.mp hy').resolve_left hst'
  exact hne (by rw [show x₁ = x₂ by grind, show y₁ = y₂ by grind])
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/LinearRelationships.leanTry it in the Lean web editor

What is formalised: every theorem of this lesson, over the rational numbers, including both halves of the "one, none or infinitely many" argument. Routine rearrangements are closed by grind, a decision procedure for such algebra. Mathlib treats the same ideas far more generally — lines as affine subspaces, systems as matrices, and Cramer's rule as Matrix.cramer — which you will meet in linear algebra.

ComputationC

Tables and systems by computer

Linear tables and systems: one, none or infinitely manyPythonExact computationExhaustive finite checkComputationally tested
"""Linear relationships in tables, and systems of two linear equations.

Part 1 decides, with exact fractions, whether a table of values comes from a
linear relationship y = m*x + b (constant slope between all pairs of
consecutive points) and whether it is proportional (b = 0). Part 2 solves
the lesson's systems by elimination and checks each solution. Part 3 goes
through EVERY system a*x + b*y = e, c*x + d*y = f with all six coefficients
in -2..2 (15,625 systems) and sorts them into one solution, no solution and
infinitely many - finding no other possibility, as the lesson proves.
"""

from fractions import Fraction as F
from itertools import product

#: name -> list of (x, y) pairs
TABLES = {
    "taxi fare (km, soles)": [(0, 5), (1, 7), (2, 9), (5, 15)],
    "Celsius -> Fahrenheit": [(-40, -40), (0, 32), (25, 77), (100, 212)],
    "rice, kg -> rupees": [(1, 60), (2, 120), (5, 300), (8, 480)],
    "square: side -> area": [(1, 1), (2, 4), (3, 9), (4, 16)],
}

#: name -> (a, b, e, c, d, f) meaning a*x + b*y = e and c*x + d*y = f
SYSTEMS = {
    "chickens and rabbits": (1, 1, 35, 2, 4, 94),
    "y = 1.8x + 32, y = x": (F(-9, 5), 1, 32, -1, 1, 0),
    "x + y = 3, 2x + 2y = 10": (1, 1, 3, 2, 2, 10),
    "x + 2y = 4, 2x + 4y = 8": (1, 2, 4, 2, 4, 8),
}

def slope(p, q):
    """Exact slope between points p and q (with different x-coordinates)."""
    (x1, y1), (x2, y2) = p, q
    if x1 == x2:
        raise ValueError("vertical: slope undefined")
    return F(y2 - y1) / F(x2 - x1)

def linear_fit(points):
    """Return (m, b) if all points lie on one line y = m*x + b, else None."""
    slopes = {slope(p, q) for p, q in zip(points, points[1:])}
    if len(slopes) != 1:
        return None
    m = slopes.pop()
    x0, y0 = points[0]
    return m, F(y0) - m * x0

def line_text(m, b):
    """Readable equation y = mx + b, e.g. 'y = (9/5)x + 32' or 'y = 60x'."""
    slope_part = f"{m}x" if m.denominator == 1 else f"({m})x"
    if b == 0:
        return f"y = {slope_part}"
    sign = "+" if b > 0 else "-"
    return f"y = {slope_part} {sign} {abs(b)}"

def classify(a, b, e, c, d, f):
    """Classify a*x + b*y = e, c*x + d*y = f.

    Returns ("one", (x, y)), ("none", None) or ("infinite", None).
    """
    det = F(a) * d - F(b) * c
    if det != 0:
        x = (F(e) * d - F(b) * f) / det
        y = (F(a) * f - F(e) * c) / det
        return "one", (x, y)
    if a == b == c == d == 0:
        return ("infinite", None) if e == f == 0 else ("none", None)
    # Rank 1: consistent exactly when the augmented minors vanish too.
    if F(a) * f - F(c) * e == 0 and F(b) * f - F(d) * e == 0:
        return "infinite", None
    return "none", None

def check(a, b, e, c, d, f, x, y):
    """Does (x, y) satisfy both equations exactly?"""
    return a * x + b * y == e and c * x + d * y == f

def census(values):
    """Classify every system with all six coefficients in ``values``."""
    counts = {"one": 0, "none": 0, "infinite": 0}
    bad = 0
    for a, b, e, c, d, f in product(values, repeat=6):
        kind, sol = classify(a, b, e, c, d, f)
        counts[kind] += 1
        if kind == "one" and not check(a, b, e, c, d, f, *sol):
            bad += 1
    return counts, bad

def main():
    print("1. Is the table linear (one slope between consecutive points)?")
    for name, points in TABLES.items():
        fit = linear_fit(points)
        if fit is None:
            print(f"   {name:<23} not linear: slopes vary")
        else:
            m, b = fit
            kind = "proportional" if b == 0 else "linear, not proportional"
            print(f"   {name:<23} {line_text(m, b)}   ({kind})")
    print()
    print("2. Systems solved by elimination")
    for name, coeffs in SYSTEMS.items():
        kind, sol = classify(*coeffs)
        if kind == "one":
            ok = "checks" if check(*coeffs, *sol) else "FAILS"
            text = f"x = {sol[0]}, y = {sol[1]}  ({ok})"
        else:
            text = {"none": "no solution", "infinite": "infinitely many"}[kind]
        print(f"   {name:<24} {text}")
    print()
    counts, bad = census(range(-2, 3))
    total = sum(counts.values())
    print(f"3. All {total} systems with coefficients in -2..2:")
    for kind in ("one", "none", "infinite"):
        share = 100 * counts[kind] / total
        print(f"   {kind:<9} solution(s): {counts[kind]:>6}  ({share:.1f}%)")
    print(f"   unique solutions failing the substitution check: {bad}")
    print()
    print("Epistemic status: parts 1 and 2 are exact rational arithmetic, and")
    print("every solution is checked by substitution. Part 3 is an exhaustive")
    print("check of finitely many systems; the lesson proves for ALL systems")
    print("that one, none and infinitely many are the only possibilities.")

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

About four systems in five have exactly one solution: the determinant ad−bcad - bc is usually not zero. The rest have none or infinitely many, and the program never met any other case — a finite confirmation of what the theorem proves for every system. Every unique solution was also checked by substituting it back into both equations.

Explore

Explore: two lines

The plot starts with the thermometer puzzle: y=1.8x+32y = 1.8x + 32 (Fahrenheit) and y=xy = x (the same number). The marked point is where the lines meet.

Where do two lines meet?

Starts at F = 1.8C + 32 and F = C.

meeting point
  • y = m₁x + b₁
  • y = m₂x + b₂
  • y = m₁x + b₁: y = 33.8
  • y = m₂x + b₂: y = 1

Things to try:

  • Make the two slopes equal. What happens to the meeting point? Now make the intercepts equal too.
  • Keep m1=1.8m_1 = 1.8 and change b1b_1. How does the meeting point move? Can you predict it with the formula x=b2−b1m1−m2x = \frac{b_2 - b_1}{m_1 - m_2}?
  • Make one slope positive and the other negative. Can such lines ever be parallel?
Exercises

Exercises

1. Linear relationships and simultaneous equations

Warm-upHuman

Find the slope of the line through (−2,7)(-2, 7) and (4,−11)(4, -11).

2. Linear relationships and simultaneous equations

Warm-upHuman

What is the slope of the line through (2,−1)(2, -1) and (2,5)(2, 5)?

Choose one

3. Linear relationships and simultaneous equations

CoreHuman

The line y=−2x+by = -2x + b passes through the point (3,1)(3, 1). What is bb?

4. Linear relationships and simultaneous equations

CoreHuman

Which is the equation of the line through (1,4)(1, 4) and (3,10)(3, 10)?

Choose one

5. Linear relationships and simultaneous equations

CoreHuman

Which of these relationships are proportional? (Choose all that apply.)

Choose all that apply

6. Linear relationships and simultaneous equations

CoreHuman

At a market in Nairobi, 33 mangoes and 22 avocados cost 160160 shillings, while 11 mango and 22 avocados cost 8080 shillings. How much does one mango cost, in shillings?

7. Linear relationships and simultaneous equations

CoreHuman

How many solutions does the system 2x−y=32x - y = 3,   6x−3y=8\;6x - 3y = 8 have?

Choose one

8. Linear relationships and simultaneous equations

CoreFormal

Which Lean statement says "the slope between any two points of the line y=mx+by = mx + b is mm"? (Here slope x₁ y₁ x₂ y₂ is (y₂ - y₁) / (x₂ - x₁), and Lean defines division by zero to give 00.)

Choose one

9. Linear relationships and simultaneous equations

StretchComputational

Write fit_line(points) for a list of points (x, y) with distinct xx-values. If all the points lie on one line y=mx+by = mx + b, return the pair (m, b) as Fractions; otherwise return None. (Use exact fractions, not floats.)

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

10. Linear relationships and simultaneous equations

StretchHuman

Let f(x)=3x+2f(x) = 3x + 2 and g(x)=2x−5g(x) = 2x - 5. The function x↦g(f(x))x \mapsto g(f(x)) (first ff, then gg) is linear. What is its yy-intercept?

Common misconceptionsH

Common misconceptions

Misconception

Slope as "run over rise". Slope is riserun=y2−y1x2−x1\dfrac{\text{rise}}{\text{run}} = \dfrac{y_2 - y_1}{x_2 - x_1}: change in yy divided by change in xx. Upside down, the line through (0,0)(0, 0) and (1,3)(1, 3) would get slope 13\tfrac{1}{3} — but it climbs 33 for every 11 across, so its slope is 33.

Misconception

"Every straight-line relationship is proportional." Only lines through the origin are. The taxi fare y=2x+5y = 2x + 5 is linear, but 22 km costs 99 soles while 44 km costs 1313, not 1818. Doubling the input doubles the output only when b=0b = 0.

Misconception

"A vertical line has slope zero." A horizontal line has slope 00: its rise is 00. A vertical line has run 00, and division by 00 is undefined, so a vertical line has no slope. (Its equation is x=cx = c, which is not of the form y=mx+by = mx + b.)

Misconception

Mixing the order of subtraction. y2−y1x1−x2\dfrac{y_2 - y_1}{x_1 - x_2} gives the wrong sign. Either order of the points is fine, but use the same order on top and bottom.

Misconception

"A system of two equations always has exactly one solution." Parallel lines give none, and two equations describing the same line give infinitely many. What can never happen is exactly two solutions.

ViewpointsH

Other ways of seeing

Geometry— Similar triangles and parallel lines

Slope is a geometric invariant: every slope triangle on a line has the same shape, so the ratio rise ÷ run is the same. Parallel lines are lines with the same slope, and the formula y=mx+(y1−mx1)y = mx + (y_1 - m x_1) shows that through any point there is exactly one line parallel to a given non-vertical line. That is the coordinate version of the parallel postulate of Euclid's geometry — a statement that, astonishingly, fails in the non-Euclidean geometries of the sphere and the hyperbolic plane (see non-Euclidean geometry).

Algebra— Elimination becomes linear algebra

Elimination works because we may add multiples of equations to each other without changing the solutions. With many equations and many unknowns, doing this systematically is Gaussian elimination, and the coefficients arranged in a rectangle form a matrix. The number ad−bcad - bc is the determinant of the matrix (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}; geometrically, it measures how the map (x,y)↦(ax+by, cx+dy)(x, y) \mapsto (ax + by,\, cx + dy) scales areas, which is why it is zero exactly when the system fails to have a unique solution. This is the beginning of linear algebra.

Category theory— Linear functions compose

Doing x↦m2x+b2x \mapsto m_2 x + b_2 and then x↦m1x+b1x \mapsto m_1 x + b_1 gives x↦m1m2 x+(m1b2+b1)x \mapsto m_1 m_2\, x + (m_1 b_2 + b_1) — another linear function, whose slope is the product of the slopes. Converting Celsius to Fahrenheit and Fahrenheit to Kelvin, for instance, composes into one linear conversion. Every linear function with m≠0m \neq 0 can be undone: the inverse of x↦mx+bx \mapsto mx + b is x↦x−bmx \mapsto \tfrac{x - b}{m}. Linear functions with non-zero slope, under composition, are a first example of a structure that mathematicians call a group (see chaining functions).

Wonder Trails

Wonder Trail

Chaining functions — and what is special about doing one thing after another — is the theme of this trail. It is written for older students, but the first steps follow directly from the composition of linear functions above.

Wonder Trail · Optional · never gradedArrows that composeWhat do functions between sets, maps between groups and continuous maps between shapes have in common? What if we studied only the arrows?Follow the trail
History & global context

History and global context

  • Chapter 8 of the Chinese Nine Chapters on the Mathematical Art, Fangcheng ("rectangular arrays"), solves systems of several linear equations in several unknowns. The coefficients were laid out as columns of counting rods on a board and combined column by column — the method we now call Gaussian elimination, more than 1,500 years before Gauss. The same chapter states rules for calculating with negative numbers, which elimination needs.
  • The Sunzi Suanjing ("Master Sun's Mathematical Manual", China, between the 3rd and 5th centuries CE) contains the pheasants-and-rabbits problem. In Japan it later became tsurukamezan, the "crane and turtle calculation", still a favourite in schools.
  • In the 1630s, Pierre de Fermat and René Descartes independently connected algebra with geometry through coordinates. Fermat showed that every equation of the first degree in two unknowns describes a straight line — which is why such equations are called linear.
  • Determinants appeared in the work of Seki Takakazu in Japan (1683) and, independently, Gottfried Wilhelm Leibniz in Germany (1693). Gabriel Cramer published the general formula for solving systems with determinants in 1750.
Further reading

Further reading

  • I. M. Gelfand, E. G. Glagoleva and A. A. Kirillov, The Method of Coordinates (English edition 1990) — a short, beautiful book on points, lines and equations.
  • I. M. Gelfand and A. Shen, Algebra (1993).
  • Kangshen Shen, John N. Crossley and Anthony W.-C. Lun, The Nine Chapters on the Mathematical Art: Companion and Commentary (1999) — including the fangcheng method.
  • Victor J. Katz, A History of Mathematics: An Introduction (3rd edition, 2009).