Documentation

CslibFrontier.Computability.BlumComplexity.Basic

Blum complexity measures #

Blum's axioms describe a complexity measure without fixing a machine model Blum, A machine-independent theory of the complexity of recursive functions. Fix an acceptable numbering φ of the partial recursive functions; here it is Mathlib's Nat.Partrec.Code with Code.eval. A complexity measure is a family Φ of partial functions, one for each program, such that

  1. Φ c n is defined exactly when φ_c n is defined, and
  2. the predicate Φ c n = m is decidable, as a predicate of (c, n, m).

Running time and space of Turing machines are the motivating examples. Cslib.BlumComplexity.fuelMeasure, in CslibFrontier.Computability.BlumComplexity.Fuel, is an instance for Mathlib's evaluator Code.evaln.

The complexity class Φ.complexityClass t of a total bound t is the class of total functions f that some program c computes with Φ c n ≤ t n for almost all n, that is, for all sufficiently large n. This is the class C_t of Borodin Borodin, Computational complexity and the existence of complexity gaps. The bound applies almost everywhere, not at every input. For each such f, finitely many inputs may exceed the bound.

Main definitions #

Main results #

References #

A Blum complexity measure [Blu67] over the acceptable numbering Nat.Partrec.Code: a cost cost c n for each program c and input n, defined exactly when c halts on n, such that the predicate m ∈ cost c n (that is, Φ c n = m) is computable.

theorem Cslib.BlumComplexity.BlumMeasure.computablePred_mem_cost_comp (Φ : BlumMeasure) {α : Type u_1} [Primcodable α] {f : α → Nat.Partrec.Code} {g h : α → ℕ} (hf : Computable f) (hg : Computable g) (hh : Computable h) :
ComputablePred fun (a : α) => h a ∈ Φ.cost (f a) (g a)

Blum's second axiom, with computable functions substituted for the program, the input and the cost.

theorem Cslib.BlumComplexity.BlumMeasure.dom_cost_of_total (Φ : BlumMeasure) {f : ℕ → ℕ} {c : Nat.Partrec.Code} (hc : ∀ (n : ℕ), f n ∈ c.eval n) (n : ℕ) :
(Φ.cost c n).Dom

A program that computes a total function has its cost defined on every input.

theorem Cslib.BlumComplexity.BlumMeasure.forall_mem_cost_iff_exists_of_total (Φ : BlumMeasure) {f : ℕ → ℕ} {c : Nat.Partrec.Code} (hc : ∀ (n : ℕ), f n ∈ c.eval n) {p : ℕ → Prop} (n : ℕ) :
(∀ m ∈ Φ.cost c n, p m) ↔ ∃ m ∈ Φ.cost c n, p m

For a program that computes a total function, a property holds of every value of its cost at n exactly when it holds of some value: the cost is defined and single-valued.

Every complexity measure is partial recursive: the least m with Φ c n = m is found by unbounded search.

theorem Cslib.BlumComplexity.BlumMeasure.computablePred_cost_le (Φ : BlumMeasure) :
ComputablePred fun (x : (Nat.Partrec.Code × ℕ) × ℕ) => match x with | ((c, n), b) => ∃ m ∈ Φ.cost c n, m ≤ b

The predicate Φ c n ≤ b is computable. In particular, whether c halts on n within cost b is decidable.

The complexity class C_t of a bound t: total functions f computed by some program c (f n ∈ c.eval n for every n) whose cost satisfies Φ c n ≤ t n for all sufficiently large n [Bor72].

theorem Cslib.BlumComplexity.BlumMeasure.mem_complexityClass {Φ : BlumMeasure} {t f : ℕ → ℕ} :
f ∈ Φ.complexityClass t ↔ ∃ (c : Nat.Partrec.Code), (∀ (n : ℕ), f n ∈ c.eval n) ∧ ∀ᶠ (n : ℕ) in Filter.atTop, ∀ m ∈ Φ.cost c n, m ≤ t n

Complexity classes are monotone in the bound, compared almost everywhere.

Complexity classes contain only computable functions.

Every computable function lies in the complexity class of some computable bound: the cost of any program computing it.