Counting frames of a concrete List Nat input
InductiveStacks of the frame counter for lists of naturals#✓fully proved
Input, one-block scratch, and a unary element counter.
inductive K | input | scratch | count
deriving DecidableEq
Used by 9
InductiveControl labels of the frame counter for lists of naturals#✓fully proved
Each complete frame increments the counter and clears its scratch.
inductive Lab | loop | block | bump | clear | good | bad
deriving DecidableEq
Used by 8
DefinitionProgram of the frame counter for lists of naturals#✓fully proved
Count by repeated shared block reading and shared scratch cleanup.
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
inductive Lab | loop | block | bump | clear | good | bad
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:39
inductive K | input | scratch | count
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:31
def read (a b : K) (d : Γ a → Option Bool) (g : Bool → Γ b)
(self good bad : Λ) : TM2.Stmt Γ Λ Bool :=
.peek a (fun _ o => isBit d o) <| .branch id
(.pop a (fun _ o => bitOf d o) <| .branch id
(.peek a (fun _ o => isBit d o) <| .branch id
(.pop a (fun _ o => bitOf d o) <| .push b g <|
.goto fun _ => self)
(.goto fun _ => bad))
(.goto fun _ => good))
(.goto fun _ => bad)
CSLibExt/Computability/Complexity/FramedCNF/Block.lean:32
def cleanS (ks : List K) (self next : Λ) : TM2.Stmt Γ Λ σ :=
.load (fun _ => Flag.tag false) <| popAll ks <|
.branch Flag.untag (.goto fun _ => self) (.goto fun _ => next)
MathlibExt/Computability/TuringMachine/Cleanup.lean:41
Uses 5 · Used by 7
DefinitionStack contents of the frame counter for lists of naturals#✓fully proved
The three actual stack contents.
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
inductive K | input | scratch | count
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:31
Uses 1 · Used by 6
TheoremOne frame adds one unary count bit#✓fully proved
One complete frame contributes exactly one unary count bit and leaves no payload scratch, independently of the decoded Nat's value.
theorem element_run (p x count : List Bool) (v : Bool) :
RunLe prog (4 * (delimit p).length)
⟨some .loop, v, st (delimit p ++ x) [] count⟩
⟨some .loop, false, st x [] (true :: count)⟩
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
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def delimit : List Bool → List Bool
| [] => [false]
| b :: l => true :: b :: delimit l
MathlibExt/Computability/Complexity.lean:68
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
Uses 11 · Used by 2
TheoremFrame counter yields the number of raw frames in unary#✓fully proved
Counting a sequence of raw frames yields its length in unary, with the caller's counter suffix preserved and scratch empty.
theorem blocks_run (bs : List (List Bool)) (count : List Bool) (v : Bool) :
RunLe prog (4 * ((bs.map delimit).flatten).length + 1)
⟨some .loop, v, st (bs.map delimit).flatten [] count⟩
⟨some .good, false,
st [] [] (List.replicate bs.length true ++ count)⟩
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
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def delimit : List Bool → List Bool
| [] => [false]
| b :: l => true :: b :: delimit l
MathlibExt/Computability/Complexity.lean:68
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
Uses 9 · Used by 1
TheoremFrame counter counts every successfully decoded list of naturals#✓fully proved
Count every successfully decoded List Nat, including noncanonical Nat payloads; the count suffix is preserved exactly.
theorem run_some {x : List Bool} {as : List Nat}
(h : bitDecode x = some as) (count : List Bool) (v : Bool) :
RunLe prog (4 * x.length + 1)
⟨some .loop, v, st x [] count⟩
⟨some .good, false,
st [] [] (List.replicate as.length true ++ count)⟩
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
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
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
Uses 16 · Used by 1
TheoremFrame counter fails on malformed list framing#✓fully proved
Malformed List Nat framing reaches the failure endpoint. The counter and scratch may be partial and must be cleared before reuse.
theorem run_none {x : List Bool} (h : bitDecode (α := List Nat) x = none)
(count : List Bool) (v : Bool) :
∃ v' S, RunLe prog (4 * x.length + 2)
⟨some .loop, v, st x [] count⟩ ⟨some .bad, v', S⟩
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
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
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
Uses 19 · Used by 1
AbbreviationFrame counter for lists of naturals as a host component#✓fully proved
The frame counter is a finite component of the existing Host.
abbrev component : Host.Comp where
K := K
Γ := fun _ => Bool
L := Lab
prog := prog
ks := [.input, .scratch, .count]
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 | scratch | count
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:31
inductive Lab | loop | block | bump | clear | good | bad
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:39
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
TheoremFrame counter decides decodability and counts length in unary#✓fully proved
Total List Nat decoding outcome and exact unary length on success.
theorem run (x : List Bool) (v : Bool) :
∃ v' S, RunLe prog (4 * x.length + 2)
⟨some .loop, v, st x [] []⟩
⟨some (if (bitDecode (α := List Nat) x).isSome then .good else .bad),
v', S⟩ ∧
∀ as : List Nat, bitDecode x = some as →
S = st [] [] (List.replicate as.length true)
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
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
Uses 16 · Used by 1
TheoremEmbedded frame counter preserves caller stacks#✓fully proved
Embedded counting preserves every caller stack outside its workspace on success and failure. Scratch is empty on success.
theorem run_embedded {J L : Type} [DecidableEq J] {Γ : J → Type}
(E : MetaMathlibExt.TM2Embedding.SEmb (fun _ : K => Bool) Γ)
(φ : Lab → L) {M : L → TM2.Stmt Γ L Bool}
(hm : MetaMathlibExt.TM2Embedding.Embeds E φ prog M)
(x : List Bool) (v : Bool) (S : ∀ j, List (Γ j))
(hs : MetaMathlibExt.TM2Embedding.Agree E (st x [] []) S) :
∃ v' T, RunLe M (4 * x.length + 2)
⟨some (φ .loop), v, S⟩
⟨some (φ (if (bitDecode (α := List Nat) x).isSome
then .good else .bad)), v', T⟩ ∧
MetaMathlibExt.TM2Embedding.Frame E S T ∧
∀ as : List Nat, bitDecode x = some as →
MetaMathlibExt.TM2Embedding.Agree E
(st [] [] (List.replicate as.length true)) T
structure SEmb {K K' : Type} (Γ : K → Type) (Γ' : K' → Type) where
/-- The stack renaming. -/
e : K → K'
/-- Distinct sub-machine stacks go to distinct host stacks. -/
inj : Injective e
/-- The alphabet of each sub-machine stack, identified with its host stack's. -/
ι : ∀ k, Γ k ≃ Γ' (e k)
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:51
inductive K | input | scratch | count
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:31
inductive Lab | loop | block | bump | clear | good | bad
deriving DecidableEq
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:39
def Embeds (M : Λ → TM2.Stmt Γ Λ σ) (M' : Λ' → TM2.Stmt Γ' Λ' σ) : Prop :=
∀ l, M' (φ l) = mapS E φ (M l) ∨ M l = .halt
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:76
def prog : Lab → TM2.Stmt (fun _ : K => Bool) Lab Bool
| .loop => .peek .input (fun _ o => o.isSome) <| .branch id
(.goto fun _ => .block) (.goto fun _ => .good)
| .block => Block.read .input .scratch some id .block .bump .bad
| .bump => .push .count (fun _ => true) (.goto fun _ => .clear)
| .clear => cleanS [.scratch] .clear .loop
| .good | .bad => .halt
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:47
def Agree (S : ∀ k, List (Γ k)) (S' : ∀ k', List (Γ' k')) : Prop :=
∀ k, S' (E.e k) = (S k).map (E.ι k)
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:80
def st (input scratch count : List Bool) : K → List Bool
| .input => input
| .scratch => scratch
| .count => count
CSLibExt/Computability/Complexity/PolynomialEncoding/ListCount.lean:56
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 bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
def Frame (S' S'' : ∀ k', List (Γ' k')) : Prop :=
∀ k', (∀ k, E.e k ≠ k') → S'' k' = S' k'
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:84
Uses 19
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.