Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.PolyTime.Nat

Polynomial-time arithmetic on unary counters #

Arithmetic on encUnary, built from Christian Reitwiessner's encodings and machine calculus. Addition concatenates the unary words; multiplication folds addition while keeping a quadratic bound on the accumulator. Fixed powers and fixed polynomials follow by composition. These operations support polynomially bounded counters and list enumeration in reductions.

Main results #

References #

The indexed bound is adapted from Cslib/Computability/Probabilistic/Encoding.lean on the cslib crypto branch at 5ff69ca93402e7c947208dc56396d6d86203ccd8.

A unary-output polynomial-time function is polynomially bounded in its unary input.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.indexed_polynomial_bound {f : ℕ → ℕ → ℕ} {count : ℕ → ℕ} (hf : ComputableTidilyInPolyTime (fun (input : ℕ × ℕ) => f input.1 input.2) (encPair encUnary encUnary) encUnary) (hcount : Cslib.PolynomiallyBounded count) :
∃ (c : ℕ) (d : ℕ), ∀ (n i : ℕ), i < count n → f n i ≤ c * (n + 1) ^ d

Efficient unary values share a polynomial bound over a polynomially bounded range of indices. Selecting an index does not require a computable choice.

Addition of unary naturals, by concatenating their encodings.

Multiplication of unary naturals, by repeated addition.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.unary_le' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableTidilyInPolyTime left input encUnary) (hright : ComputableTidilyInPolyTime right input encUnary) :
ComputableTidilyInPolyTime (fun (a : α) => decide (left a ≤ right a)) input encBool

Compare computed unary values, fixing their intermediate encodings before proof search.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.unary_lt' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableTidilyInPolyTime left input encUnary) (hright : ComputableTidilyInPolyTime right input encUnary) :
ComputableTidilyInPolyTime (fun (a : α) => decide (left a < right a)) input encBool

Strictly compare computed unary values, with both operand encodings fixed.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.unary_beq {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableTidilyInPolyTime left input encUnary) (hright : ComputableTidilyInPolyTime right input encUnary) :
ComputableTidilyInPolyTime (fun (a : α) => left a == right a) input encBool

Equality of computed unary counters, fixing the intermediate encoding for proof search.

The natural-number pairing function, with both arguments and the result in unary.

Evaluate a fixed polynomial on unary naturals, with its result also in unary.

Convert a unary natural to its binary encoding by incrementing a binary counter.

Plain polynomial-time automation #

Addition of unary naturals, by concatenating their encodings.

Evaluate a fixed polynomial on unary naturals, with its result also in unary.

Multiplication of unary naturals, by repeated addition.

theorem Turing.MultiTapeTM.ComputableInPolyTime.unary_add' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableInPolyTime left input encUnary) (hright : ComputableInPolyTime right input encUnary) :
ComputableInPolyTime (fun (a : α) => left a + right a) input encUnary

Add two computed unary naturals with the same full input context.

theorem Turing.MultiTapeTM.ComputableInPolyTime.unary_sub' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableInPolyTime left input encUnary) (hright : ComputableInPolyTime right input encUnary) :
ComputableInPolyTime (fun (a : α) => left a - right a) input encUnary

Subtract two computed unary naturals with the same full input context.

theorem Turing.MultiTapeTM.ComputableInPolyTime.unary_mul' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableInPolyTime left input encUnary) (hright : ComputableInPolyTime right input encUnary) :
ComputableInPolyTime (fun (a : α) => left a * right a) input encUnary

Multiply two computed unary naturals with the same full input context.

A fixed power of a unary natural.