The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V07. Linear algebra

Mathlib.Algebra.LinearRecurrence

25 declarations. Mathlib docs · Source

Linear recurrence

Informally, a "linear recurrence" is an assertion of the form ∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1), where u is a sequence, d is the order of the recurrence and the a i are its coefficients.

In this file, we define the structure LinearRecurrence so that LinearRecurrence.mk d a represents the above relation, and we call a sequence u which verifies it a solution of the linear recurrence.

We prove a few basic lemmas about this concept, such as :

  • the space of solutions is a submodule of (ℕ → α) (i.e a vector space if α is a field)
  • the function that maps a solution u to its first d terms builds a LinearEquiv between the solution space and Fin d → α, aka α ^ d. As a consequence, two solutions are equal if and only if their first d terms are equal.
  • a geometric sequence q ^ n is solution iff q is a root of a particular polynomial, which we call the characteristic polynomial of the recurrence

Of course, although we can inductively generate solutions (cf mkSol), the interesting part would be to determine closed-forms for the solutions. This is currently not implemented, as we are waiting for definition and properties of eigenvalues and eigenvectors.

E.tupleSucc maps ![s₀, s₁, ..., sₙ] to ![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ], where n := E.order. This operation is quite useful for determining closed-form solutions of E.

theorem LinearRecurrence.mk.inj E1 #

∀ {R : Type u_1} {inst : CommSemiring R} {order : ℕ} {coeffs : Fin order → R} {order_1 : ℕ}
  {coeffs_1 : Fin order_1 → R},
  { order := order, coeffs := coeffs } = { order := order_1, coeffs := coeffs_1 } → order = order_1 ∧ coeffs ≍ coeffs_1

theorem LinearRecurrence.mk.injEq E0 #

∀ {R : Type u_1} [inst : CommSemiring R] (order : ℕ) (coeffs : Fin order → R) (order_1 : ℕ)
  (coeffs_1 : Fin order_1 → R),
  ({ order := order, coeffs := coeffs } = { order := order_1, coeffs := coeffs_1 }) =
    (order = order_1 ∧ coeffs ≍ coeffs_1)

def LinearRecurrence.ctorIdx E1 #

{R : Type u_1} → {inst : CommSemiring R} → LinearRecurrence R → ℕ

structure LinearRecurrence E1 #

(R : Type u_1) → [CommSemiring R] → Type u_1

A "linear recurrence relation" over a commutative semiring is given by its order n and n coefficients.

ctor LinearRecurrence.mk E0 #

{R : Type u_1} → [inst : CommSemiring R] → (order : ℕ) → (Fin order → R) → LinearRecurrence R

abbrev LinearRecurrence.order E1 #

{R : Type u_1} → [inst : CommSemiring R] → LinearRecurrence R → ℕ

Order of the linear recurrence

abbrev LinearRecurrence.coeffs E1 #

{R : Type u_1} → [inst : CommSemiring R] → (self : LinearRecurrence R) → Fin self.order → R

Coefficients of the linear recurrence

instance instInhabitedLinearRecurrence E0 #

(R : Type u_1) → [inst : CommSemiring R] → Inhabited (LinearRecurrence R)

def LinearRecurrence.IsSolution E1 #

{R : Type u_1} → [inst : CommSemiring R] → LinearRecurrence R → (ℕ → R) → Prop

We say that a sequence u is solution of LinearRecurrence order coeffs when we have u (n + order) = ∑ i : Fin order, coeffs i * u (n + i) for any n.

def LinearRecurrence.mkSol E1 #

{R : Type u_1} → [inst : CommSemiring R] → (E : LinearRecurrence R) → (Fin E.order → R) → ℕ → R

A solution of a LinearRecurrence which satisfies certain initial conditions. We will prove this is the only such solution.

theorem LinearRecurrence.is_sol_mkSol E1 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R) (init : Fin E.order → R), E.IsSolution (E.mkSol init)

E.mkSol indeed gives solutions to E.

theorem LinearRecurrence.mkSol_eq_init E1 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R) (init : Fin E.order → R) (n : Fin E.order),
  E.mkSol init ↑n = init n

E.mkSol init's first E.order terms are init.

def LinearRecurrence.solSpace E1 #

{R : Type u_1} → [inst : CommSemiring R] → LinearRecurrence R → Submodule R (ℕ → R)

The space of solutions of E, as a Submodule over R of the module ℕ → R.

theorem LinearRecurrence.is_sol_iff_mem_solSpace E1 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R) (u : ℕ → R), E.IsSolution u ↔ u ∈ E.solSpace

Defining property of the solution space : u is a solution iff it belongs to the solution space.

def LinearRecurrence.toInit E1 #

{R : Type u_1} → [inst : CommSemiring R] → (E : LinearRecurrence R) → ↥E.solSpace ≃ₗ[R] Fin E.order → R

The function that maps a solution u of E to its first E.order terms as a LinearEquiv.

theorem LinearRecurrence.mkSol_injective E1 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R), Function.Injective E.mkSol

def LinearRecurrence.basis E1 #

{R : Type u_1} → [inst : CommSemiring R] → (E : LinearRecurrence R) → Module.Basis (Fin E.order) R ↥E.solSpace

A basis of the solution space given by solutions whose initial conditions are the standard basis vectors

theorem LinearRecurrence.repr_basis_eq E0 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R) (u : ↥E.solSpace),
  E.basis.repr u = Finsupp.ofSupportFinite (↑u ∘ Fin.val) ⋯

The coordinates of a solution in the basis are its first E.order values

theorem LinearRecurrence.repr_basis_apply E0 #

∀ {R : Type u_1} [inst : CommSemiring R] (E : LinearRecurrence R) (u : ↥E.solSpace) (n : Fin E.order),
  (E.basis.repr u) n = ↑u ↑n

The nth coordinate of a solution in the basis equals its nth value

def LinearRecurrence.tupleSucc E1 #

{R : Type u_1} → [inst : CommSemiring R] → (E : LinearRecurrence R) → (Fin E.order → R) →ₗ[R] Fin E.order → R

E.tupleSucc maps ![s₀, s₁, ..., sₙ] to ![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ], where n := E.order.

theorem LinearRecurrence.solSpace_rank E1 #

∀ {R : Type u_1} [inst : CommRing R] [StrongRankCondition R] (E : LinearRecurrence R),
  Module.rank R ↥E.solSpace = ↑E.order

The dimension of E.solSpace is E.order.

def LinearRecurrence.charPoly E1 #

{R : Type u_1} → [inst : CommRing R] → LinearRecurrence R → Polynomial R

The characteristic polynomial of E is X ^ E.order - ∑ i : Fin E.order, (E.coeffs i) * X ^ i.

theorem LinearRecurrence.charPoly_degree_eq_order E0 #

∀ {R : Type u_1} [inst : CommRing R] (E : LinearRecurrence R) [Nontrivial R], E.charPoly.degree = ↑E.order

theorem LinearRecurrence.charPoly_monic E1 #

∀ {R : Type u_1} [inst : CommRing R] (E : LinearRecurrence R), E.charPoly.Monic

theorem LinearRecurrence.geom_sol_iff_root_charPoly E1 #

∀ {R : Type u_1} [inst : CommRing R] (E : LinearRecurrence R) (q : R),
  (E.IsSolution fun n ↦ q ^ n) ↔ E.charPoly.IsRoot q

The geometric sequence q^n is a solution of E iff q is a root of E's characteristic polynomial.