Cook-Levin: the five generators as sub-machines of one host
Host stacks and the five embeddings
InductiveStacks of the Cook–Levin host machine#✓fully proved
The host has a shared output stack, an input-code stack, and five private counter blocks: an update block and a situation-definition block, each with one stack per counter of the family generator, and a shift block, an accept block and an init block, with one stack per counter of the shift, accept and init generator respectively.
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
inductive CK
| Tn | Ti | Hs | Gc | HG | Ka | Wc | Vc | TW | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Family.lean:348
inductive CK
| Tn | Ti | Hs | Gc | HG | Wc | Vc | TW | TW1 | KB | U | Ui | R | Ri | CB | CW | P | Q | tmp | md | Ka
| c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:136
inductive CK
| Tn | Hs | Gc | HG | Wc | Kc | K1 | Vc | TW | CB | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:75
inductive CK
| Tn | Xn | En | Fn | Gc | Mm | Hs | HG | Wc | Vc | KA | ZA | Z45 | Z6 | Z1 | Z2 | N1 | N2
| CB | Zr | P | Q | tmp | md | c1 | c2 | Id
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:218
Uses 4 · Used by 37
AbbreviationAlphabets of the Cook–Levin host machine#✓fully proved
For \(g \in \mathbb{N}\), the host stacks carry the following alphabets: the shared output stack holds Booleans, the input-code stack holds codes in \(\{0, \dots, g - 1\}\), and every stack of every private counter block has a one-element alphabet.
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
Uses 5 · Used by 16
DefinitionHost stack renaming for the update generator#✓fully proved
The map from the stacks of the clause-family generator, used as the update generator, to the host stacks that sends the output stack to the shared output stack and the counter stack of each counter \(x\) to the counter \(x\) of the host's update block.
def eU : Family.GK → HK
| .out => .out
| .c x => .up x
abbrev GK := SK CK
CSLibExt/Computability/Complexity/CookLevin/Family.lean:357
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
Uses 4 · Used by 1
DefinitionHost stack renaming for the situation-definition generator#✓fully proved
The map from the stacks of the clause-family generator, used as the situation-definition generator, to the host stacks that sends the output stack to the shared output stack and the counter stack of each counter \(x\) to the counter \(x\) of the host's situation-definition block.
def eS : Family.GK → HK
| .out => .out
| .c x => .sd x
abbrev GK := SK CK
CSLibExt/Computability/Complexity/CookLevin/Family.lean:357
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
DefinitionHost stack renaming for the shift generator#✓fully proved
The map from the stacks of the shift generator to the host stacks that sends the output stack to the shared output stack and the counter stack of each shift counter \(x\) to the counter \(x\) of the host's shift block.
def eH : SK Shift.CK → HK
| .out => .out
| .c x => .sh x
inductive SK (C : Type)
| out
| c (x : C)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:57
inductive CK
| Tn | Ti | Hs | Gc | HG | Wc | Vc | TW | TW1 | KB | U | Ui | R | Ri | CB | CW | P | Q | tmp | md | Ka
| c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:136
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
Uses 3 · Used by 1
DefinitionHost stack renaming for the accept generator#✓fully proved
The map from the stacks of the accept generator to the host stacks that sends the output stack to the shared output stack and the counter stack of each accept counter \(x\) to the counter \(x\) of the host's accept block.
def eA : SK Accept.CK → HK
| .out => .out
| .c x => .ac x
inductive SK (C : Type)
| out
| c (x : C)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:57
inductive CK
| Tn | Hs | Gc | HG | Wc | Kc | K1 | Vc | TW | CB | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:75
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
Uses 3 · Used by 1
DefinitionHost stack renaming for the init generator#✓fully proved
The map from the stacks of the init generator to the host stacks that sends the output stack to the shared output stack, the input stack to the host's input-code stack, and the counter stack of each init counter \(x\) to the counter \(x\) of the host's init block.
def eI : IK InitFamily.CK → HK
| .b .out => .out
| .b (.c x) => .ini x
| .inp => .inp
inductive IK (C : Type)
| b (k : SK C)
| inp
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:59
inductive CK
| Tn | Xn | En | Fn | Gc | Mm | Hs | HG | Wc | Vc | KA | ZA | Z45 | Z6 | Z1 | Z2 | N1 | N2
| CB | Zr | P | Q | tmp | md | c1 | c2 | Id
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:218
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
Uses 4 · Used by 1
DefinitionEmbedding of the update generator's stacks into the host#✓fully proved
For \(g \in \mathbb{N}\), this is the stack embedding of the family generator's stacks (a Boolean output stack and one unit counter stack per counter) into the host stacks with \(g\) input codes, used for the update generator: the output stack goes to the host's shared output stack, and the counter stack \(x\) goes to the stack \(x\) of the host's private update block. Distinct stacks go to distinct host stacks, and each stack's alphabet is identified with its host stack's alphabet by the identity.
def embU : SEmb Family.GΓ (HΓ g) where
e := eU
inj := by intro a b h; cases a <;> cases b <;> simp_all [eU]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
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
abbrev GΓ := SΓ CK
CSLibExt/Computability/Complexity/CookLevin/Family.lean:360
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def eU : Family.GK → HK
| .out => .out
| .c x => .up x
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:82
Uses 10 · Used by 2
DefinitionEmbedding of the situation-definition generator into the host#✓fully proved
For \(g\) input codes, the stack embedding of the clause-family generator's stacks, used as the situation-definition generator, into the host stacks that sends the output stack to the shared output stack and the counter stack of each counter \(x\) to the counter \(x\) of the host's situation-definition block, identifying each stack's alphabet with itself.
def embS : SEmb Family.GΓ (HΓ g) where
e := eS
inj := by intro a b h; cases a <;> cases b <;> simp_all [eS]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
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
abbrev GΓ := SΓ CK
CSLibExt/Computability/Complexity/CookLevin/Family.lean:360
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def eS : Family.GK → HK
| .out => .out
| .c x => .sd x
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:87
Uses 10 · Used by 2
DefinitionEmbedding of the shift generator into the host#✓fully proved
For \(g\) input codes, the stack embedding of the shift generator's stacks into the host stacks that sends the output stack to the shared output stack and the counter stack of each shift counter \(x\) to the counter \(x\) of the host's shift block, identifying each stack's alphabet with itself.
def embH : SEmb (SΓ Shift.CK) (HΓ g) where
e := eH
inj := by intro a b h; cases a <;> cases b <;> simp_all [eH]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
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
abbrev SΓ (C : Type) : SK C → Type
| .out => Bool
| .c _ => Unit
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:63
inductive CK
| Tn | Ti | Hs | Gc | HG | Wc | Vc | TW | TW1 | KB | U | Ui | R | Ri | CB | CW | P | Q | tmp | md | Ka
| c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:136
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def eH : SK Shift.CK → HK
| .out => .out
| .c x => .sh x
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:92
Uses 10 · Used by 2
DefinitionEmbedding of the accept generator into the host#✓fully proved
For \(g\) input codes, the stack embedding of the accept generator's stacks into the host stacks that sends the output stack to the shared output stack and the counter stack of each accept counter \(x\) to the counter \(x\) of the host's accept block, identifying each stack's alphabet with itself.
def embA : SEmb (SΓ Accept.CK) (HΓ g) where
e := eA
inj := by intro a b h; cases a <;> cases b <;> simp_all [eA]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
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
abbrev SΓ (C : Type) : SK C → Type
| .out => Bool
| .c _ => Unit
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:63
inductive CK
| Tn | Hs | Gc | HG | Wc | Kc | K1 | Vc | TW | CB | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:75
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def eA : SK Accept.CK → HK
| .out => .out
| .c x => .ac x
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:97
Uses 10 · Used by 2
DefinitionEmbedding of the init generator into the host#✓fully proved
For \(g\) input codes, the stack embedding of the init generator's stacks (with input alphabet the \(g\) codes) into the host stacks that sends the output stack to the shared output stack, the input stack to the host's input-code stack, and the counter stack of each init counter \(x\) to the counter \(x\) of the host's init block, identifying each stack's alphabet with itself.
def embI : SEmb (IΓ InitFamily.CK (Fin g)) (HΓ g) where
e := eI
inj := by
intro a b h
rcases a with (_ | a) | _ <;> rcases b with (_ | b) | _ <;> simp_all [eI]
ι := fun k => match k with
| .b .out => Equiv.refl _
| .b (.c _) => Equiv.refl _
| .inp => Equiv.refl _
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
abbrev IΓ (C G : Type) : IK C → Type
| .b k => SΓ C k
| .inp => G
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:65
inductive CK
| Tn | Xn | En | Fn | Gc | Mm | Hs | HG | Wc | Vc | KA | ZA | Z45 | Z6 | Z1 | Z2 | N1 | N2
| CB | Zr | P | Q | tmp | md | c1 | c2 | Id
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:218
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def eI : IK InitFamily.CK → HK
| .b .out => .out
| .b (.c x) => .ini x
| .inp => .inp
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:102
Uses 11 · Used by 2
The host program and the sequencing theorem
InductiveLabels of the Cook–Levin host machine#✓fully proved
For parameters \(N, n_L, K, g, d, n_1, n_Y\), the host labels consist of a copy of the family generator's labels (for \(N\) situations and \(n_L\) literals) for the update phase, a second copy of them for the situation-definition phase, a copy of the shift generator's labels (for \(N\) situations, \(K\) stacks, \(g\) symbols and depth \(d\)), a copy of the accept generator's labels (for \(n_1\) code clauses and \(g\) symbols), a copy of the init generator's labels (for \(g\) symbols and \(n_Y\) certificate codes), and one final label.
inductive HL (N nL KK g d n1 ny : ℕ)
| up (l : Family.GL N nL)
| sd (l : Family.GL N nL)
| sh (l : Shift.GL N KK g d)
| ac (l : Accept.GL n1 g)
| ini (l : InitFamily.GL g ny)
| fin
deriving DecidableEq, Fintype
inductive GL (N m : ℕ)
| pre (s : PS)
| tHead | tRest
| tw (s : MS)
| e00 (i : Fin N) | cv1 (i : Fin N) | cv2 (i : Fin N)
| lit (i : Fin N) (j : Fin m) (s : LS)
| fin (i : Fin N)
| dtw | done
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Family.lean:375
inductive GL (N KK g d : ℕ)
| pre (s : PS)
| tHead | tRest | tw (s : MS) | t1a | t1b | t1c | t1d | tEnd | tEnd2
| s (i : Fin N) (k : Fin KK) (x : ST)
| sb (i : Fin N) (k : Fin KK) (r : Fin (d + 1))
| b (i : Fin N) (k : Fin KK) (x : BD g d)
| bad | done
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:225
inductive GL (n1 g : ℕ)
| pre (s : PS)
| e00 (c : AK n1 g) | cv1 (c : AK n1 g) | cv2 (c : AK n1 g) | lit (c : AK n1 g) (s : LS)
| fin (c : AK n1 g)
| done
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:125
inductive GL (g n : ℕ)
| pre1 (s : PS1) | pre2 (s : PS2)
| hd (p : PH) | rs (p : PH) | b1 (p : PH) | b2 (p : PH) | bM (p : PH) (s : MS) | dr (p : PH)
| i3h | i3b1 | i3b2 | i3M (s : MS) | rd (i : Fin g) | i3d | bad
| e00 (c : CL g n) | cv1 (c : CL g n) | cv2 (c : CL g n)
| lit (c : CL g n) (l : Fin (n + 2)) (s : LS) | fin (c : CL g n)
| done
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:323
Uses 4 · Used by 13
DefinitionChaining step of the host program#✓fully proved
For a host label \(l\), the chaining step is the host statement that sets the Boolean internal state to false (the state in which every generator starts) and then jumps to \(l\).
def chain (l : HL N nL KK g d n1 ny) : TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool :=
.load (fun _ => false) (.goto fun _ => l)
inductive HL (N nL KK g d n1 ny : ℕ)
| up (l : Family.GL N nL)
| sd (l : Family.GL N nL)
| sh (l : Shift.GL N KK g d)
| ac (l : Accept.GL n1 g)
| ini (l : InitFamily.GL g ny)
| fin
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:188
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
Uses 3 · Used by 2
DefinitionThe host program#✓fully proved
Given the five generator programs (update, situation definition, shift, accept and init), the host program runs init, then update, then situation definition, then shift, then accept. At each label of a generator other than its final label, the host executes that generator's statement with the generator's stacks embedded into the host stacks (output onto the shared output stack, counters onto the generator's own private counter block, and for init the input stack onto the host's input-code stack) and its labels renamed into the host's copy of them. At a generator's final label the host performs one chaining step: it resets the Boolean state to false and jumps to the start label of the next generator, and after accept it jumps to the final host label, where it halts.
def hprog : HL N nL KK g d n1 ny → TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool
| .ini l => if l = .done then chain (.up (.pre .eg)) else mapS (embI g) HL.ini (Pi l)
| .up l => if l = .done then chain (.sd (.pre .eg)) else mapS (embU g) HL.up (Pu l)
| .sd l => if l = .done then chain (.sh (.pre .eg)) else mapS (embS g) HL.sd (Ps l)
| .sh l => if l = .done then chain (.ac (.pre .eg)) else mapS (embH g) HL.sh (Ph l)
| .ac l => if l = .done then chain .fin else mapS (embA g) HL.ac (Pa l)
| .fin => .halt
inductive HL (N nL KK g d n1 ny : ℕ)
| up (l : Family.GL N nL)
| sd (l : Family.GL N nL)
| sh (l : Shift.GL N KK g d)
| ac (l : Accept.GL n1 g)
| ini (l : InitFamily.GL g ny)
| fin
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:188
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def chain (l : HL N nL KK g d n1 ny) : TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool :=
.load (fun _ => false) (.goto fun _ => l)
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:206
def mapS : TM2.Stmt Γ Λ σ → TM2.Stmt Γ' Λ' σ
| .push k f q => .push (E.e k) (fun s => E.ι k (f s)) (mapS q)
| .peek k f q => .peek (E.e k) (fun s o => f s (o.map (E.ι k).symm)) (mapS q)
| .pop k f q => .pop (E.e k) (fun s o => f s (o.map (E.ι k).symm)) (mapS q)
| .load a q => .load a (mapS q)
| .branch f q₁ q₂ => .branch f (mapS q₁) (mapS q₂)
| .goto f => .goto fun s => φ (f s)
| .halt => .halt
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:65
def embI : SEmb (IΓ InitFamily.CK (Fin g)) (HΓ g) where
e := eI
inj := by
intro a b h
rcases a with (_ | a) | _ <;> rcases b with (_ | b) | _ <;> simp_all [eI]
ι := fun k => match k with
| .b .out => Equiv.refl _
| .b (.c _) => Equiv.refl _
| .inp => Equiv.refl _
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:140
def embU : SEmb Family.GΓ (HΓ g) where
e := eU
inj := by intro a b h; cases a <;> cases b <;> simp_all [eU]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:108
def embS : SEmb Family.GΓ (HΓ g) where
e := eS
inj := by intro a b h; cases a <;> cases b <;> simp_all [eS]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:116
def embH : SEmb (SΓ Shift.CK) (HΓ g) where
e := eH
inj := by intro a b h; cases a <;> cases b <;> simp_all [eH]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:124
def embA : SEmb (SΓ Accept.CK) (HΓ g) where
e := eA
inj := by intro a b h; cases a <;> cases b <;> simp_all [eA]
ι := fun k => match k with
| .out => Equiv.refl _
| .c _ => Equiv.refl _
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:132
Uses 39 · Used by 4
DefinitionThe host as a finite multi-stack Turing machine#✓fully proved
Given the five generator programs (update and situation-definition programs over the family generator's stacks, a shift program, an accept program, and an init program whose input alphabet has \(g\) codes), the host machine is the finite multi-stack Turing machine whose stacks are the host stacks, with the input-code stack as input stack and the shared output stack as output stack, whose alphabets are the host alphabets, whose labels are the host labels, whose start label is the init generator's start label, whose internal state is a Boolean with initial value false, and whose program is the host program built from the five generator programs.
This is a finiteness check only: the input and output stacks are provisional until the precomputation is attached.
def hostTM : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ g
Λ := HL N nL KK g d n1 ny
main := .ini (.pre1 .eg)
σ := Bool
initialState := false
m := hprog Pu Ps Ph Pa Pi
inductive HK
| out
| inp
| up (x : Family.CK)
| sd (x : Family.CK)
| sh (x : Shift.CK)
| ac (x : Accept.CK)
| ini (x : InitFamily.CK)
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:57
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
inductive HL (N nL KK g d n1 ny : ℕ)
| up (l : Family.GL N nL)
| sd (l : Family.GL N nL)
| sh (l : Shift.GL N KK g d)
| ac (l : Accept.GL n1 g)
| ini (l : InitFamily.GL g ny)
| fin
deriving DecidableEq, Fintype
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:188
def hprog : HL N nL KK g d n1 ny → TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool
| .ini l => if l = .done then chain (.up (.pre .eg)) else mapS (embI g) HL.ini (Pi l)
| .up l => if l = .done then chain (.sd (.pre .eg)) else mapS (embU g) HL.up (Pu l)
| .sd l => if l = .done then chain (.sh (.pre .eg)) else mapS (embS g) HL.sd (Ps l)
| .sh l => if l = .done then chain (.ac (.pre .eg)) else mapS (embH g) HL.sh (Ph l)
| .ac l => if l = .done then chain .fin else mapS (embA g) HL.ac (Pa l)
| .fin => .halt
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:211
Uses 33
TheoremSequencing#✓fully proved
Let \(P_u\), \(P_s\) (update and situation definition), \(P_h\) (shift), \(P_a\)
(accept) and \(P_i\) (init) be generator programs that halt at their label done, and let \(\xi\) be
a list of input codes. Suppose that for each generator \(j \in \{u, s, h, a, i\}\) there are counter
values \(F_j\), a word \(w_j\) and a bound \(B_j\) such that, for every output word \(o\), the run of \(P_j\)
from its start label with state bit false, on stacks holding the counters \(F_j\) and the output \(o\)
(for init, also \(\xi\) on its input stack), reaches done within \(B_j\) steps, with some state bit
and with output \(w_j o\). Let \(o\) be a word and let \(S_0\) be host stacks whose output stack holds
\(o\), whose input stack holds \(\xi\), and whose private block of each generator \(j\) holds the
counters \(F_j\). Then the host program on \(P_u, P_s, P_h, P_a, P_i\), started at the init
generator's start label with state bit false on \(S_0\), reaches its final label within
\(B_i + B_u + B_s + B_h + B_a + 5\) steps, with some state bit and with output
\(w_a w_h w_s w_u w_i o\).
Cslib.Complexity.CookLevin.Assembly.seq_run · 23 lines
theorem seq_run (hu0 : Pu .done = .halt) (hs0 : Ps .done = .halt) (hh0 : Ph .done = .halt)
(ha0 : Pa .done = .halt) (hi0 : Pi .done = .halt)
{Fu Fs : Family.CK → ℕ} {Fh : Shift.CK → ℕ} {Fa : Accept.CK → ℕ} {Fi : InitFamily.CK → ℕ}
{xs : List (Fin g)} {wu ws wh wa wi : List Bool} {Bu Bs Bh Ba Bi : ℕ}
(hu : ∀ o, ∃ (v : Bool) (S : ∀ k, List (Family.GΓ k)),
RunLe Pu Bu ⟨some (.pre .eg), false, CounterView.st Fu o⟩ ⟨some .done, v, S⟩ ∧ S .out = wu ++ o)
(hs : ∀ o, ∃ (v : Bool) (S : ∀ k, List (Family.GΓ k)),
RunLe Ps Bs ⟨some (.pre .eg), false, CounterView.st Fs o⟩ ⟨some .done, v, S⟩ ∧ S .out = ws ++ o)
(hh : ∀ o, ∃ (v : Bool) (S : ∀ k, List (SΓ Shift.CK k)),
RunLe Ph Bh ⟨some (.pre .eg), false, CounterView.st Fh o⟩ ⟨some .done, v, S⟩ ∧ S .out = wh ++ o)
(ha : ∀ o, ∃ (v : Bool) (S : ∀ k, List (SΓ Accept.CK k)),
RunLe Pa Ba ⟨some (.pre .eg), false, CounterView.st Fa o⟩ ⟨some .done, v, S⟩ ∧ S .out = wa ++ o)
(hi : ∀ o, ∃ (v : Bool) (S : ∀ k, List (IΓ InitFamily.CK (Fin g) k)),
RunLe Pi Bi ⟨some (.pre1 .eg), false, emb (CounterView.st Fi o) xs⟩ ⟨some .done, v, S⟩ ∧
S (.b .out) = wi ++ o)
(S₀ : ∀ k, List (HΓ g k)) (o : List Bool) (ho : S₀ .out = o) (hin : S₀ .inp = xs)
(cu : ∀ x, S₀ (.up x) = cnt () (Fu x)) (cs : ∀ x, S₀ (.sd x) = cnt () (Fs x))
(ch : ∀ x, S₀ (.sh x) = cnt () (Fh x)) (ca : ∀ x, S₀ (.ac x) = cnt () (Fa x))
(ci : ∀ x, S₀ (.ini x) = cnt () (Fi x)) :
∃ (v : Bool) (S : ∀ k, List (HΓ g k)),
RunLe (hprog Pu Ps Ph Pa Pi) (Bi + Bu + Bs + Bh + Ba + 5)
⟨some (.ini (.pre1 .eg)), false, S₀⟩ ⟨some .fin, v, S⟩ ∧
S .out = wa ++ (wh ++ (ws ++ (wu ++ (wi ++ o))))
inductive CK
| Tn | Ti | Hs | Gc | HG | Ka | Wc | Vc | TW | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Family.lean:348
inductive CK
| Tn | Ti | Hs | Gc | HG | Wc | Vc | TW | TW1 | KB | U | Ui | R | Ri | CB | CW | P | Q | tmp | md | Ka
| c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:136
inductive CK
| Tn | Hs | Gc | HG | Wc | Kc | K1 | Vc | TW | CB | P | Q | tmp | md | c1 | c2
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:75
inductive CK
| Tn | Xn | En | Fn | Gc | Mm | Hs | HG | Wc | Vc | KA | ZA | Z45 | Z6 | Z1 | Z2 | N1 | N2
| CB | Zr | P | Q | tmp | md | c1 | c2 | Id
deriving DecidableEq
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:218
abbrev GΓ := SΓ CK
CSLibExt/Computability/Complexity/CookLevin/Family.lean:360
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 st (f : C → ℕ) (o : List Bool) : ∀ k, List (SΓ C k)
| .out => o
| .c x => cnt () (f x)
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:72
abbrev SΓ (C : Type) : SK C → Type
| .out => Bool
| .c _ => Unit
CSLibExt/Computability/Complexity/CookLevin/CounterView.lean:63
abbrev IΓ (C G : Type) : IK C → Type
| .b k => SΓ C k
| .inp => G
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:65
def emb (S : ∀ k, List (SΓ C k)) (xs : List G) : ∀ k, List (IΓ C G k)
| .b k => S k
| .inp => xs
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:74
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
abbrev cnt {α : Type} (u : α) (n : ℕ) : List α := List.replicate n u
MathlibExt/Computability/TuringMachine/Program.lean:115
def hprog : HL N nL KK g d n1 ny → TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool
| .ini l => if l = .done then chain (.up (.pre .eg)) else mapS (embI g) HL.ini (Pi l)
| .up l => if l = .done then chain (.sd (.pre .eg)) else mapS (embU g) HL.up (Pu l)
| .sd l => if l = .done then chain (.sh (.pre .eg)) else mapS (embS g) HL.sd (Ps l)
| .sh l => if l = .done then chain (.ac (.pre .eg)) else mapS (embH g) HL.sh (Ph l)
| .ac l => if l = .done then chain .fin else mapS (embA g) HL.ac (Pa l)
| .fin => .halt
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:211
Uses 51 · Used by 1
The host on the five real generators of a machine
AbbreviationThe host on the real generators of a machine#✓fully proved
Let \(M\) be a finite multi-stack Turing machine with encoding data \(E\), let \(Y\) be a list of input symbols, and let \(\mathit{acc}\) be an output symbol. This is the host program whose five generators are the real ones for \(M\). The update generator is the family generator of \(E\) for the (label, state) codes, window codes and next (label, state) codes of the situations of \(E\). The situation-definition generator is the family generator of \(E\) for the same (label, state) codes and window codes, with the positions of the situation variables in place of the next codes. The shift generator is the one of \(E\). The accept generator is the one for the number of (label, state) codes, the code of the halted label with the initial internal state, the number of the output stack, and the code of \(\mathit{acc}\) on the output stack. The init generator is the one for the code of the start label and initial state of \(M\), the number of the input stack, and the sorted distinct codes of the symbols of \(Y\). The input itself is not a parameter: the init generator reads it from the host's input-code stack.
noncomputable abbrev realProg (Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) :=
hprog (Family.prog E.layout E.la E.na E.wa E.N) (Family.prog E.layout E.la E.sa E.wa E.N)
(Shift.prog E.layout E.sa E.pl E.cn E.pu E.N)
(Accept.prog E.layout E.A0 E.acode (E.kc M.k₁) (E.enc M.k₁ acc))
(InitFamily.iprog E.layout (E.lc (some M.main,
M.initialState)) (E.kc M.k₀) (InitFamily.ycs E Ys))
def hprog : HL N nL KK g d n1 ny → TM2.Stmt (HΓ g) (HL N nL KK g d n1 ny) Bool
| .ini l => if l = .done then chain (.up (.pre .eg)) else mapS (embI g) HL.ini (Pi l)
| .up l => if l = .done then chain (.sd (.pre .eg)) else mapS (embU g) HL.up (Pu l)
| .sd l => if l = .done then chain (.sh (.pre .eg)) else mapS (embS g) HL.sd (Ps l)
| .sh l => if l = .done then chain (.ac (.pre .eg)) else mapS (embH g) HL.sh (Ph l)
| .ac l => if l = .done then chain .fin else mapS (embA g) HL.ac (Pa l)
| .fin => .halt
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:211
def prog : GL N L.nLits → TM2.Stmt GΓ (GL N L.nLits) Bool
| .pre .eg => emitR (.c .Gc) (List.replicate L.g ()) (.pre (.hg .head))
| .pre (.hg s) => mulS .Hs .md .Gc .HG .tmp (fun s => .pre (.hg s)) (.pre .ew) s
| .pre .ew => emitR (.c .Wc) (List.replicate L.A ()) (.pre .ek)
| .pre .ek => emitR (.c .Ka) (List.replicate L.KK ()) (.pre (.w .head))
| .pre (.w s) => mulS .Ka .md .HG .Wc .tmp (fun s => .pre (.w s)) (.pre .dk) s
| .pre .dk => xfer (.c .Ka) [] (.pre .dk) (.pre .cp1)
| .pre .cp1 => xfer (.c .Tn) [⟨.c .Ka, ()⟩, ⟨.c .tmp, ()⟩] (.pre .cp1) (.pre .cp2)
| .pre .cp2 => xfer (.c .tmp) [⟨.c .Tn, ()⟩] (.pre .cp2) (.pre .inc)
| .pre .inc => incr (.c .Ka) () (.pre (.v .head))
| .pre (.v s) => mulS .Ka .md .Wc .Vc .tmp (fun s => .pre (.v s)) (.pre .dk2) s
| .pre .dk2 => xfer (.c .Ka) [] (.pre .dk2) .tHead
⋯
CSLibExt/Computability/Complexity/CookLevin/Family.lean:448
def prog : Lab L N → TM2.Stmt (SΓ CK) (Lab L N) Bool
| .pre .eg => emitR (.c .Gc) (List.replicate L.g ()) (.pre (.hg .head))
| .pre (.hg s) => mulS .Hs .md .Gc .HG .tmp (fun s => .pre (.hg s)) (.pre .ew) s
| .pre .ew => emitR (.c .Wc) (List.replicate L.A ()) (.pre .ek)
| .pre .ek => emitR (.c .Ka) (List.replicate L.KK ()) (.pre (.w .head))
| .pre (.w s) => mulS .Ka .md .HG .Wc .tmp (fun s => .pre (.w s)) (.pre .dk) s
| .pre .dk => xfer (.c .Ka) [] (.pre .dk) (.pre (.v .head))
| .pre (.v s) => mulS .Tn .md .Wc .Vc .tmp (fun s => .pre (.v s)) (.pre .vw1) s
| .pre .vw1 => xfer (.c .Wc) [⟨.c .Vc, ()⟩, ⟨.c .tmp, ()⟩] (.pre .vw1) (.pre .vw2)
| .pre .vw2 => xfer (.c .tmp) [⟨.c .Wc, ()⟩] (.pre .vw2) .tHead
| .tHead => forHead (.c .Tn) (.c .Ti) () (.tw .head) .tRest
| .tRest => xfer (.c .Ti) [⟨.c .Tn, ()⟩] .tRest .done
⋯
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:389
def prog : GL n1 L.g → TM2.Stmt (SΓ CK) (GL n1 L.g) Bool
| .pre .eg => emitR (.c .Gc) (List.replicate L.g ()) (.pre (.hg .head))
| .pre (.hg s) => mulS .Hs .md .Gc .HG .tmp (fun s => .pre (.hg s)) (.pre .ew) s
| .pre .ew => emitR (.c .Wc) (List.replicate L.A ()) (.pre .ek)
| .pre .ek => emitR (.c .Kc) (List.replicate L.KK ()) (.pre (.w .head))
| .pre (.w s) => mulS .Kc .md .HG .Wc .tmp (fun s => .pre (.w s)) (.pre (.tw .head)) s
| .pre (.tw s) => mulS .Tn .md .Wc .TW .tmp (fun s => .pre (.tw s)) (.pre .inc) s
| .pre .inc => incr (.c .Tn) () (.pre (.v .head))
| .pre (.v s) => mulS .Tn .md .Wc .Vc .tmp (fun s => .pre (.v s)) (.pre .cb1) s
| .pre .cb1 => xfer (.c .TW) [⟨.c .CB, ()⟩, ⟨.c .tmp, ()⟩] (.pre .cb1) (.pre .cb2)
| .pre .cb2 => xfer (.c .tmp) [⟨.c .TW, ()⟩] (.pre .cb2) (.pre .cbA)
| .pre .cbA => emitR (.c .CB) (List.replicate L.A ()) (.pre .k1)
⋯
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:183
def iprog : Lb L ycs → TM2.Stmt (IΓ CK (Fin L.g)) (Lb L ycs) Bool
| .rd i => rdS (fun c => .e00 (.inp c)) GL.miss i
| l => mapS liftE id (prog L ic k0 ycs l)
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:452
noncomputable def ycs (Ys : List (M.Γ M.k₀)) : List ℕ :=
((Ys.map (E.enc M.k₀)).toFinset).sort (· ≤ ·)
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:1491
Uses 22 · Used by 3
DefinitionThe formula emitted by the host#✓fully proved
Let \(M\) be a finite multi-stack Turing machine with encoding data \(E\), let \(x\) and \(Y\) be lists of input symbols, let \(\mathit{acc}\) be an output symbol, and let \(m, T \in \mathbb{N}\). Let \(H = m + (T + 1) d + 1\) be the stack cap, where \(d\) is the window depth of \(M\). The CNF formula \(\Phi(x, Y, \mathit{acc}, m, T)\) is the concatenation, in this order, of the accept family for \(\mathit{acc}\), the shift family, the situation-definition family, the update family, and the init family for \(x\), \(Y\) and \(m\), all at run length \(T\) and stack cap \(H\).
noncomputable def Phi (x Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) (m T : ℕ) : CNF :=
E.accFamily acc T (capH m T (depth M)) ++
(Shift.shFamily E.layout E.sa E.pl E.cn E.pu E.N T (capH m T (depth M)) ++
(Family.family E.layout E.la E.sa E.wa T (capH m T (depth M)) E.N ++
(Family.family E.layout E.la E.na E.wa T (capH m T (depth M)) E.N ++
E.initFamily x Ys m T (capH m T (depth M)))))
abbrev CNF := List Clause
CSLibExt/Computability/Complexity/DenseSAT.lean:59
def capH (m T d : ℕ) : ℕ := m + (T + 1) * d + 1
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:1420
def depth (M : FinTM2) : ℕ :=
letI := M.ΛFin
Finset.univ.sup fun l => ops (M.m l)
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:231
def shFamily (N T H : ℕ) : CNF :=
(List.range T).flatMap fun t => (List.range N).flatMap fun i =>
(List.range L.KK).flatMap fun k => shBlk L sa pl cn pu T H t i k
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:100
def family (T H N : ℕ) : CNF :=
(List.range T).flatMap fun t =>
(List.range N).map fun i => denseClause (L.numVars T H) (lits L la na wa H t i)
CSLibExt/Computability/Complexity/CookLevin/Family.lean:132
Uses 18 · Used by 9
DefinitionStep bound of the host#✓fully proved
Let \(M\) be a finite multi-stack Turing machine with encoding data \(E\), let \(Y\) be a list of input symbols, and let \(m, T \in \mathbb{N}\). Let \(H = m + (T + 1) d + 1\), where \(d\) is the window depth of \(M\), and let \(R = T + H + 1\). Let \(L\) be the layout of \(E\) and \(N\) its number of situations. Let \(c_I\) be the init generator's constant for \(L\), the number of distinct codes of symbols of \(Y\), and the number of the input stack; let \(c_F\) be the family generator's constant for \(L\) and \(N\); let \(c_S\) be the shift generator's constant for \(L\) and \(N\); and let \(c_A\) be the accept generator's constant for \(L\), the number of (label, state) codes, and the number of the output stack. The step bound is
the bounds of the init, update, situation-definition, shift and accept generators plus five chaining steps.
noncomputable def realB (Ys : List (M.Γ M.k₀)) (m T : ℕ) : ℕ :=
InitFamily.initC E.layout (InitFamily.ycs E Ys).length (E.kc M.k₀) * (T + capH m T (depth M) + 1) ^ 5 +
Family.genC E.layout E.N * (T + capH m T (depth M) + 1) ^ 5 +
Family.genC E.layout E.N * (T + capH m T (depth M) + 1) ^ 5 +
Shift.shC E.layout E.N * (T + capH m T (depth M) + 1) ^ 6 +
Accept.accC E.layout E.A0 (E.kc M.k₁) * (T + capH m T (depth M) + 1) ^ 4 + 5
def initC (L : Layout) (nY k0 : ℕ) : ℕ := 18928 * (L.A + L.KK + L.g + nY + k0 + 1) ^ 5
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:1427
noncomputable def ycs (Ys : List (M.Γ M.k₀)) : List ℕ :=
((Ys.map (E.enc M.k₀)).toFinset).sort (· ≤ ·)
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:1491
def capH (m T d : ℕ) : ℕ := m + (T + 1) * d + 1
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:1420
def depth (M : FinTM2) : ℕ :=
letI := M.ΛFin
Finset.univ.sup fun l => ops (M.m l)
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:231
def genC (L : Layout) (N : ℕ) : ℕ := 323 * (L.A + L.KK + L.g + L.d + N + 1) ^ 5
CSLibExt/Computability/Complexity/CookLevin/Family.lean:1051
def shC (L : Layout) (N : ℕ) : ℕ := 828 * (L.A + L.KK + L.g + L.d + N + 1) ^ 7
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:1380
def accC (L : Layout) (n1 k1 : ℕ) : ℕ := 314 * (L.A + L.KK + L.g + n1 + k1 + 1) ^ 5
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:575
Uses 10 · Used by 6
TheoremThe assembled generator, after the precomputation#✓fully proved
Let \(E\) be an encoding of a machine \(M\), let \(x\) and \(Y\) be lists of input symbols of \(M\), let \(a\) be a symbol of its output stack, and let \(m, T \in \mathbb{N}\) with \(|x| \le m\). Put \(H = m + (T + 1)d + 1\), where \(d\) is the window depth of \(M\). Let \(S_0\) be host stacks whose output stack holds a word \(o\), whose input stack holds the symbol codes of \(x\) in reverse order, whose update, situation-definition, shift and accept blocks each hold \(T\) on the time counter, \(H\) on the height counter and nothing on the other counters, and whose init block holds \(T\), \(|x|\), \(m - |x|\) and \(H - m\) on its four size counters and nothing on the others. Then the host program on the real generators of \(E\) for \(Y\) and \(a\), started at the init generator's start label with state bit false on \(S_0\), reaches its final label within the step bound \(\mathrm{realB}(E, Y, m, T)\) (the five generators' bounds plus five chaining steps), with some state bit and with output stack the dense encoding of the formula \(\Phi(E, x, Y, a, m, T)\) followed by \(o\).
theorem real_run (x Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) (m T : ℕ) (hx : x.length ≤ m)
(S₀ : ∀ k, List (HΓ E.layout.g k)) (o : List Bool) (ho : S₀ .out = o)
(hin : S₀ .inp = (x.map (InitFamily.encF E)).reverse)
(cu : ∀ z, S₀ (.up z) = cnt () (Family.initF T (capH m T (depth M)) z))
(cs : ∀ z, S₀ (.sd z) = cnt () (Family.initF T (capH m T (depth M)) z))
(ch : ∀ z, S₀ (.sh z) = cnt () (Shift.initF T (capH m T (depth M)) z))
(ca : ∀ z, S₀ (.ac z) = cnt () (Accept.initF T (capH m T (depth M)) z))
(ci : ∀ z, S₀ (.ini z) = cnt () (InitFamily.initF T x.length (m - x.length)
(capH m T (depth M) - m) z)) :
∃ (v : Bool) (S : ∀ k, List (HΓ E.layout.g k)),
RunLe (realProg E Ys acc) (realB E Ys m T)
⟨some (.ini (.pre1 .eg)), false, S₀⟩ ⟨some .fin, v, S⟩ ∧
S .out = encodeCNF (Phi E x Ys acc m T) ++ o
abbrev HΓ (g : ℕ) : HK → Type
| .out => Bool
| .inp => Fin g
| .up _ => Unit
| .sd _ => Unit
| .sh _ => Unit
| .ac _ => Unit
| .ini _ => Unit
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:68
def encF (z : M.Γ M.k₀) : Fin E.layout.g := ⟨E.enc M.k₀ z, E.enc_lt _ z (E.input_mem z)⟩
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:1495
abbrev cnt {α : Type} (u : α) (n : ℕ) : List α := List.replicate n u
MathlibExt/Computability/TuringMachine/Program.lean:115
def initF (T H : ℕ) : CK → ℕ
| .Tn => T
| .Hs => H
| _ => 0
CSLibExt/Computability/Complexity/CookLevin/Family.lean:912
def capH (m T d : ℕ) : ℕ := m + (T + 1) * d + 1
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:1420
def depth (M : FinTM2) : ℕ :=
letI := M.ΛFin
Finset.univ.sup fun l => ops (M.m l)
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:231
def initF (T H : ℕ) : CK → ℕ
| .Tn => T
| .Hs => H
| _ => 0
CSLibExt/Computability/Complexity/CookLevin/Shift.lean:1251
def initF (T H : ℕ) : CK → ℕ
| .Tn => T
| .Hs => H
| _ => 0
CSLibExt/Computability/Complexity/CookLevin/Accept.lean:403
def initF (T n e f : ℕ) : CK → ℕ
| .Tn => T
| .Xn => n
| .En => e
| .Fn => f
| _ => 0
CSLibExt/Computability/Complexity/CookLevin/InitFamily.lean:1066
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
noncomputable abbrev realProg (Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) :=
hprog (Family.prog E.layout E.la E.na E.wa E.N) (Family.prog E.layout E.la E.sa E.wa E.N)
(Shift.prog E.layout E.sa E.pl E.cn E.pu E.N)
(Accept.prog E.layout E.A0 E.acode (E.kc M.k₁) (E.enc M.k₁ acc))
(InitFamily.iprog E.layout (E.lc (some M.main,
M.initialState)) (E.kc M.k₀) (InitFamily.ycs E Ys))
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:362
noncomputable def realB (Ys : List (M.Γ M.k₀)) (m T : ℕ) : ℕ :=
InitFamily.initC E.layout (InitFamily.ycs E Ys).length (E.kc M.k₀) * (T + capH m T (depth M) + 1) ^ 5 +
Family.genC E.layout E.N * (T + capH m T (depth M) + 1) ^ 5 +
Family.genC E.layout E.N * (T + capH m T (depth M) + 1) ^ 5 +
Shift.shC E.layout E.N * (T + capH m T (depth M) + 1) ^ 6 +
Accept.accC E.layout E.A0 (E.kc M.k₁) * (T + capH m T (depth M) + 1) ^ 4 + 5
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:378
def encodeCNF (φ : CNF) : List Bool := φ.flatMap encodeClause
CSLibExt/Computability/Complexity/DenseSAT.lean:90
noncomputable def Phi (x Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) (m T : ℕ) : CNF :=
E.accFamily acc T (capH m T (depth M)) ++
(Shift.shFamily E.layout E.sa E.pl E.cn E.pu E.N T (capH m T (depth M)) ++
(Family.family E.layout E.la E.sa E.wa T (capH m T (depth M)) E.N ++
(Family.family E.layout E.la E.na E.wa T (capH m T (depth M)) E.N ++
E.initFamily x Ys m T (capH m T (depth M)))))
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:370
Uses 66 · Used by 1
TheoremCorrectness of the assembled formula#✓fully proved
Let \(M\) be a finite multi-stack Turing machine with encoding data \(E\), let \(x\) and \(Y\) be lists of input symbols of \(M\), let \(\mathit{acc}\) be an output symbol of \(M\), and let \(m, T \in \mathbb{N}\). Suppose that \(|x| \le m\) and that \(\mathit{acc}\) is one of the effective symbols of the output stack under \(E\). Then the formula \(\Phi(x, Y, \mathit{acc}, m, T)\) emitted by the host is satisfiable if and only if there is a list \(y\) of input symbols, all belonging to \(Y\), such that the concatenation \(xy\) has length at most \(m\) and the idle-extended run of \(M\) from the initial configuration on input \(xy\) is, after \(T\) steps, an accepting configuration for \(\mathit{acc}\): halted, in the initial internal state, with \(\mathit{acc}\) on top of the output stack.
The proof carries the soundness and completeness of the five families through the concatenation.
theorem phi_iff {x Ys : List (M.Γ M.k₀)} {acc : M.Γ M.k₁} {m T : ℕ} (hx : x.length ≤ m)
(hacc : ∃ i, E.dec M.k₁ i = acc) :
(∃ a, cnfSat (Phi E x Ys acc m T) a) ↔
∃ y : List (M.Γ M.k₀), (∀ z ∈ y, z ∈ Ys) ∧ (x ++ y).length ≤ m ∧
Accepts M (runI M (initList M (x ++ y)) T) acc
def cnfSat (φ : CNF) (a : List Bool) : Prop :=
∀ c ∈ φ, clauseSat c a
CSLibExt/Computability/Complexity/DenseSAT.lean:67
noncomputable def Phi (x Ys : List (M.Γ M.k₀)) (acc : M.Γ M.k₁) (m T : ℕ) : CNF :=
E.accFamily acc T (capH m T (depth M)) ++
(Shift.shFamily E.layout E.sa E.pl E.cn E.pu E.N T (capH m T (depth M)) ++
(Family.family E.layout E.la E.sa E.wa T (capH m T (depth M)) E.N ++
(Family.family E.layout E.la E.na E.wa T (capH m T (depth M)) E.N ++
E.initFamily x Ys m T (capH m T (depth M)))))
CSLibExt/Computability/Complexity/CookLevin/Assembly.lean:370
def Accepts (M : FinTM2) (c : M.Cfg) (acc : M.Γ M.k₁) : Prop :=
c.l = none ∧ c.var = M.initialState ∧ (c.stk M.k₁).head? = some acc
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:2019
def runI (M : FinTM2) (c : M.Cfg) : ℕ → M.Cfg
| 0 => c
| t + 1 => stepI M (runI M c t)
CSLibExt/Computability/Complexity/CookLevin/Situation.lean:691
Uses 24 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.