proofs, primes,
& the patterns hiding in numbers
a visual reference for induction, divisibility, recursion, and linear recurrence relations. every concept shows its shape. every symbol earns its keep.
mathematical induction
a two-step proof machine. prove it works for the first case. prove each case implies the next. logic does the rest. this is the domino effect written in math.
every induction proof is a line of dominos
to prove infinitely many statements, you only need to prove two things:
- base case — push the first domino (prove P(1) directly)
- inductive step — show each domino knocks the next (if P(k) is true, then P(k+1) is true)
if both hold, every domino falls. that's the whole trick.
prove: 1 + 2 + 3 + ... + n = n(n+1)/2
click through each step of the proof. watch how the inductive hypothesis becomes the bridge from k to k+1.
every induction proof has the same skeleton
master the skeleton. the only part that changes problem-to-problem is the algebra in the inductive step.
the inductive hypothesis (IH)
the load-bearing assumption. when you write "assume P(k) is true," that assumption IS the inductive hypothesis. it's the tool you use to reach P(k+1).
a temporary assumption
you assume P(k) is true for some arbitrary k. you don't prove it — you just borrow it. then you use that assumption to prove P(k+1).
it's NOT circular reasoning. the base case is the real starting point. the IH just says: "if the chain hasn't broken by step k, it won't break at step k+1 either."
forgetting to use it
if your proof of P(k+1) never references P(k), you're not doing induction — you're just proving each case directly. the IH is the hinge. if you don't use it, the proof isn't valid induction.
every time you substitute or simplify in the inductive step, ask: "did i just use the IH?" if not, you probably need to.
prime numbers
a prime is a natural number greater than 1 whose only positive divisors are 1 and itself. primes are the atomic elements of the integers — every other integer is built from them.
watch primes emerge from the natural numbers
start with 2. circle it (prime). cross out every multiple of 2. move to the next uncircled number (3). circle it. cross out its multiples. repeat. survivors are primes.
key facts
- 1 is NOT prime — primes must be greater than 1
- 2 is the only even prime — every other even number is divisible by 2
- fundamental theorem of arithmetic — every integer > 1 has a unique prime factorization (up to order)
- there are infinitely many primes — proved by euclid around 300 BC
greatest common divisor
the gcd of two integers is the largest number that divides both of them. written gcd(a, b). the euclidean algorithm finds it in logarithmic time using just repeated remainders.
gcd(a, b) = gcd(b, a mod b)
keep replacing the larger number with the remainder until one side becomes 0. the other side is your gcd.
why it works (intuition)
if d divides both a and b, then d also divides (a - b), and more generally (a mod b). so the set of common divisors doesn't change when we swap (a, b) for (b, a mod b). the numbers shrink, but the gcd is invariant. eventually we hit 0, and whatever's left is the answer.
least common multiple
the lcm of two integers is the smallest positive number that BOTH divide into. it's the gcd's dual — and they're connected by one of the cleanest formulas in number theory.
lcm(a, b) · gcd(a, b) = a · b
once you know the gcd, the lcm is free. example with a=12 and b=18:
prime-factorization way (visual)
| number | factorization |
|---|---|
| 12 | 2² · 3 |
| 18 | 2 · 3² |
| gcd | 2¹ · 3¹ = 6 (take the MIN exponent for each prime) |
| lcm | 2² · 3² = 36 (take the MAX exponent for each prime) |
recursion
recursion is defining something in terms of smaller versions of itself. every recursion has two parts: base case (where it stops) and recursive case (where it calls itself).
factorial: n! = n · (n-1)!
to compute 5!, we compute 5 · 4!, which needs 4!, which needs 3!, ... all the way down to the base case. then the answers unwind back up.
descend first the call stack grows as we hit the recursive case over and over. ascend then the base case triggers and answers climb back up.
recursion always needs a base case
without a base case, recursion never stops. in code this is a stack overflow. in math it's a definition that doesn't actually define anything. base case = the terminator.
recursive definitions
a recursive definition builds an object by saying (1) what the smallest cases look like, and (2) how to build larger cases from smaller ones. it's induction's twin — both work on the same domino logic, just pointed in different directions.
2ⁿ defined recursively
first few terms: 1, 2, 4, 8, 16, 32, ...
each term is the sum of the two before it
first few terms: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
definitions aren't just for sequences
you can define an entire set of objects recursively. example: the set S of all even non-negative integers.
the exclusion clause matters — without it, you could argue anything is in S. standard practice in formal definitions.
linear recurrence relations
a recurrence relation expresses aₙ in terms of earlier terms. LINEAR means the earlier terms appear to the first power — no squaring, no multiplying terms together, no weird functions of them.
a linear recurrence looks like this:
each aₙ₋ᵢ shows up exactly once, to the first power, multiplied by some coefficient. f(n) is an optional "forcing" term (if it's 0, the recurrence is homogeneous — see next sections).
linear vs NOT linear
the order of a recurrence
order = how far back you need to look. if aₙ depends on aₙ₋₁, it's order 1. if it depends on aₙ₋₁ and aₙ₋₂, it's order 2. simple as that.
| recurrence | depends on | order |
|---|---|---|
| aₙ = 3aₙ₋₁ | aₙ₋₁ | 1 |
| Fₙ = Fₙ₋₁ + Fₙ₋₂ | previous two | 2 |
| aₙ = aₙ₋₁ + 2aₙ₋₃ | aₙ₋₁ and aₙ₋₃ | 3 |
| aₙ = 5aₙ₋₁ − 6aₙ₋₂ + aₙ₋₄ | aₙ₋₁, aₙ₋₂, aₙ₋₄ | 4 |
rule: order = largest index gap between aₙ and the earliest term on the right-hand side. an order-k recurrence needs k initial conditions (a₀ through aₖ₋₁, or similar) to be fully determined.
homogeneous
a recurrence is homogeneous when there's no "extra" term. every piece of the equation involves aₙ or earlier aₙ values. nothing else.
if everything can be moved to one side and equals 0 — it's homogeneous
constant coefficients (CC)
the numbers multiplying aₙ₋₁, aₙ₋₂, etc. are actual numbers — not functions of n.
LHCC — linear, homogeneous, constant coefficients
combine all three properties and you get an LHCC recurrence. this is the sweet spot — LHCCs are the recurrences we know how to solve in closed form using the characteristic equation.
a recurrence is LHCC if ALL three hold:
- LINEAR each aₙ₋ᵢ appears to the first power, not multiplied by each other
- HOMOGENEOUS no extra forcing term — only aₙ-subscripted pieces
- CONSTANT COEFFICIENTS the multipliers are numbers, not functions of n
canonical form of an order-k LHCC
examples
| recurrence | LHCC? | why |
|---|---|---|
| aₙ = 3aₙ₋₁ − 2aₙ₋₂ | yes | linear, homogeneous, CC — order 2 |
| Fₙ = Fₙ₋₁ + Fₙ₋₂ | yes | fibonacci is LHCC, order 2 |
| aₙ = 5aₙ₋₁ + 2 | no | the "+ 2" breaks homogeneity |
| aₙ = n·aₙ₋₁ | no | coefficient n is not constant |
| aₙ = aₙ₋₁² | no | not linear |
the characteristic equation
the big payoff. for any LHCC, you can turn the recurrence into a polynomial equation, solve it, and write down an exact closed-form formula for aₙ. no more computing term-by-term.
guess aₙ = rⁿ. see what r has to be.
start with an LHCC like aₙ = c₁·aₙ₋₁ + c₂·aₙ₋₂. substitute aₙ = rⁿ:
divide both sides by rⁿ⁻²:
solve this quadratic. the roots tell you the building blocks of the closed form.
solve fibonacci: Fₙ = Fₙ₋₁ + Fₙ₋₂, F₀ = 0, F₁ = 1
what the characteristic equation's roots mean
| roots of char. equation | general solution |
|---|---|
| distinct real roots r₁, r₂ | aₙ = A·r₁ⁿ + B·r₂ⁿ |
| repeated root r (mult. 2) | aₙ = (A + Bn)·rⁿ |
| three distinct roots r₁, r₂, r₃ | aₙ = A·r₁ⁿ + B·r₂ⁿ + C·r₃ⁿ |
| root r repeated m times | (A + Bn + Cn² + ... + constants·n^(m-1))·rⁿ |
the constants A, B, C, ... always come from plugging in the initial conditions (you'll need as many conditions as the order of the recurrence).
why the characteristic equation is a big deal
it turns an infinite recursive process into a finite algebraic one. instead of computing aₙ by grinding through every earlier term, you solve a polynomial once and get a formula that works for all n. for LHCCs this is guaranteed to work. for non-LHCCs (inhomogeneous, nonlinear, or variable coefficients) you need other techniques — generating functions, substitution, the "method of undetermined coefficients," or just computing term-by-term.