Documentation

CslibFrontier.Computability.WordRAM.Native

Native primitive certificates and whole-run transport for WordRAM #

The width is a runtime input encoded in unary; operand values and addresses are encoded in binary (Basis.encoding). For each operation symbol, a single native machine handles every encoded width and operand tuple, returning none when an operation is undefined or overflows 2 ^ w. Left shift caps the shift count at the unary width before exponentiating (checkedShiftLeft_eq), rejecting overflow when x > 0 and y ≥ w without materializing x <<< y. Polynomial bounds are in the complete encoded input length, including the unary width, not the bit length of a binary-encoded width. Computable width selection with charged costs and input fit remain separate obligations.

Every word-RAM basis shares the same checked-constant, equality/comparison test, address, move, and control-label certificates (Basis.nativePrimitivesOfPolyTime). Supplying operation certificates yields complete GenericRAM.Model.NativePrimitives bundles and IsPolynomial proofs for Basis.standard, Basis.additive, Basis.arithmetic, and Basis.exact, as well as arbitrary sub-bases (Basis.restrict) and homomorphic preimages (Basis.Hom.checkedOp_polyTime).

Via WordRAM.Program.toGeneric, halting WordRAM.Executes runs correspond to halting GenericRAM.FiniteState.run executions and inherit whole-run native transport (WordRAM.transportCertificate, WordRAM.transport_inO, WordRAM.transport_polyTime, and WordRAM.transport_polyTime_of_le_const) whenever a NativePrimitives bundle is supplied for B.genericModel.

Main definitions #

Main results #

References #

Uses Christian Reitwiessner's binary natural encodings and native machine arithmetic through the library's polynomial-time calculus.

Binary encodings for word values and addresses, with the runtime word width encoded in unary.

@[reducible, inline]
noncomputable abbrev Cslib.WordRAM.encWidthOperands {k : ℕ} :

