A linear-time machine for total binary-payload normalization
InductiveStacks of the payload normalizer machine#✓fully proved
Input, reverse buffer, and output.
inductive K | input | buffer | output
deriving DecidableEq
Used by 27
InductiveControl labels of the payload normalizer machine#✓fully proved
The reader records the last payload bit; none means empty input.
inductive Lab | read (last : Option Bool) | copy | done
deriving DecidableEq
Used by 31
DefinitionProgram of the payload normalizer machine#✓fully proved
Normalization using only Boolean stack symbols and finite control.
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .read last =>
.peek .input (fun _ o => o.isSome) <| .branch id
(.pop .input (fun _ o => o.getD false) <|
.push .buffer id <| .goto fun b => .read (some b))
(if last = some false then
.push .buffer (fun _ => true) (.goto fun _ => .copy)
else .goto fun _ => .copy)
| .copy => moveB .buffer .output some id .copy .done
| .done => .halt
inductive Lab | read (last : Option Bool) | copy | done
deriving DecidableEq
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:36
inductive K | input | buffer | output
deriving DecidableEq
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:28
def moveB (a b : K) (d : Γ a → Option Bool) (g : Bool → Γ b) (self next : Λ) :
TM2.Stmt Γ Λ σ :=
.peek a (fun _ o => Flag.tag (isBit d o))
(.branch Flag.untag
(.pop a (fun _ o => Flag.tag (bitOf d o))
(.branch Flag.untag
(.push b (fun _ => g true) (.goto fun _ => self))
(.push b (fun _ => g false) (.goto fun _ => self))))
(.goto fun _ => next))
MathlibExt/Computability/TuringMachine/BitOps.lean:86
Uses 4 · Used by 11
DefinitionStack contents for the payload normalizer invariant#✓fully proved
The three stack contents used in the run invariant.
def st (input buffer output : List Bool) : K → List Bool
| .input => input
| .buffer => buffer
| .output => output
inductive K | input | buffer | output
deriving DecidableEq
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:28
Uses 1 · Used by 13
TheoremRead phase of the payload normalizer consumes each bit once#✓fully proved
The read phase consumes each input bit once and optionally adds the implicit terminal one. The prefix records already-consumed input.
theorem read_run (xs : List Bool) : ∀ (pre out : List Bool) (v : Bool),
Run prog (xs.length + 1)
⟨some (.read pre.getLast?), v, st xs pre.reverse out⟩
⟨some .copy, false, st [] (normalizeNat (pre ++ xs)).reverse out⟩
def Run (n : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
(flip bind (TM2.step M))^[n] (some c) = some d
MathlibExt/Computability/TuringMachine/Program.lean:84
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .read last =>
.peek .input (fun _ o => o.isSome) <| .branch id
(.pop .input (fun _ o => o.getD false) <|
.push .buffer id <| .goto fun b => .read (some b))
(if last = some false then
.push .buffer (fun _ => true) (.goto fun _ => .copy)
else .goto fun _ => .copy)
| .copy => moveB .buffer .output some id .copy .done
| .done => .halt
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:46
def st (input buffer output : List Bool) : K → List Bool
| .input => input
| .buffer => buffer
| .output => output
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:58
def normalizeNat (bits : List Bool) : List Bool :=
if bits.getLast? = some false then bits ++ [true] else bits
CSLibExt/Computability/Complexity/FramedCNF/Normalize.lean:27
Uses 7 · Used by 2
TheoremLinear step bound for the payload normalizer machine#✓fully proved
The whole component runs in at most 2 |x| + 3 steps.
theorem run (x : List Bool) :
∃ v S, RunLe prog (2 * x.length + 3)
⟨some (.read none), false, st x [] []⟩
⟨some .done, v, S⟩ ∧ S .output = normalizeNat x
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .read last =>
.peek .input (fun _ o => o.isSome) <| .branch id
(.pop .input (fun _ o => o.getD false) <|
.push .buffer id <| .goto fun b => .read (some b))
(if last = some false then
.push .buffer (fun _ => true) (.goto fun _ => .copy)
else .goto fun _ => .copy)
| .copy => moveB .buffer .output some id .copy .done
| .done => .halt
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:46
def st (input buffer output : List Bool) : K → List Bool
| .input => input
| .buffer => buffer
| .output => output
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:58
def normalizeNat (bits : List Bool) : List Bool :=
if bits.getLast? = some false then bits ++ [true] else bits
CSLibExt/Computability/Complexity/FramedCNF/Normalize.lean:27
Uses 11 · Used by 1
AbbreviationPayload normalizer as a host component#✓fully proved
The normalizer in the canonical component interface.
abbrev component : Host.Comp where
K := K
Γ := fun _ => Bool
L := Lab
prog := prog
ks := [.input, .buffer, .output]
ks_nodup := by decide
mem_ks k := by cases k <;> decide
structure Comp where
/-- Stack indices. -/
K : Type
/-- Decidable equality of stack indices. -/
[decK : DecidableEq K]
/-- Finitely many stacks. -/
[finK : Fintype K]
/-- Stack alphabets. -/
Γ : K → Type
/-- Finite alphabets. -/
[finΓ : ∀ k, Fintype (Γ k)]
/-- Labels. -/
⋯
CSLibExt/Computability/Complexity/Host.lean:53
inductive K | input | buffer | output
deriving DecidableEq
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:28
inductive Lab | read (last : Option Bool) | copy | done
deriving DecidableEq
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:36
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .read last =>
.peek .input (fun _ o => o.isSome) <| .branch id
(.pop .input (fun _ o => o.getD false) <|
.push .buffer id <| .goto fun b => .read (some b))
(if last = some false then
.push .buffer (fun _ => true) (.goto fun _ => .copy)
else .goto fun _ => .copy)
| .copy => moveB .buffer .output some id .copy .done
| .done => .halt
CSLibExt/Computability/Complexity/FramedCNF/NormalizeMachine.lean:46
Uses 4 · Used by 1
TheoremPayload normalization is polynomial-time#✓fully proved
Total binary-payload normalization is polynomial-time in the canonical encoded machine model.
theorem isPolyTime_normalizeNat :
MetaMathlibExt.ComplexityTheory.IsPolyTime normalizeNat
def IsPolyTime {α β : Type} [BitstringEncoding α] [BitstringEncoding β]
(f : α → β) : Prop :=
IsPolyTimeWithEncoding (BitstringEncoding.toEncoding (α := α))
(BitstringEncoding.toEncoding (α := β)) f
MathlibExt/Computability/Complexity.lean:186
def normalizeNat (bits : List Bool) : List Bool :=
if bits.getLast? = some false then bits ++ [true] else bits
CSLibExt/Computability/Complexity/FramedCNF/Normalize.lean:27
Uses 19
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.