← back to discrete math

Sequences

Oscar Levin · CC BY-SA 4.0 · Discrete Mathematics: An Open Introduction, Ch. 2

A sequence is a function from the naturals to some codomain. The interesting question is never "what is the next term?" but "what is the closed form?" Recurrence relations define sequences by self-reference. Solving them means eliminating the self-reference. Induction proves the solution is correct.

n=0 n=1 n=2 n=k n=k+1 base case inductive step

Arithmetic sequences

Each term differs from the previous by a constant d. The closed form is a(n) = a(0) + dn. The sum of the first n terms is n(a(0) + a(n))/2. These are linear functions in disguise.

Scheme

Geometric sequences

Each term is the previous multiplied by a constant ratio r. The closed form is a(n) = a(0) * r^n. The partial sum is a(0)(r^n - 1)/(r - 1) when r is not 1. Exponential growth lives here.

Scheme

Recurrence relations

A recurrence defines each term using previous terms. The Fibonacci sequence is the classic: F(n) = F(n-1) + F(n-2). A linear homogeneous recurrence with constant coefficients can be solved by finding roots of its characteristic equation. The characteristic root technique turns a recursive definition into a closed formula.

Scheme

Solving recurrences: the characteristic root method

For a(n) = c1*a(n-1) + c2*a(n-2), guess a(n) = r^n. Substituting gives r^2 = c1*r + c2. Solve this quadratic for r. If you get two distinct roots r1 and r2, the general solution is a(n) = A*r1^n + B*r2^n, where A and B come from initial conditions.

Scheme

Proof by induction

Induction proves a statement P(n) for all n >= 0. Prove P(0) (base case). Then prove that P(k) implies P(k+1) (inductive step). The domino analogy: knock over the first, and every domino falls. Here we verify (not prove, since programs check instances) the classic sum formula.

Scheme

Notation reference

Math Scheme Python Meaning
a(n) = a(0) + dn(arith a0 d n)a0 + d*nArithmetic closed form
a(n) = a(0) * r^n(geom a0 r n)a0 * r**nGeometric closed form
r^2 = c1*r + c2solve by handsolve by handCharacteristic equation
P(0) and P(k) implies P(k+1)verify instancesverify instancesInduction
Neighbors

Other chapter pages

  • Milewski Ch.19 โ€” F-algebras and catamorphisms: recursion as a categorical pattern
  • Levin Ch.5 โ€” generating functions encode sequences as formal power series

Foundations (Wikipedia)

Translation notes

Levin treats sequences as functions from naturals. The Scheme implementations use iterative loops where possible to avoid stack overflow on large inputs. The characteristic root method is demonstrated but the algebra (solving quadratics, plugging in initial conditions) happens by hand. Programs verify the result, they do not derive it.