Input encoding of the word-RAM operation and test primitives: the runtime word width in unary (encUnary, framed) followed by the k operands in binary (encPi encNat: a framed list in encPi's fixed index order, given by Fintype.equivFin (Fin k)). It is encPair B.encoding.config (encPi B.encoding.value), the input encoding of GenericRAM.Model.NativePrimitives, for every basis B.

All word-RAM generic tests (eq, lt, and the faulting test none) are polynomial-time at every encoded width.

theorem Cslib.WordRAM.checkedShiftLeft_eq (w x y : ℕ) :
(if decide (Fits w (x <<< y)) = true then some (x <<< y) else none) = if decide (Fits w (x * 2 ^ min w y)) = true then some (x * 2 ^ min w y) else none

Left shift fits a w-bit word if and only if shifting by min w y fits, and when it fits both shifts produce the same word. This avoids materializing x <<< y when y > w.

Every operation in Basis.exact has a polynomial-time checked implementation, preserving exact subtraction-underflow and zero-divisor faults.

Package a complete NativePrimitives bundle for a word-RAM basis from polynomial-time certificates for its operations.

Complete native scalar primitive bundle for Basis.standard.

The standard word-RAM primitive bundle has polynomial time and space bounds in all fields.

Complete native scalar primitive bundle for Basis.additive.

The additive word-RAM primitive bundle has polynomial time and space bounds in all fields.

Complete native scalar primitive bundle for Basis.arithmetic.

The arithmetic word-RAM primitive bundle has polynomial time and space bounds in all fields.

Complete native scalar primitive bundle for Basis.exact.

The exact word-RAM primitive bundle has polynomial time and space bounds in all fields.

Whole-run transport adapter #

theorem Cslib.WordRAM.executes_iff_exists_finiteRun {B : Basis} {r : ℕ} (w : ℕ) (p : Program B r) (s : GenericRAM.FiniteState B.genericModel r) (u : State r) (hden : s.denote = State.toGeneric B u) (v : ℕ) :
(∃ (m : ℕ), Executes w p u v m) ↔ ∃ (n : ℕ), GenericRAM.FiniteState.run w p.toGeneric n s = some (Sum.inr v)

Halting WordRAM.Executes runs correspond to halting FiniteState.run executions of p.toGeneric.

noncomputable def Cslib.WordRAM.transportCertificate {B : Basis} {r : ℕ} {α : Type} {ei : α ↪ List Bool} (enc : B.genericModel.Encoding) (N : B.genericModel.NativePrimitives enc) (p : Program B r) {f cfg : α → ℕ} {initState : α → GenericRAM.FiniteState B.genericModel r} {u : α → State r} {steps : α → ℕ} (cSteps : GenericRAM.NativeCertificate steps ei Turing.MultiTapeTM.encNat) (cCfg : GenericRAM.NativeCertificate cfg ei enc.config) (cInit : GenericRAM.NativeCertificate initState ei (GenericRAM.FiniteState.encoding enc)) (hden : ∀ (a : α), (initState a).denote = State.toGeneric B (u a)) (hExec : ∀ (a : α), ∃ m ≤ steps a, Executes (cfg a) p (u a) (f a) m) :

Transport a halting WordRAM.Executes certificate within steps a instructions to a native multitape Turing-machine certificate for f : α → ℕ.

theorem Cslib.WordRAM.transport_inO {B : Basis} {r : ℕ} {α : Type} {ei : α ↪ List Bool} (enc : B.genericModel.Encoding) (N : B.genericModel.NativePrimitives enc) (p : Program B r) {f cfg : α → ℕ} {initState : α → GenericRAM.FiniteState B.genericModel r} {u : α → State r} {steps : α → ℕ} (cSteps : GenericRAM.NativeCertificate steps ei Turing.MultiTapeTM.encNat) (cCfg : GenericRAM.NativeCertificate cfg ei enc.config) (cInit : GenericRAM.NativeCertificate initState ei (GenericRAM.FiniteState.encoding enc)) (hden : ∀ (a : α), (initState a).denote = State.toGeneric B (u a)) (hExec : ∀ (a : α), ∃ m ≤ steps a, Executes (cfg a) p (u a) (f a) m) :
Turing.MultiTapeTM.ComputableInO f ei enc.value (fun (a : α) => cSteps.time a + (cCfg.time a + cInit.time a) + GenericRAM.FiniteState.runTime enc N p.toGeneric (steps a, cfg a, initState a)) fun (a : α) => cSteps.space a + (cCfg.space a + cInit.space a) + GenericRAM.FiniteState.runSpace enc N p.toGeneric (steps a, cfg a, initState a)

Parameterized ComputableInO transport theorem from WordRAM.Executes.

theorem Cslib.WordRAM.transport_polyTime {B : Basis} {r : ℕ} {α : Type} {ei : α ↪ List Bool} (enc : B.genericModel.Encoding) (N : B.genericModel.NativePrimitives enc) (p : Program B r) {f cfg : α → ℕ} {initState : α → GenericRAM.FiniteState B.genericModel r} {u : α → State r} {steps : α → ℕ} (cSteps : GenericRAM.NativeCertificate steps ei Turing.MultiTapeTM.encNat) (cCfg : GenericRAM.NativeCertificate cfg ei enc.config) (cInit : GenericRAM.NativeCertificate initState ei (GenericRAM.FiniteState.encoding enc)) (hden : ∀ (a : α), (initState a).denote = State.toGeneric B (u a)) (hExec : ∀ (a : α), ∃ m ≤ steps a, Executes (cfg a) p (u a) (f a) m) (hN : N.IsPolynomial) (hSteps : cSteps.IsPolynomial) (hCfg : cCfg.IsPolynomial) (hInit : cInit.IsPolynomial) (hStepsBound : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (ei a).length) steps) {bound : α → ℕ} (hB : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (ei a).length) bound) (hOutLen : ∀ (a : α), ∀ j ≤ steps a, ((GenericRAM.FiniteState.resultEncoding enc) (GenericRAM.FiniteState.run (cfg a) p.toGeneric j (initState a))).length ≤ bound a) :

Automatic ComputableInPolyTime transport corollary from WordRAM.Executes.

theorem Cslib.WordRAM.transport_polyTime_of_le_const {B : Basis} {r : ℕ} {α : Type} {ei : α ↪ List Bool} (enc : B.genericModel.Encoding) (N : B.genericModel.NativePrimitives enc) (p : Program B r) {f cfg : α → ℕ} {initState : α → GenericRAM.FiniteState B.genericModel r} {u : α → State r} {steps : α → ℕ} (cSteps : GenericRAM.NativeCertificate steps ei Turing.MultiTapeTM.encNat) (cCfg : GenericRAM.NativeCertificate cfg ei enc.config) (cInit : GenericRAM.NativeCertificate initState ei (GenericRAM.FiniteState.encoding enc)) (hden : ∀ (a : α), (initState a).denote = State.toGeneric B (u a)) (hExec : ∀ (a : α), ∃ m ≤ steps a, Executes (cfg a) p (u a) (f a) m) (hN : N.IsPolynomial) (hSteps : cSteps.IsPolynomial) (hCfg : cCfg.IsPolynomial) (hInit : cInit.IsPolynomial) (K : ℕ) (hStepsLe : ∀ (a : α), steps a ≤ K) :

Automatic ComputableInPolyTime transport corollary from WordRAM.Executes under a constant step-budget bound ∀ a, steps a ≤ K.