Documentation

Complexitylib.Models.TuringMachine.Hoare.Space

Space-aware Hoare specifications #

TM.HoareSpace states the all-reachable auxiliary-space invariant required by TM.ComputesInSpace; TM.HoareTimeSpace pairs it with a terminating time-bounded Hoare triple. The public API includes structural rules, sequential composition, transducer closure, and a fresh-start computation bridge.

Main results #

theorem Complexity.Cfg.WithinAuxSpace.mono {n : } {Q : Type} {c : Cfg n Q} {inputLength inputLength' space space' : } (h : c.WithinAuxSpace inputLength space) (hinput : inputLength inputLength') (hspace : space space') :
c.WithinAuxSpace inputLength' space'

Enlarging the logical input region and work-space budget preserves an auxiliary-space bound.

theorem Complexity.Cfg.WithinAuxSpace.transition {n : } {Q : Type} {c : Cfg n Q} {inputLength space : } (h : c.WithinAuxSpace inputLength space) :
{ state := c.state, input := TM.transitionInput c.input, work := fun (i : Fin n) => TM.transitionTape (c.work i), output := TM.transitionTape c.output }.WithinAuxSpace inputLength (space + 1)

The standard combinator phase transition moves input and work heads by at most one, so one additional auxiliary-space cell covers the seam.

theorem Complexity.Cfg.WithinAuxSpace.reachesIn {n : } {tm : TM n} {c c' : Cfg n tm.Q} {time inputLength space : } (h : c.WithinAuxSpace inputLength space) (hreach : tm.reachesIn time c c') :
c'.WithinAuxSpace inputLength (space + time)

A time-step run can increase every charged head position by at most time, so adding that many cells preserves the auxiliary-space bound.

theorem Complexity.TM.HoareSpace.weaken_pre {n : } {tm : TM n} {pre pre' : TapePred n} {inputLength space : } (h : tm.HoareSpace pre inputLength space) (hpre : ∀ (inp : Tape) (work : Fin nTape) (out : Tape), pre' inp work outpre inp work out) :
tm.HoareSpace pre' inputLength space

Strengthening the precondition preserves an all-reachable space contract.

theorem Complexity.TM.HoareSpace.mono {n : } {tm : TM n} {pre : TapePred n} {inputLength inputLength' space space' : } (h : tm.HoareSpace pre inputLength space) (hinput : inputLength inputLength') (hspace : space space') :
tm.HoareSpace pre inputLength' space'

Enlarging the logical input region and auxiliary-space budget preserves a space contract.

theorem Complexity.TM.HoareTime.and_hoareSpace {n : } {tm : TM n} {pre post : TapePred n} {time inputLength space : } (htime : tm.HoareTime pre post time) (hspace : tm.HoareSpace pre inputLength space) :
tm.HoareTimeSpace pre post time inputLength space

Pair an existing terminating Hoare proof with an all-reachable space proof. This is the main entry point for upgrading established subroutine contracts without reproving their endpoint behavior.

theorem Complexity.TM.HoareTime.toHoareTimeSpace {n : } {tm : TM n} {pre post : TapePred n} {time inputLength initialSpace : } (htime : tm.HoareTime pre post time) (hinitial : ∀ (inp : Tape) (work : Fin nTape) (out : Tape), pre inp work out{ state := tm.qstart, input := inp, work := work, output := out }.WithinAuxSpace inputLength initialSpace) :
tm.HoareTimeSpace pre post time inputLength (initialSpace + time)

Upgrade a terminating time-bounded Hoare triple to an all-reachable time-and-space contract. If every starting configuration fits in initialSpace, then at most one additional cell per machine step gives the uniform bound initialSpace + time.

theorem Complexity.TM.HoareTimeSpace.toHoareTime {n : } {tm : TM n} {pre post : TapePred n} {time inputLength space : } (h : tm.HoareTimeSpace pre post time inputLength space) :
tm.HoareTime pre post time

A time-and-space contract exposes its ordinary time-bounded Hoare triple.

theorem Complexity.TM.HoareTimeSpace.toHoareSpace {n : } {tm : TM n} {pre post : TapePred n} {time inputLength space : } (h : tm.HoareTimeSpace pre post time inputLength space) :
tm.HoareSpace pre inputLength space

A time-and-space contract exposes its all-reachable space component.

theorem Complexity.TM.HoareTimeSpace.consequence {n : } {tm : TM n} {pre pre' post post' : TapePred n} {time time' inputLength inputLength' space space' : } (h : tm.HoareTimeSpace pre post time inputLength space) (hpre : ∀ (inp : Tape) (work : Fin nTape) (out : Tape), pre' inp work outpre inp work out) (hpost : ∀ (inp : Tape) (work : Fin nTape) (out : Tape), post inp work outpost' inp work out) (htime : time time') (hinput : inputLength inputLength') (hspace : space space') :
tm.HoareTimeSpace pre' post' time' inputLength' space'

Consequence rule: strengthen the precondition, weaken the postcondition, and enlarge any of the three numerical bounds.

theorem Complexity.TM.IsTransducer.seqTM {n : } {tm₁ tm₂ : TM n} (h₁ : tm₁.IsTransducer) (h₂ : tm₂.IsTransducer) :
(tm₁.seqTM tm₂).IsTransducer

Sequentially composing one-way-output machines preserves the transducer discipline.

theorem Complexity.TM.seqTM_hoareTimeSpace {n : } (tm₁ tm₂ : TM n) {pre mid mid' post : TapePred n} {b₁ b₂ inputLength space₁ space₂ : } (h₁ : tm₁.HoareTimeSpace pre mid b₁ inputLength space₁) (htrans : ∀ (inp : Tape) (work : Fin nTape) (out : Tape), mid inp work outmid' (transitionInput inp) (fun (i : Fin n) => transitionTape (work i)) (transitionTape out)) (h₂ : tm₂.HoareTimeSpace mid' post b₂ inputLength space₂) :
(tm₁.seqTM tm₂).HoareTimeSpace pre post (b₁ + 1 + b₂) inputLength (max space₁ space₂)

Sequential composition of time-and-space Hoare contracts.

theorem Complexity.TM.computesInSpace_of_hoareTimeSpace {n : } {tm : TM n} {f : List BoolList Bool} {T S : } (htrans : tm.IsTransducer) (h : ∀ (x : List Bool), tm.HoareTimeSpace (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = Tape.init (List.map Γ.ofBool x) (work = fun (x : Fin n) => Tape.init []) out = Tape.init []) (fun (x_1 : Tape) (x_2 : Fin nTape) (out : Tape) => out.HasOutput (f x)) (T x.length) x.length (S x.length)) :

Per-input fresh-start time-and-space contracts package a total function transducer satisfying TM.ComputesInSpace.