Buckets:
cfahlgren1/math / lean /OAI /Computability /UniqueGames /Machines /MachineExpanderFamilyTransferLemmas.lean
| import OAI.Computability.UniqueGames.Machines.MachineExpanderFamilyTapes | |
| import OAI.Computability.UniqueGames.Machines.MachineExpanderTableProgramLemmas | |
| namespace OAI | |
| /-! | |
| # Actual family-table installation and counter cleanup | |
| Checked physical drain and transfer loops are placed in the family program | |
| through its finite register equivalence. Alphabet equality transports their | |
| actual traces back to the dependent alphabet of the full family machine. | |
| -/ | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachineExpanderFamily | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl | |
| section Composition | |
| open MachineComposition | |
| theorem controlStatementInverse {K Λ σ τ : Type} {Γ : K → Type} | |
| (states : σ ≃ τ) (q : TM2.Stmt Γ Λ σ) : | |
| MachineControl.statement id states.symm (MachineControl.statement id states q) = q := by | |
| induction q <;> | |
| simp_all only [MachineControl.statement, Equiv.apply_symm_apply, | |
| Equiv.symm_apply_apply, id_eq] | |
| /-- Static state-coordinate transport preserves every actual transition. -/ | |
| theorem controlTrace {K Λ σ τ : Type} {Γ : K → Type} [DecidableEq K] | |
| (states : σ ≃ τ) (target : Λ → TM2.Stmt Γ Λ τ) | |
| (n : Nat) (start finish : TM2.Cfg Γ Λ σ) | |
| (run : (advance (TM2.step (MachineControl.program (Equiv.refl Λ) states.symm target)))^[n] | |
| (some start) = some finish) : | |
| (advance (TM2.step target))^[n] | |
| (some (MachineControl.configuration id states start)) = | |
| some (MachineControl.configuration id states finish) := by | |
| let source := MachineControl.program (Equiv.refl Λ) states.symm target | |
| have roundtrip : MachineControl.program (Equiv.refl Λ) states source = target := by | |
| funext label | |
| change MachineControl.statement id states | |
| (MachineControl.statement id states.symm (target label)) = target label | |
| exact controlStatementInverse states.symm _ | |
| have simulation : ∀ a b, TM2.step source a = some b → | |
| TM2.step target (MachineControl.configuration id states a) = | |
| some (MachineControl.configuration id states b) := by | |
| intro a b hab | |
| have h := MachineControl.step_simulation (Equiv.refl Λ) states source a | |
| rw [roundtrip, hab] at h | |
| exact h | |
| exact liftSuccessfulTrace (TM2.step source) (TM2.step target) | |
| (MachineControl.configuration id states) simulation n start finish run | |
| theorem controlDrainTrace {K Λ σ τ : Type} [DecidableEq K] | |
| (states : (σ × Option Bool) ≃ τ) (source : K) (again : Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ τ) | |
| (code : target again = MachineControl.statement id states | |
| (MachineDrain.drain source again exit)) | |
| (base : K → List Bool) (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step target))^[(base source).length + 1] | |
| (some ⟨some again, states (ambient, register), base⟩) = | |
| some ⟨exit, states (ambient, none), Function.update base source []⟩ := by | |
| let raw := MachineControl.program (Equiv.refl Λ) states.symm target | |
| have atRaw : raw again = MachineDrain.drain source again exit := by | |
| change MachineControl.statement id states.symm (target again) = _ | |
| rw [code] | |
| exact controlStatementInverse states _ | |
| have run := MachineDrain.drainTrace source again exit raw atRaw base (base source) ambient register | |
| simp only [Function.update_eq_self] at run | |
| simpa only [MachineControl.configuration, Option.map_some, id_eq, Option.map_id] using | |
| controlTrace states target ((base source).length + 1) _ _ run | |
| theorem controlTransferTrace {K Λ σ τ : Type} [DecidableEq K] | |
| (states : (σ × Option Bool) ≃ τ) (source destination : K) | |
| (distinct : source ≠ destination) (again : Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ τ) | |
| (code : target again = MachineControl.statement id states | |
| (Reduction.MachineTransfer.loopAt source destination id false again exit)) | |
| (base : K → List Bool) (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step target))^[(base source).length + 1] | |
| (some ⟨some again, states (ambient, register), base⟩) = | |
| some ⟨exit, states (ambient, none), | |
| Reduction.MachineTransfer.tapesAt source destination base [] | |
| ((base source).reverse ++ base destination)⟩ := by | |
| let raw := MachineControl.program (Equiv.refl Λ) states.symm target | |
| have atRaw : raw again = Reduction.MachineTransfer.loopAt source destination id false again exit := by | |
| change MachineControl.statement id states.symm (target again) = _ | |
| rw [code] | |
| exact controlStatementInverse states _ | |
| have run := Reduction.MachineTransfer.transferAt_fromTapes source destination distinct id false | |
| again exit raw atRaw base ambient register | |
| unfold Reduction.MachineTransfer.nextAt at run | |
| simpa only [MachineControl.configuration, Option.map_some, id_eq, Option.map_id, | |
| List.map_id] using controlTrace states target ((base source).length + 1) _ _ run | |
| section TransferVariables | |
| variable {ρ : Type} {d : Nat} | |
| def clearRegister (state : State ρ d) : State ρ d := | |
| (MachineExpanderTable.clearRegister state.1, state.2) | |
| @[simp] theorem registerStates_reset (state : State ρ d) : | |
| registerStates ρ d (((registerStates ρ d).symm state).1, none) = | |
| clearRegister state := rfl | |
| @[simp] theorem clearRegister_idempotent (state : State ρ d) : | |
| clearRegister (clearRegister state) = clearRegister state := rfl | |
| @[simp] theorem caller_clearRegister (state : State ρ d) : | |
| caller (clearRegister state) = caller state := rfl | |
| @[simp] theorem clearRegister_position (state : State ρ d) : | |
| (clearRegister state).1.2 = state.1.2 := rfl | |
| @[simp] theorem clearRegister_register (state : State ρ d) : | |
| (clearRegister state).1.1.2 = none := rfl | |
| variable [Fintype ρ] | |
| /-- The Boolean view is the same actual program under alphabet equality. -/ | |
| theorem boolTraceActual (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (n : Nat) | |
| (start finish : TM2.Cfg BoolAlphabet (Label d) (State ρ d)) | |
| (run : (advance (TM2.step (boolView positive H growth)))^[n] (some start) = some finish) : | |
| (advance (TM2.step (program positive H growth)))^[n] | |
| (some (MachineAlphabetTransport.configuration alphabet_eq.symm start)) = | |
| some (MachineAlphabetTransport.configuration alphabet_eq.symm finish) := by | |
| have h := MachineAlphabetTransport.successfulTrace alphabet_eq.symm | |
| (boolView positive H growth) n start finish run | |
| simpa only [boolView, MachineAlphabetTransport.program_symm_roundtrip] using h | |
| theorem drainBoolTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (source : Tape) (again next : OuterLabel) | |
| (code : boolOuterStatement (ρ := ρ) positive H again = drainStatement source again next) | |
| (base : Tape → List Bool) (state : State ρ d) : | |
| (advance (TM2.step (boolView positive H growth)))^[(base source).length + 1] | |
| (some ⟨some (.inr again), state, base⟩) = | |
| some ⟨some (.inr next), clearRegister state, Function.update base source []⟩ := by | |
| have atLoop : boolView (ρ := ρ) positive H growth (.inr again) = | |
| MachineControl.statement id (registerStates ρ d) | |
| (MachineDrain.drain source (.inr again) (some (.inr next))) := by | |
| rw [boolView_outer, code] | |
| rfl | |
| have h := controlDrainTrace (registerStates ρ d) source (.inr again) (some (.inr next)) | |
| (boolView positive H growth) atLoop base | |
| ((registerStates ρ d).symm state).1 ((registerStates ρ d).symm state).2 | |
| simpa only [Prod.mk.eta, Equiv.apply_symm_apply, registerStates_reset] using h | |
| theorem transferBoolTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (source destination : Tape) (distinct : source ≠ destination) | |
| (again next : OuterLabel) | |
| (code : boolOuterStatement (ρ := ρ) positive H again = | |
| MachineControl.statement id (registerStates ρ d) | |
| (Reduction.MachineTransfer.loopAt (Γ := BoolAlphabet) source destination id false | |
| (.inr again) (some (.inr next)))) | |
| (base : Tape → List Bool) (state : State ρ d) : | |
| (advance (TM2.step (boolView positive H growth)))^[(base source).length + 1] | |
| (some ⟨some (.inr again), state, base⟩) = | |
| some ⟨some (.inr next), clearRegister state, | |
| Reduction.MachineTransfer.tapesAt source destination base [] | |
| ((base source).reverse ++ base destination)⟩ := by | |
| have atLoop : boolView (ρ := ρ) positive H growth (.inr again) = | |
| MachineControl.statement id (registerStates ρ d) | |
| (Reduction.MachineTransfer.loopAt source destination id false | |
| (.inr again) (some (.inr next))) := by | |
| rw [boolView_outer, code] | |
| have h := controlTransferTrace (registerStates ρ d) source destination distinct | |
| (.inr again) (some (.inr next)) (boolView positive H growth) atLoop base | |
| ((registerStates ρ d).symm state).1 ((registerStates ρ d).symm state).2 | |
| simpa only [Prod.mk.eta, Equiv.apply_symm_apply, registerStates_reset] using h | |
| /-- Only these four tape words change during installation. -/ | |
| def installedTapes (base : Tape → List Bool) (newWord : List Bool) : Tape → List Bool := | |
| Function.update | |
| (Function.update | |
| (Function.update (Function.update base tableTape newWord) resultTape []) | |
| (.inr .tableReverse) []) | |
| (.inr .currentSize) [] | |
| def cleanedCounterTapes (base : Tape → List Bool) : Tape → List Bool := | |
| Function.update (Function.update base inputVertexTape []) vertexCountTape [] | |
| theorem installTableBoolTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (newWord : List Bool) | |
| (resultWord : base resultTape = newWord) (reverseEmpty : base (.inr .tableReverse) = []) | |
| (state : State ρ d) : | |
| (advance (TM2.step (boolView positive H growth)))^[ | |
| (base tableTape).length + 2 * newWord.length + (base (.inr .currentSize)).length + 4] | |
| (some ⟨some (.inr .clearOldTable), state, base⟩) = | |
| some ⟨some (.inr (.affine .multiplySize .seed)), clearRegister state, | |
| installedTapes base newWord⟩ := by | |
| let b0 := Function.update base tableTape [] | |
| let b1 := Function.update (Function.update b0 resultTape []) (.inr .tableReverse) newWord.reverse | |
| let b2 := Function.update (Function.update b1 (.inr .tableReverse) []) tableTape newWord | |
| let b3 := Function.update b2 (.inr .currentSize) [] | |
| have h0 := drainBoolTrace positive H growth tableTape .clearOldTable .reverseResult rfl base state | |
| have b0Result : b0 resultTape = newWord := by | |
| simpa [b0, tableTape, resultTape] using resultWord | |
| have b0Reverse : b0 (.inr .tableReverse) = [] := by | |
| simpa [b0, tableTape] using reverseEmpty | |
| have h1 : (advance (TM2.step (boolView positive H growth)))^[newWord.length + 1] | |
| (some ⟨some (.inr .reverseResult), clearRegister state, b0⟩) = | |
| some ⟨some (.inr .reverseTable), clearRegister state, b1⟩ := by | |
| simpa only [b0Result, b0Reverse, List.append_nil, Reduction.MachineTransfer.tapesAt, | |
| clearRegister_idempotent] using | |
| transferBoolTrace positive H growth resultTape (.inr .tableReverse) (by decide) | |
| .reverseResult .reverseTable rfl b0 (clearRegister state) | |
| have b1Reverse : b1 (.inr .tableReverse) = newWord.reverse := by simp [b1] | |
| have b1Table : b1 tableTape = [] := by simp [b1, b0, tableTape, resultTape] | |
| have h2 : (advance (TM2.step (boolView positive H growth)))^[newWord.length + 1] | |
| (some ⟨some (.inr .reverseTable), clearRegister state, b1⟩) = | |
| some ⟨some (.inr .clearCurrentSize), clearRegister state, b2⟩ := by | |
| simpa only [b1Reverse, b1Table, List.reverse_reverse, List.length_reverse, | |
| List.append_nil, Reduction.MachineTransfer.tapesAt, clearRegister_idempotent] using | |
| transferBoolTrace positive H growth (.inr .tableReverse) tableTape (by decide) | |
| .reverseTable .clearCurrentSize rfl b1 (clearRegister state) | |
| have b2Current : b2 (.inr .currentSize) = base (.inr .currentSize) := by | |
| simp [b2, b1, b0, tableTape, resultTape] | |
| have h3 : (advance (TM2.step (boolView positive H growth)))^[ | |
| (base (.inr .currentSize)).length + 1] | |
| (some ⟨some (.inr .clearCurrentSize), clearRegister state, b2⟩) = | |
| some ⟨some (.inr (.affine .multiplySize .seed)), clearRegister state, b3⟩ := by | |
| simpa only [b2Current, clearRegister_idempotent] using | |
| drainBoolTrace positive H growth (.inr .currentSize) .clearCurrentSize | |
| (.affine .multiplySize .seed) rfl b2 (clearRegister state) | |
| have final : b3 = installedTapes base newWord := by | |
| funext tape | |
| rcases tape with table | extra | |
| · rcases table with row | tableExtra | |
| · cases row <;> simp [b3, b2, b1, b0, installedTapes, tableTape, resultTape] | |
| · cases tableExtra <;> simp [b3, b2, b1, b0, installedTapes, tableTape, resultTape] | |
| · cases extra <;> simp [b3, b2, b1, b0, installedTapes, tableTape, resultTape] | |
| rw [show (base tableTape).length + 2 * newWord.length + | |
| (base (.inr .currentSize)).length + 4 = | |
| ((base (.inr .currentSize)).length + 1) + | |
| ((newWord.length + 1) + ((newWord.length + 1) + ((base tableTape).length + 1))) by omega, | |
| Function.iterate_add_apply _ ((base (.inr .currentSize)).length + 1), | |
| Function.iterate_add_apply _ (newWord.length + 1) ((newWord.length + 1) + ((base tableTape).length + 1)), | |
| Function.iterate_add_apply _ (newWord.length + 1) ((base tableTape).length + 1), | |
| h0, h1, h2, h3, final] | |
| theorem cleanupCountersBoolTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (state : State ρ d) : | |
| (advance (TM2.step (boolView positive H growth)))^[ | |
| (base inputVertexTape).length + (base vertexCountTape).length + 2] | |
| (some ⟨some (.inr .drainInputVertex), state, base⟩) = | |
| some ⟨some (.inr .levelGuard), clearRegister state, cleanedCounterTapes base⟩ := by | |
| have h0 := drainBoolTrace positive H growth inputVertexTape .drainInputVertex .drainVertexCount | |
| rfl base state | |
| have count : (Function.update base inputVertexTape []) vertexCountTape = base vertexCountTape := by | |
| simp [inputVertexTape, vertexCountTape] | |
| have h1 := drainBoolTrace positive H growth vertexCountTape .drainVertexCount .levelGuard | |
| rfl (Function.update base inputVertexTape []) (clearRegister state) | |
| simp only [count, clearRegister_idempotent] at h1 | |
| rw [show (base inputVertexTape).length + (base vertexCountTape).length + 2 = | |
| ((base vertexCountTape).length + 1) + ((base inputVertexTape).length + 1) by omega, | |
| Function.iterate_add_apply, h0] | |
| exact h1 | |
| /-- Actual dependent-alphabet trace for draining the old table, installing the | |
| new forward table by two physical reversals, and clearing the old size word. -/ | |
| theorem installTableTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (newWord : List Bool) (resultWord : toBoolTapes base resultTape = newWord) | |
| (reverseEmpty : toBoolTapes base (.inr .tableReverse) = []) (state : State ρ d) : | |
| (advance (TM2.step (program positive H growth)))^[ | |
| (toBoolTapes base tableTape).length + 2 * newWord.length + | |
| (toBoolTapes base (.inr .currentSize)).length + 4] | |
| (some ⟨some (.inr .clearOldTable), state, base⟩) = | |
| some ⟨some (.inr (.affine .multiplySize .seed)), clearRegister state, | |
| fromBoolTapes (installedTapes (toBoolTapes base) newWord)⟩ := by | |
| have h := installTableBoolTrace positive H growth (toBoolTapes base) newWord resultWord reverseEmpty state | |
| simpa only [configuration_fromBool, fromBool_toBool] using boolTraceActual positive H growth _ _ _ h | |
| /-- After the checked affine phase, both table-loop counters are physically | |
| drained and the actual family level guard is reached. -/ | |
| theorem cleanupCountersTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (state : State ρ d) : | |
| (advance (TM2.step (program positive H growth)))^[ | |
| (toBoolTapes base inputVertexTape).length + (toBoolTapes base vertexCountTape).length + 2] | |
| (some ⟨some (.inr .drainInputVertex), state, base⟩) = | |
| some ⟨some (.inr .levelGuard), clearRegister state, | |
| fromBoolTapes (cleanedCounterTapes (toBoolTapes base))⟩ := by | |
| have h := cleanupCountersBoolTrace positive H growth (toBoolTapes base) state | |
| simpa only [configuration_fromBool, fromBool_toBool] using boolTraceActual positive H growth _ _ _ h | |
| def installTableInTime (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (newWord : List Bool) (resultWord : toBoolTapes base resultTape = newWord) | |
| (reverseEmpty : toBoolTapes base (.inr .tableReverse) = []) (state : State ρ d) : | |
| StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr .clearOldTable), state, base⟩ | |
| (some ⟨some (.inr (.affine .multiplySize .seed)), clearRegister state, | |
| fromBoolTapes (installedTapes (toBoolTapes base) newWord)⟩) | |
| ((toBoolTapes base tableTape).length + 2 * newWord.length + | |
| (toBoolTapes base (.inr .currentSize)).length + 4) where | |
| steps := (toBoolTapes base tableTape).length + 2 * newWord.length + | |
| (toBoolTapes base (.inr .currentSize)).length + 4 | |
| evals_in_steps := installTableTrace positive H growth base newWord resultWord reverseEmpty state | |
| steps_le_m := Nat.le_refl _ | |
| def cleanupCountersInTime (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (state : State ρ d) : | |
| StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr .drainInputVertex), state, base⟩ | |
| (some ⟨some (.inr .levelGuard), clearRegister state, | |
| fromBoolTapes (cleanedCounterTapes (toBoolTapes base))⟩) | |
| ((toBoolTapes base inputVertexTape).length + (toBoolTapes base vertexCountTape).length + 2) where | |
| steps := (toBoolTapes base inputVertexTape).length + (toBoolTapes base vertexCountTape).length + 2 | |
| evals_in_steps := cleanupCountersTrace positive H growth base state | |
| steps_le_m := Nat.le_refl _ | |
| end TransferVariables | |
| theorem affine_source_ne_scratch (phase : AffinePhase) : | |
| affineSource phase ≠ .inr .unaryScratch := by cases phase <;> decide | |
| theorem affine_source_ne_destination (phase : AffinePhase) : | |
| affineSource phase ≠ affineDestination phase := by cases phase <;> decide | |
| theorem affine_scratch_ne_destination (phase : AffinePhase) : | |
| (.inr .unaryScratch : Tape) ≠ affineDestination phase := by cases phase <;> decide | |
| /-- Exact final dependent tape family, with all other tape contents retained. -/ | |
| def affineResultTapes (d : Nat) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) : | |
| (tape : Tape) → List (Alphabet tape) := | |
| Function.update base (affineDestination phase) | |
| (boolWord (affineDestination phase) | |
| (encodeWord (affineCoefficient d phase * n) ++ toBoolTapes base (affineDestination phase))) | |
| theorem affineResultTapes_other (d : Nat) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) (tape : Tape) | |
| (different : tape ≠ affineDestination phase) : | |
| affineResultTapes d phase base n tape = base tape := by | |
| simp [affineResultTapes, different] | |
| theorem affineResultTapes_source (d : Nat) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) : | |
| affineResultTapes d phase base n (affineSource phase) = base (affineSource phase) := | |
| affineResultTapes_other d phase base n _ (affine_source_ne_destination phase) | |
| theorem affineResultTapes_scratch (d : Nat) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) : | |
| affineResultTapes d phase base n (.inr .unaryScratch) = base (.inr .unaryScratch) := | |
| affineResultTapes_other d phase base n _ (affine_scratch_ne_destination phase) | |
| theorem affineResultTapes_destination (d : Nat) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) : | |
| toBoolTapes (affineResultTapes d phase base n) (affineDestination phase) = | |
| encodeWord (affineCoefficient d phase * n) ++ toBoolTapes base (affineDestination phase) := by | |
| simp [affineResultTapes, toBoolTapes] | |
| variable {ρ : Type} [Fintype ρ] {d : Nat} | |
| /-- The concrete Boolean view is pulled into unary-affine state coordinates, | |
| executed from its actual statements, and transported back without extra steps. -/ | |
| theorem affinePhaseBoolTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (phase : AffinePhase) (base : Tape → List Bool) | |
| (n : Nat) (suffix : List Bool) | |
| (sourceWord : base (affineSource phase) = encodeWord n ++ suffix) | |
| (scratchEmpty : base (.inr .unaryScratch) = []) (state : State ρ d) : | |
| (advance (TM2.step (boolView positive H growth)))^[2 * (n + 1) + 1] | |
| (some ⟨some (.inr (.affine phase .seed)), state, base⟩) = | |
| some ⟨some (affineExit d phase), clearRegister state, | |
| Function.update base (affineDestination phase) | |
| (encodeWord (affineCoefficient d phase * n) ++ base (affineDestination phase))⟩ := by | |
| let states := registerStates ρ d | |
| let target := boolView (ρ := ρ) positive H growth | |
| let sourceProgram := MachineControl.program (Equiv.refl (Label d)) states.symm target | |
| have atSeed : sourceProgram (.inr (.affine phase .seed)) = | |
| MachineUnaryAffineAt.seed (affineDestination phase) 0 (.inr (.affine phase .scan)) := by | |
| change MachineControl.statement id states.symm | |
| (boolView positive H growth (.inr (.affine phase .seed))) = _ | |
| rw [boolView_outer] | |
| exact controlStatementInverse states _ | |
| have atScan : sourceProgram (.inr (.affine phase .scan)) = | |
| MachineUnaryAffineAt.scan (affineSource phase) (.inr .unaryScratch) | |
| (affineDestination phase) (affineCoefficient d phase) | |
| (.inr (.affine phase .scan)) (.inr (.affine phase .restore)) := by | |
| change MachineControl.statement id states.symm | |
| (boolView positive H growth (.inr (.affine phase .scan))) = _ | |
| rw [boolView_outer] | |
| exact controlStatementInverse states _ | |
| have atRestore : sourceProgram (.inr (.affine phase .restore)) = | |
| Reduction.MachineTransfer.loopAt (.inr .unaryScratch) (affineSource phase) id false | |
| (.inr (.affine phase .restore)) (some (affineExit d phase)) := by | |
| change MachineControl.statement id states.symm | |
| (boolView positive H growth (.inr (.affine phase .restore))) = _ | |
| rw [boolView_outer] | |
| exact controlStatementInverse states _ | |
| have raw := MachineUnaryAffineAt.seededAffineTrace | |
| (affineSource phase) (.inr .unaryScratch) (affineDestination phase) | |
| (affine_source_ne_scratch phase) (affine_source_ne_destination phase) | |
| (affine_scratch_ne_destination phase) (affineCoefficient d phase) 0 | |
| (.inr (.affine phase .seed)) (.inr (.affine phase .scan)) (.inr (.affine phase .restore)) | |
| (some (affineExit d phase)) sourceProgram atSeed atScan atRestore base n suffix | |
| sourceWord scratchEmpty (states.symm state).1 (states.symm state).2 | |
| have run := controlTrace states target (2 * (n + 1) + 1) _ _ raw | |
| simpa only [states, target, MachineControl.configuration, Option.map_some, id_eq, Prod.mk.eta, | |
| Equiv.apply_symm_apply, Nat.add_zero, registerStates_reset] using run | |
| /-- Actual family-program execution. Alphabet conversion is static equality | |
| transport; the transition count is exactly the checked unary-affine count. -/ | |
| theorem affinePhaseTrace (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) (suffix : List Bool) | |
| (sourceWord : toBoolTapes base (affineSource phase) = encodeWord n ++ suffix) | |
| (scratchEmpty : base (.inr .unaryScratch) = []) (state : State ρ d) : | |
| (advance (TM2.step (program positive H growth)))^[2 * (n + 1) + 1] | |
| (some ⟨some (.inr (.affine phase .seed)), state, base⟩) = | |
| some ⟨some (affineExit d phase), clearRegister state, | |
| affineResultTapes d phase base n⟩ := by | |
| have raw := affinePhaseBoolTrace positive H growth phase (toBoolTapes base) n suffix | |
| sourceWord scratchEmpty state | |
| have transported := boolTraceActual positive H growth (2 * (n + 1) + 1) _ _ raw | |
| simpa only [configuration_fromBool, fromBoolTapes_update, fromBool_toBool, | |
| affineResultTapes] using transported | |
| def affinePhaseInTime (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (phase : AffinePhase) | |
| (base : (tape : Tape) → List (Alphabet tape)) (n : Nat) (suffix : List Bool) | |
| (sourceWord : toBoolTapes base (affineSource phase) = encodeWord n ++ suffix) | |
| (scratchEmpty : base (.inr .unaryScratch) = []) (state : State ρ d) : | |
| StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr (.affine phase .seed)), state, base⟩ | |
| (some ⟨some (affineExit d phase), clearRegister state, | |
| affineResultTapes d phase base n⟩) (2 * (n + 1) + 1) where | |
| steps := 2 * (n + 1) + 1 | |
| evals_in_steps := affinePhaseTrace positive H growth phase base n suffix sourceWord scratchEmpty state | |
| steps_le_m := Nat.le_refl _ | |
| def copyCountInTime (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (n : Nat) (sourceWord : base (.inr .currentSize) = encodeWord n) | |
| (scratchEmpty : base (.inr .unaryScratch) = []) | |
| (destinationEmpty : base vertexCountTape = []) (state : State ρ d) : | |
| StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr (.affine .copyCount .seed)), state, base⟩ | |
| (some ⟨some (.inl (.inr .initialize)), clearRegister state, | |
| Function.update base vertexCountTape (encodeWord n)⟩) (2 * (n + 1) + 1) := by | |
| have run := affinePhaseInTime positive H growth .copyCount base n [] | |
| (by simpa only [affineSource, toBoolTapes, toBoolWord, List.append_nil] using sourceWord) | |
| scratchEmpty state | |
| change base (.inl (.inr .vertexCount)) = [] at destinationEmpty | |
| simpa only [affineExit, affineResultTapes, affineDestination, affineCoefficient, | |
| Nat.one_mul, vertexCountTape, boolWord, toBoolTapes, toBoolWord, | |
| destinationEmpty, List.append_nil] using run | |
| def multiplySizeInTime (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : (tape : Tape) → List (Alphabet tape)) | |
| (n : Nat) (sourceWord : base inputVertexTape = encodeWord n) | |
| (scratchEmpty : base (.inr .unaryScratch) = []) | |
| (destinationEmpty : base (.inr .currentSize) = []) (state : State ρ d) : | |
| StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr (.affine .multiplySize .seed)), state, base⟩ | |
| (some ⟨some (.inr .drainInputVertex), clearRegister state, | |
| Function.update base (.inr .currentSize) (encodeWord (cloudSize d * n))⟩) | |
| (2 * (n + 1) + 1) := by | |
| have run := affinePhaseInTime positive H growth .multiplySize base n [] | |
| (by simpa only [affineSource, inputVertexTape, toBoolTapes, toBoolWord, | |
| List.append_nil] using sourceWord) | |
| scratchEmpty state | |
| simpa only [affineExit, affineResultTapes, affineDestination, affineCoefficient, | |
| boolWord, toBoolTapes, toBoolWord, destinationEmpty, List.append_nil] using run | |
| end Composition | |
| variable {ρ : Type} {d : Nat} | |
| @[simp] theorem caller_initialState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ambient : ρ) : caller (initialState positive H ambient) = ambient := rfl | |
| @[simp] theorem caller_normalizeState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (state : State ρ d) : caller (normalizeState positive H state) = caller state := rfl | |
| @[simp] theorem clearRegister_initialState (positive : 0 < d) | |
| (H : Table (cloudSize d) d) (ambient : ρ) : | |
| clearRegister (initialState positive H ambient) = initialState positive H ambient := rfl | |
| /-- The guard changes only the physical remaining-level word. -/ | |
| theorem boundaryTapes_update_level (remaining current next : Nat) | |
| (word suffix : List Bool) : | |
| Function.update (boundaryTapes remaining current word suffix) | |
| (.inr .remainingLevel) (encodeWord next ++ suffix) = | |
| boundaryTapes next current word suffix := by | |
| funext tape | |
| rcases tape with tape | extra | |
| · rcases tape with row | extra | |
| · cases row <;> simp [boundaryTapes, tableFrame, MachineEmbedding.tapes, Function.update] | |
| · cases extra <;> simp [boundaryTapes, tableFrame, MachineEmbedding.tapes, Function.update] | |
| · cases extra <;> simp [boundaryTapes, extraFrame, MachineEmbedding.tapes, Function.update] | |
| /-- The two literal prefixes install the actual level-zero table and unary one. -/ | |
| theorem initialTapes_initialize (level : Nat) (suffix : List Bool) : | |
| Function.update | |
| (Function.update (initialTapes level suffix) tableTape (initialEncoding d)) | |
| (.inr .currentSize) (encodeWord 1) = | |
| boundaryTapes level 1 (initialEncoding d) suffix := by | |
| funext tape | |
| rcases tape with tape | extra | |
| · rcases tape with row | extra | |
| · cases row <;> simp [initialTapes, boundaryTapes, tableFrame, | |
| MachineEmbedding.tapes, Function.update, tableTape] | |
| · cases extra <;> simp [initialTapes, boundaryTapes, tableFrame, | |
| MachineEmbedding.tapes, Function.update, tableTape] | |
| · cases extra <;> simp [initialTapes, boundaryTapes, extraFrame, | |
| MachineEmbedding.tapes, Function.update, tableTape] | |
| variable [Fintype ρ] | |
| /-- Static alphabet transport preserves this actual single transition. -/ | |
| theorem actualStep_of_boolStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) | |
| (start finish : TM2.Cfg BoolAlphabet (Label d) (State ρ d)) | |
| (run : TM2.step (boolView positive H growth) start = some finish) : | |
| TM2.step (program positive H growth) | |
| (MachineAlphabetTransport.configuration alphabet_eq.symm start) = | |
| some (MachineAlphabetTransport.configuration alphabet_eq.symm finish) := by | |
| have h := MachineAlphabetTransport.step_simulation alphabet_eq.symm | |
| (boolView positive H growth) start | |
| rw [run] at h | |
| simpa only [boolView, MachineAlphabetTransport.program_symm_roundtrip, | |
| Option.map_some] using h | |
| theorem bool_initializeStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (state : State ρ d) : | |
| TM2.step (boolView positive H growth) ⟨some (.inr .initialize), state, base⟩ = | |
| some ⟨some (.inr .levelGuard), normalizeState positive H state, | |
| Function.update | |
| (Function.update base tableTape (initialEncoding d ++ base (.inl (.inl .table)))) | |
| (.inr .currentSize) (encodeWord 1 ++ base (.inr .currentSize))⟩ := by | |
| change some (TM2.stepAux (boolView positive H growth (.inr .initialize)) state base) = _ | |
| rw [boolView_outer] | |
| simp only [boolOuterStatement, Reduction.MachineSubstitution.stepAux_pushWord, | |
| List.reverse_reverse, TM2.stepAux] | |
| rfl | |
| theorem bool_levelGuard_succStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (state : State ρ d) | |
| (remaining : Nat) (suffix : List Bool) | |
| (counter : base (.inr .remainingLevel) = encodeWord (remaining + 1) ++ suffix) : | |
| TM2.step (boolView positive H growth) ⟨some (.inr .levelGuard), state, base⟩ = | |
| some ⟨some (.inr (.affine .copyCount .seed)), clearRegister state, | |
| Function.update base (.inr .remainingLevel) (encodeWord remaining ++ suffix)⟩ := by | |
| change some (TM2.stepAux (boolView positive H growth (.inr .levelGuard)) state base) = _ | |
| rw [boolView_outer] | |
| simp [boolOuterStatement, MachineControl.statement, MachineUnaryCounter.guard, | |
| TM2.stepAux, registerStates, clearRegister, MachineExpanderTable.clearRegister, | |
| counter, encodeWord, List.replicate_succ] | |
| theorem bool_levelGuard_zeroStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (state : State ρ d) | |
| (suffix : List Bool) | |
| (counter : base (.inr .remainingLevel) = encodeWord 0 ++ suffix) : | |
| TM2.step (boolView positive H growth) ⟨some (.inr .levelGuard), state, base⟩ = | |
| some ⟨some (.inr .done), clearRegister state, base⟩ := by | |
| change some (TM2.stepAux (boolView positive H growth (.inr .levelGuard)) state base) = _ | |
| rw [boolView_outer] | |
| simp [boolOuterStatement, MachineControl.statement, MachineUnaryCounter.guard, | |
| TM2.stepAux, registerStates, clearRegister, MachineExpanderTable.clearRegister, | |
| counter, encodeWord] | |
| theorem bool_doneStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : Tape → List Bool) (state : State ρ d) : | |
| TM2.step (boolView positive H growth) ⟨some (.inr .done), state, base⟩ = | |
| some ⟨none, normalizeState positive H state, base⟩ := by | |
| change some (TM2.stepAux (boolView positive H growth (.inr .done)) state base) = _ | |
| rw [boolView_outer] | |
| rfl | |
| /-- The literal initialization executes in one transition of the actual program. -/ | |
| theorem initializeStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) : | |
| TM2.step (program positive H growth) ⟨some (.inr .initialize), state, base⟩ = | |
| some ⟨some (.inr .levelGuard), normalizeState positive H state, | |
| Function.update | |
| (Function.update base tableTape (initialEncoding d ++ base (.inl (.inl .table)))) | |
| (.inr .currentSize) (encodeWord 1 ++ base (.inr .currentSize))⟩ := by | |
| have h := actualStep_of_boolStep positive H growth _ _ | |
| (bool_initializeStep positive H growth (toBoolTapes base) state) | |
| simp only [configuration_fromBool, fromBoolTapes_update, fromBool_toBool] at h | |
| exact h | |
| /-- A positive level physically loses one true bit, retaining its delimiter and suffix. -/ | |
| theorem levelGuard_succStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (remaining : Nat) (suffix : List Bool) | |
| (counter : base (.inr .remainingLevel) = encodeWord (remaining + 1) ++ suffix) : | |
| TM2.step (program positive H growth) ⟨some (.inr .levelGuard), state, base⟩ = | |
| some ⟨some (.inr (.affine .copyCount .seed)), clearRegister state, | |
| Function.update base (.inr .remainingLevel) (encodeWord remaining ++ suffix)⟩ := by | |
| have h := actualStep_of_boolStep positive H growth _ _ | |
| (bool_levelGuard_succStep positive H growth (toBoolTapes base) state | |
| remaining suffix counter) | |
| simpa only [configuration_fromBool, fromBoolTapes_update, fromBool_toBool, | |
| boolWord] using h | |
| /-- The zero delimiter is retained when the family loop enters its final halt. -/ | |
| theorem levelGuard_zeroStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (suffix : List Bool) | |
| (counter : base (.inr .remainingLevel) = encodeWord 0 ++ suffix) : | |
| TM2.step (program positive H growth) ⟨some (.inr .levelGuard), state, base⟩ = | |
| some ⟨some (.inr .done), clearRegister state, base⟩ := by | |
| have h := actualStep_of_boolStep positive H growth _ _ | |
| (bool_levelGuard_zeroStep positive H growth (toBoolTapes base) state suffix counter) | |
| simpa only [configuration_fromBool, fromBool_toBool] using h | |
| theorem doneStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) : | |
| TM2.step (program positive H growth) ⟨some (.inr .done), state, base⟩ = | |
| some ⟨none, normalizeState positive H state, base⟩ := by | |
| have h := actualStep_of_boolStep positive H growth _ _ | |
| (bool_doneStep positive H growth (toBoolTapes base) state) | |
| simpa only [configuration_fromBool, fromBool_toBool] using h | |
| theorem initialize_boundaryStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (level : Nat) (suffix : List Bool) (state : State ρ d) : | |
| TM2.step (program positive H growth) | |
| ⟨some (.inr .initialize), state, initialTapes level suffix⟩ = | |
| some ⟨some (.inr .levelGuard), initialState positive H (caller state), | |
| boundaryTapes level 1 (initialEncoding d) suffix⟩ := by | |
| have h := initializeStep positive H growth (initialTapes level suffix) state | |
| have ht : initialTapes level suffix (.inl (.inl .table)) = [] := rfl | |
| have hc : initialTapes level suffix (.inr .currentSize) = [] := rfl | |
| simp only [ht, hc, List.append_nil, normalizeState] at h | |
| exact h.trans (congrArg | |
| (fun tapes : ∀ tape, List (Alphabet tape) => | |
| (some ⟨some (.inr .levelGuard), initialState positive H (caller state), tapes⟩ : | |
| Option (TM2.Cfg Alphabet (Label d) (State ρ d)))) | |
| (initialTapes_initialize level suffix)) | |
| theorem levelGuard_boundary_succStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (remaining current : Nat) | |
| (word suffix : List Bool) (state : State ρ d) : | |
| TM2.step (program positive H growth) | |
| ⟨some (.inr .levelGuard), state, boundaryTapes (remaining + 1) current word suffix⟩ = | |
| some ⟨some (.inr (.affine .copyCount .seed)), clearRegister state, | |
| boundaryTapes remaining current word suffix⟩ := by | |
| simpa only [boundaryTapes_update_level] using | |
| levelGuard_succStep positive H growth | |
| (boundaryTapes (remaining + 1) current word suffix) state remaining suffix rfl | |
| theorem levelGuard_boundary_zeroStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (growth : 1 < cloudSize d) (current : Nat) | |
| (word suffix : List Bool) (state : State ρ d) : | |
| TM2.step (program positive H growth) | |
| ⟨some (.inr .levelGuard), state, boundaryTapes 0 current word suffix⟩ = | |
| some ⟨some (.inr .done), clearRegister state, | |
| boundaryTapes 0 current word suffix⟩ := | |
| levelGuard_zeroStep positive H growth | |
| (boundaryTapes 0 current word suffix) state suffix rfl | |
| end UniqueGamesTheorem.Foundations.Complexity.MachineExpanderFamily | |
| /-! | |
| # Concrete boundary steps of the expander-table machine | |
| Every execution theorem below reduces the actual common program statement. | |
| States and dependent tape frames are arbitrary; only the relevant unary word | |
| or finite-position branch is specified. No phase execution is a premise. | |
| -/ | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachineExpanderTable | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl | |
| variable {ρ : Type} {d : Nat} | |
| @[simp] theorem caller_boundaryState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ambient : ρ) (position : Position d) : | |
| caller (boundaryState positive H ambient position) = ambient := rfl | |
| @[simp] theorem prepareState_boundaryState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ambient : ρ) (position : Position d) : | |
| prepareState positive H (boundaryState positive H ambient position) = | |
| boundaryState positive H ambient position := rfl | |
| @[simp] theorem clearRegister_boundaryState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ambient : ρ) (position : Position d) : | |
| clearRegister (boundaryState positive H ambient position) = | |
| boundaryState positive H ambient position := rfl | |
| @[simp] theorem caller_prepareState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (state : State ρ d) : caller (prepareState positive H state) = caller state := rfl | |
| @[simp] theorem caller_resetState (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (state : State ρ d) : caller (resetState positive H state) = caller state := rfl | |
| @[simp] theorem caller_clearRegister (state : State ρ d) : | |
| caller (clearRegister state) = caller state := rfl | |
| @[simp] theorem caller_advancePositionState (positive : 0 < d) (state : State ρ d) : | |
| caller (advancePositionState positive state) = caller state := rfl | |
| @[simp] theorem caller_resetPositionState (positive : 0 < d) (state : State ρ d) : | |
| caller (resetPositionState positive state) = caller state := rfl | |
| theorem nextPosition_val_of_lt (positive : 0 < d) (position : Position d) | |
| (more : position.val + 1 < rowFactor d) : | |
| (nextPosition positive position).val = position.val + 1 := Nat.mod_eq_of_lt more | |
| /-- Replacing the count word leaves the entire row frame and result unchanged. -/ | |
| theorem boundaryTapes_update_count (vertex remaining next : Nat) | |
| (oldTable output countSuffix result : List Bool) : | |
| Function.update (boundaryTapes vertex remaining oldTable output countSuffix result) | |
| (.inr .vertexCount) (encodeWord next ++ countSuffix) = | |
| boundaryTapes vertex next oldTable output countSuffix result := by | |
| funext tape | |
| rcases tape with row | extra | |
| · cases row <;> simp [boundaryTapes, rowTapes, MachineEmbedding.tapes, Function.update] | |
| · cases extra <;> simp [boundaryTapes, extraTapes, MachineEmbedding.tapes, Function.update] | |
| /-- The last row's one actual push increments the unary vertex word. -/ | |
| theorem boundaryTapes_increment_vertex (vertex remaining : Nat) | |
| (oldTable output countSuffix result : List Bool) : | |
| Function.update (boundaryTapes vertex remaining oldTable output countSuffix result) | |
| (.inl .inputVertex) (true :: encodeWord vertex) = | |
| boundaryTapes (vertex + 1) remaining oldTable output countSuffix result := by | |
| funext tape | |
| rcases tape with row | extra | |
| · cases row <;> | |
| simp [boundaryTapes, rowTapes, MachineEmbedding.tapes, Function.update, | |
| encodeWord, List.replicate_succ] | |
| · cases extra <;> | |
| simp [boundaryTapes, extraTapes, MachineEmbedding.tapes, Function.update] | |
| theorem initialTapes_initialize (vertices : Nat) (oldTable countSuffix : List Bool) : | |
| Function.update (initialTapes vertices oldTable countSuffix) (.inl .inputVertex) [false] = | |
| boundaryTapes 0 vertices oldTable [] countSuffix [] := by | |
| funext tape | |
| rcases tape with row | extra | |
| · cases row <;> | |
| simp [initialTapes, boundaryTapes, rowTapes, MachineEmbedding.tapes, | |
| Function.update, encodeWord] | |
| · cases extra <;> | |
| simp [initialTapes, boundaryTapes, extraTapes, MachineEmbedding.tapes, | |
| Function.update] | |
| variable [Fintype ρ] | |
| theorem initializeStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) : | |
| TM2.step (program positive H) ⟨some (.inr .initialize), state, base⟩ = | |
| some ⟨some (.inr .vertexGuard), resetState positive H state, | |
| Function.update base (.inl .inputVertex) (false :: base (.inl .inputVertex))⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .initialize)) state base) = _ | |
| rw [program_outer] | |
| rfl | |
| theorem initialize_boundaryStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (vertices : Nat) (oldTable countSuffix : List Bool) (state : State ρ d) : | |
| TM2.step (program positive H) | |
| ⟨some (.inr .initialize), state, initialTapes vertices oldTable countSuffix⟩ = | |
| some ⟨some (.inr .vertexGuard), initialState positive H (caller state), | |
| boundaryTapes 0 vertices oldTable [] countSuffix []⟩ := by | |
| have h := initializeStep positive H (initialTapes vertices oldTable countSuffix) state | |
| have input : initialTapes vertices oldTable countSuffix (.inl .inputVertex) = [] := rfl | |
| simp only [input, resetState] at h | |
| exact h.trans (congrArg | |
| (fun tapes : ∀ tape, List (Alphabet tape) => | |
| (some ⟨some (.inr .vertexGuard), initialState positive H (caller state), tapes⟩ : | |
| Option (TM2.Cfg Alphabet (Label d) (State ρ d)))) | |
| (initialTapes_initialize vertices oldTable countSuffix)) | |
| /-- A positive vertex counter is physically decremented; its suffix remains. -/ | |
| theorem vertexGuard_succStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (remaining : Nat) (suffix : List Bool) | |
| (counter : base (.inr .vertexCount) = encodeWord (remaining + 1) ++ suffix) : | |
| TM2.step (program positive H) ⟨some (.inr .vertexGuard), state, base⟩ = | |
| some ⟨some (.inr .prepareRow), clearRegister state, | |
| Function.update base (.inr .vertexCount) (encodeWord remaining ++ suffix)⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .vertexGuard)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, MachineControl.statement, vertexGuardCore, TM2.stepAux, | |
| guardStates, clearRegister, counter, encodeWord, List.replicate_succ] | |
| /-- The zero delimiter is retained when the loop enters output reversal. -/ | |
| theorem vertexGuard_zeroStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (suffix : List Bool) | |
| (counter : base (.inr .vertexCount) = encodeWord 0 ++ suffix) : | |
| TM2.step (program positive H) ⟨some (.inr .vertexGuard), state, base⟩ = | |
| some ⟨some (.inr .reverseOutput), clearRegister state, base⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .vertexGuard)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, MachineControl.statement, vertexGuardCore, TM2.stepAux, | |
| guardStates, clearRegister, counter, encodeWord] | |
| theorem vertexGuard_boundary_succStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (vertex remaining : Nat) (oldTable output countSuffix result : List Bool) | |
| (state : State ρ d) : | |
| TM2.step (program positive H) | |
| ⟨some (.inr .vertexGuard), state, | |
| boundaryTapes vertex (remaining + 1) oldTable output countSuffix result⟩ = | |
| some ⟨some (.inr .prepareRow), clearRegister state, | |
| boundaryTapes vertex remaining oldTable output countSuffix result⟩ := by | |
| simpa only [boundaryTapes_update_count] using | |
| vertexGuard_succStep positive H | |
| (boundaryTapes vertex (remaining + 1) oldTable output countSuffix result) | |
| state remaining countSuffix rfl | |
| theorem vertexGuard_boundary_zeroStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (vertex : Nat) (oldTable output countSuffix result : List Bool) (state : State ρ d) : | |
| TM2.step (program positive H) | |
| ⟨some (.inr .vertexGuard), state, | |
| boundaryTapes vertex 0 oldTable output countSuffix result⟩ = | |
| some ⟨some (.inr .reverseOutput), clearRegister state, | |
| boundaryTapes vertex 0 oldTable output countSuffix result⟩ := | |
| vertexGuard_zeroStep positive H | |
| (boundaryTapes vertex 0 oldTable output countSuffix result) state countSuffix rfl | |
| /-- Preparing a row modifies finite control only, preserving every tape. -/ | |
| theorem prepareRowStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) : | |
| TM2.step (program positive H) ⟨some (.inr .prepareRow), state, base⟩ = | |
| some ⟨some (.inl .initialize), prepareState positive H state, base⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .prepareRow)) state base) = _ | |
| rw [program_outer] | |
| rfl | |
| /-- A nonfinal row advances the finite position without changing tapes. -/ | |
| theorem afterRow_moreStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (more : state.2.val + 1 < rowFactor d) : | |
| TM2.step (program positive H) ⟨some (.inr .afterRow), state, base⟩ = | |
| some ⟨some (.inr .prepareRow), advancePositionState positive state, base⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .afterRow)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, TM2.stepAux, more] | |
| /-- The final row increments the tape vertex and resets the finite position. -/ | |
| theorem afterRow_lastStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (last : ¬ state.2.val + 1 < rowFactor d) : | |
| TM2.step (program positive H) ⟨some (.inr .afterRow), state, base⟩ = | |
| some ⟨some (.inr .vertexGuard), resetPositionState positive state, | |
| Function.update base (.inl .inputVertex) (true :: base (.inl .inputVertex))⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .afterRow)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, TM2.stepAux, last] | |
| theorem afterRow_last_boundaryStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (vertex remaining : Nat) (oldTable output countSuffix result : List Bool) | |
| (state : State ρ d) (last : ¬ state.2.val + 1 < rowFactor d) : | |
| TM2.step (program positive H) | |
| ⟨some (.inr .afterRow), state, | |
| boundaryTapes vertex remaining oldTable output countSuffix result⟩ = | |
| some ⟨some (.inr .vertexGuard), resetPositionState positive state, | |
| boundaryTapes (vertex + 1) remaining oldTable output countSuffix result⟩ := by | |
| have input : boundaryTapes vertex remaining oldTable output countSuffix result | |
| (.inl .inputVertex) = encodeWord vertex := rfl | |
| have h := afterRow_lastStep positive H | |
| (boundaryTapes vertex remaining oldTable output countSuffix result) state last | |
| simp only [input] at h | |
| exact h.trans (congrArg | |
| (fun tapes : ∀ tape, List (Alphabet tape) => | |
| (some ⟨some (.inr .vertexGuard), resetPositionState positive state, tapes⟩ : | |
| Option (TM2.Cfg Alphabet (Label d) (State ρ d)))) | |
| (boundaryTapes_increment_vertex vertex remaining oldTable output countSuffix result)) | |
| /-- One reversal step moves an actual symbol and preserves the finite position. -/ | |
| theorem reverseOutput_consStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (symbol : Bool) (word : List Bool) (source : base (.inl .output) = symbol :: word) : | |
| TM2.step (program positive H) ⟨some (.inr .reverseOutput), state, base⟩ = | |
| some ⟨some (.inr .reverseOutput), ((state.1.1, some symbol), state.2), | |
| Function.update (Function.update base (.inl .output) word) | |
| (.inr .result) (symbol :: base (.inr .result))⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .reverseOutput)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, MachineControl.statement, Reduction.MachineTransfer.loopAt, | |
| Reduction.MachineTransfer.exitAt, TM2.stepAux, guardStates, source] | |
| theorem reverseOutput_nilStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) | |
| (source : base (.inl .output) = []) : | |
| TM2.step (program positive H) ⟨some (.inr .reverseOutput), state, base⟩ = | |
| some ⟨some (.inr .done), clearRegister state, base⟩ := by | |
| have same : Function.update base (.inl .output) [] = base := by | |
| simpa only [source] using Function.update_eq_self (.inl .output) base | |
| change some (TM2.stepAux (program positive H (.inr .reverseOutput)) state base) = _ | |
| rw [program_outer] | |
| simp [outerStatement, MachineControl.statement, Reduction.MachineTransfer.loopAt, | |
| Reduction.MachineTransfer.exitAt, TM2.stepAux, guardStates, clearRegister, source, same] | |
| theorem doneStep (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (base : ∀ tape, List (Alphabet tape)) (state : State ρ d) : | |
| TM2.step (program positive H) ⟨some (.inr .done), state, base⟩ = | |
| some ⟨none, state, base⟩ := by | |
| change some (TM2.stepAux (program positive H (.inr .done)) state base) = _ | |
| rw [program_outer] | |
| rfl | |
| end UniqueGamesTheorem.Foundations.Complexity.MachineExpanderTable | |
| end OAI | |
Xet Storage Details
- Size:
- 51.5 kB
- Xet hash:
- c89f625e49c63f762d2177fe5a364c22c5c613b94b6aca6dc0d42b375245cd5b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.