Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.InSpace.NatPow

Binary natural powers with a runtime exponent #

The base and exponent are binary naturals. Repeated multiplication keeps the immutable base and one accumulator; the iteration counter is binary. The space bound charges the possible output length, proportional to the exponent times the binary length of the base, and the binary length of the exponent. No unary charge for the base is introduced.

Main results #

theorem Turing.MultiTapeTM.ComputableInSpace.natPow :
ComputableInSpace (fun (q : ℕ × ℕ) => q.1 ^ q.2) (encPair encNat encNat) encNat fun (q : ℕ × ℕ) => (q.2 + 1) * (encNat q.1).length + (encNat q.2).length + 1

A runtime exponent is evaluated by repeated multiplication within the possible output length plus the binary counter length. The bound is valid also at base or exponent zero.

theorem Turing.MultiTapeTM.ComputableInSpace.budget_natPow_variable {α : Type} {encIn : α ↪ List Bool} {Bs a n : α → ℕ} (ha : ComputableInSpace a encIn encNat Bs) (hn : ComputableInSpace n encIn encNat Bs) (hbound : BigOLe (fun (x : α) => (n x + 1) * (encNat (a x)).length + (encNat (n x)).length + 1) Bs) :
ComputableInSpace (fun (x : α) => a x ^ n x) encIn encNat Bs

A power with a computed exponent stays within a budget covering both arguments and the possible output length. Unlike budget_natPow, the exponent here is an input-dependent value.

theorem Turing.MultiTapeTM.ComputableInSpace.budget_natPow_constBase {α : Type} {enc : α ↪ List Bool} {S n : α → ℕ} (base : ℕ) (hn : ComputableInSpace n enc encNat S) (hb : BigOLe n S) :
ComputableInSpace (fun (a : α) => base ^ n a) enc encNat S

Powers of a fixed base fit in any workspace budget that covers the exponent's value.

theorem Turing.MultiTapeTM.ComputableInSpace.budget_twoPow {α : Type} {enc : α ↪ List Bool} {S n : α → ℕ} (hn : ComputableInSpace n enc encNat S) (hb : BigOLe n S) :
ComputableInSpace (fun (a : α) => 2 ^ n a) enc encNat S

A binary power of two fits in any budget that bounds the value of its exponent.