Documentation

Complexitylib.Models.TuringMachine.Subroutines.BinaryPolynomial

Canonical binary evaluation of a fixed natural polynomial #

This module exposes a finite Horner program compiled from a fixed polynomial. It preserves the input, writes the polynomial value to the designated result tape in canonical binary, and restores the scratch accumulator and both counters to canonical zero. Its all-prefix space bound depends on value width, not runtime, and is logarithmic in the input value for every fixed polynomial.

Main results #

@[simp]

A fixed polynomial contributes exactly one coefficient for each degree through its natural degree, including explicit zero coefficients.

The compiled coefficient list is never empty, including for the zero polynomial.

@[simp]

Horner evaluation leaves an accumulator unchanged at the empty list.

theorem Complexity.TM.binaryHornerFold_cons (x coeff acc : ) (coeffs : List ) :
binaryHornerFold x (coeff :: coeffs) acc = binaryHornerFold x coeffs (acc * x + coeff)

One Horner step multiplies the accumulator by the input and adds the next coefficient.

The high-degree-first coefficient list computes the polynomial's ordinary evaluation when Horner evaluation starts from zero.

Ordinary polynomial evaluation is bounded by the explicit cap used for every intermediate value of the compiled Horner routine.

theorem Complexity.TM.binaryPolynomialEvalTM_hoareTime_frame {n : } (inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n) (hdistinct : BinaryPolynomialDistinct inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx) (p : Polynomial ) (inputValue : ) (inp₀ : Tape) (work₀ : Fin nTape) (out₀ : Tape) (hinput : (work₀ inputIdx).HasBinaryNat inputValue) (hresult : (work₀ resultIdx).HasBinaryNat 0) (hscratch : (work₀ scratchIdx).HasBinaryNat 0) (hmulCounter : (work₀ mulCounterIdx).HasBinaryNat 0) (haddCounter : (work₀ addCounterIdx).HasBinaryNat 0) (hinp : Parked inp₀) (hother : ∀ (i : Fin n), i inputIdxi resultIdxi scratchIdxi mulCounterIdxi addCounterIdxParked (work₀ i)) (hout : Parked out₀) :
(binaryPolynomialEvalTM inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx p).HoareTime (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = work₀ out = out₀) (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = Function.update work₀ resultIdx ((Tape.init (List.map Γ.ofBool (Polynomial.eval inputValue p).bits)).move Dir3.right) out = out₀) (binaryPolynomialTime p inputValue)

Evaluating a fixed polynomial changes only the result tape. The input is preserved literally, and the scratch accumulator and both internal counters are restored to their initial canonical-zero tapes.

theorem Complexity.TM.binaryPolynomialEvalTM_hoareTimeSpace_frame {n : } (inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n) (hdistinct : BinaryPolynomialDistinct inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx) (p : Polynomial ) (inputValue inputLength initialSpace : ) (inp₀ : Tape) (work₀ : Fin nTape) (out₀ : Tape) (hinput : (work₀ inputIdx).HasBinaryNat inputValue) (hresult : (work₀ resultIdx).HasBinaryNat 0) (hscratch : (work₀ scratchIdx).HasBinaryNat 0) (hmulCounter : (work₀ mulCounterIdx).HasBinaryNat 0) (haddCounter : (work₀ addCounterIdx).HasBinaryNat 0) (hinp : Parked inp₀) (hother : ∀ (i : Fin n), i inputIdxi resultIdxi scratchIdxi mulCounterIdxi addCounterIdxParked (work₀ i)) (hout : Parked out₀) (hworkSpace : ∀ (i : Fin n), (work₀ i).head initialSpace) (hinputSpace : inp₀.head inputLength + initialSpace + 1) :
(binaryPolynomialEvalTM inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx p).HoareTimeSpace (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = work₀ out = out₀) (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = Function.update work₀ resultIdx ((Tape.init (List.map Γ.ofBool (Polynomial.eval inputValue p).bits)).move Dir3.right) out = out₀) (binaryPolynomialTime p inputValue) inputLength (binaryPolynomialSpace initialSpace p inputValue)

Every prefix of fixed-polynomial evaluation respects a common bound based on the width of a polynomial cap for all Horner intermediate values.

theorem Complexity.TM.binaryPolynomialSpace_bigO (initialSpace : ) (p : Polynomial ) :
BigO (fun (inputValue : ) => binaryPolynomialSpace initialSpace p inputValue) fun (inputValue : ) => Nat.log 2 inputValue

For every fixed polynomial and initial-space allowance, the public all-prefix space bound is logarithmic in the numeric input.

@[simp]

Evaluation of the explicit width polynomial is exactly twice the Horner-prefix value cap.

theorem Complexity.TM.binaryPolynomialEvalTM_isTransducer {n : } (inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n) (p : Polynomial ) :
(binaryPolynomialEvalTM inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx p).IsTransducer

Fixed-polynomial evaluation never moves its output head left.