Documentation

LeanPool.BeyondBethe.Complexitylib.Models.TuringMachine.Subroutines.BinaryAddConst

Addition of a fixed natural to a canonical binary tape #

This module exposes the literal-frame and resource contracts for a finite sequence of binary successors compiled from a hardwired natural constant.

Main results #

theorem Complexity.TM.binaryAddConstTime_zero_le (fixedValue : ℕ) :
binaryAddConstTime fixedValue 0 ≤ 4 * (fixedValue + 1) ^ 2

Adding a fixed constant to zero has a quadratic time bound.

theorem Complexity.TM.binaryAddConstTM_reachesIn_frame {n : ℕ} (idx : Fin n) (fixedValue dstValue : ℕ) (inp₀ : Tape) (work₀ : Fin n → Tape) (out₀ : Tape) (hdst : (work₀ idx).HasBinaryNat dstValue) (hinp : Parked inp₀) (hother : ∀ (i : Fin n), i ≠ idx → Parked (work₀ i)) (hout : Parked out₀) :
(binaryAddConstTM idx fixedValue).reachesIn (binaryAddConstTime fixedValue dstValue) { state := (binaryAddConstTM idx fixedValue).qstart, input := inp₀, work := work₀, output := out₀ } { state := (binaryAddConstTM idx fixedValue).qhalt, input := inp₀, work := Function.update work₀ idx ((Tape.init (List.map Γ.ofBool (dstValue + fixedValue).bits)).move Dir3.right), output := out₀ }

Fixed-constant addition has the advertised exact runtime and changes only the destination tape.

theorem Complexity.TM.binaryAddConstTM_hoareTime_frame {n : ℕ} (idx : Fin n) (fixedValue dstValue : ℕ) (inp₀ : Tape) (work₀ : Fin n → Tape) (out₀ : Tape) (hdst : (work₀ idx).HasBinaryNat dstValue) (hinp : Parked inp₀) (hother : ∀ (i : Fin n), i ≠ idx → Parked (work₀ i)) (hout : Parked out₀) :
(binaryAddConstTM idx fixedValue).HoareTime (fun (inp : Tape) (work : Fin n → Tape) (out : Tape) => inp = inp₀ ∧ work = work₀ ∧ out = out₀) (fun (inp : Tape) (work : Fin n → Tape) (out : Tape) => inp = inp₀ ∧ work = Function.update work₀ idx ((Tape.init (List.map Γ.ofBool (dstValue + fixedValue).bits)).move Dir3.right) ∧ out = out₀) (binaryAddConstTime fixedValue dstValue)

Time-bounded literal-frame contract for fixed-constant addition.

theorem Complexity.TM.binaryAddConstTM_hoareTimeSpace_frame {n : ℕ} (idx : Fin n) (fixedValue dstValue inputLength initialSpace : ℕ) (inp₀ : Tape) (work₀ : Fin n → Tape) (out₀ : Tape) (hdst : (work₀ idx).HasBinaryNat dstValue) (hinp : Parked inp₀) (hother : ∀ (i : Fin n), i ≠ idx → Parked (work₀ i)) (hout : Parked out₀) (hworkSpace : ∀ (i : Fin n), (work₀ i).head ≤ initialSpace) (hinputSpace : inp₀.head ≤ inputLength + initialSpace + 1) :
(binaryAddConstTM idx fixedValue).HoareTimeSpace (fun (inp : Tape) (work : Fin n → Tape) (out : Tape) => inp = inp₀ ∧ work = work₀ ∧ out = out₀) (fun (inp : Tape) (work : Fin n → Tape) (out : Tape) => inp = inp₀ ∧ work = Function.update work₀ idx ((Tape.init (List.map Γ.ofBool (dstValue + fixedValue).bits)).move Dir3.right) ∧ out = out₀) (binaryAddConstTime fixedValue dstValue) inputLength (binaryAddConstSpace initialSpace fixedValue dstValue)

Every prefix of fixed-constant addition respects a bound controlled by the final destination width.

theorem Complexity.TM.binaryAddConstTM_isTransducer {n : ℕ} (idx : Fin n) (fixedValue : ℕ) :

Fixed-constant addition never moves its output head left.