Buckets:
cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Machines /MachineExpanderFamilyCycle.lean
| import Mathlib | |
| import OAI.Combinatorics.IndependentSets.Machines.MachineExpanderFamilyAffine | |
| import OAI.Combinatorics.IndependentSets.Machines.MachineExpanderFamilyBounds | |
| namespace OAI | |
| namespace IndependentSetsGames.Foundations.Complexity.MachineExpanderFamily | |
| section | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords | |
| open MachineExpanderFamilyBounds | |
| theorem installed_returnFrame (remaining current : Nat) (oldWord newWord suffix : List Bool) : | |
| fromBoolTapes (installedTapes (toBoolTapes (returnFrame remaining current oldWord newWord suffix)) | |
| newWord) = installedFrame remaining current newWord suffix := by | |
| rw [returnFrame_eq_cycleTapes, toBool_cycleTapes] | |
| funext tape | |
| rcases tape with tape | tape | |
| · rcases tape with row | extra | |
| · cases row <;> rfl | |
| · cases extra <;> rfl | |
| · cases tape <;> rfl | |
| theorem cleaned_multipliedFrame (d remaining current : Nat) (newWord suffix : List Bool) : | |
| fromBoolTapes (cleanedCounterTapes | |
| (toBoolTapes (multipliedFrame d remaining current newWord suffix))) = | |
| boundaryTapes remaining (current * cloudSize d) newWord suffix := by | |
| rw [boundaryTapes_eq_cycleTapes] | |
| unfold multipliedFrame | |
| rw [toBool_cycleTapes] | |
| have multiply : cloudSize d * current = current * cloudSize d := Nat.mul_comm _ _ | |
| rw [multiply] | |
| funext tape | |
| rcases tape with tape | tape | |
| · rcases tape with row | extra | |
| · cases row <;> rfl | |
| · cases extra <;> rfl | |
| · cases tape <;> rfl | |
| structure ResizeRun {v d : Nat} {ρ : Type} [Fintype ρ] | |
| (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) | |
| (G : Table v (degree d)) (remaining : Nat) (state : State ρ d) (suffix : List Bool) where | |
| finalState : State ρ d | |
| caller_preserved : caller finalState = caller state | |
| execution : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr (.affine .copyCount .seed)), state, | |
| boundaryTapes remaining v (MachineExpanderTable.oldTableWord G) suffix⟩ | |
| (some ⟨some (.inr .levelGuard), finalState, | |
| boundaryTapes remaining (v * cloudSize d) | |
| (encodeWords (rotationWords (step G H))) suffix⟩) | |
| (resizeCost G H) | |
| noncomputable def resizeInTime {v d : Nat} {ρ : Type} [Fintype ρ] | |
| (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) | |
| (G : Table v (degree d)) (remaining : Nat) (state : State ρ d) (suffix : List Bool) : | |
| ResizeRun positive H growth G remaining state suffix := by | |
| let oldWord := MachineExpanderTable.oldTableWord G | |
| let newWord := encodeWords (rotationWords (step G H)) | |
| have copy := copyCountInTime positive H growth | |
| (boundaryTapes remaining v oldWord suffix) v rfl rfl rfl state | |
| rw [copyFrame_eq_update] at copy | |
| let called := MachineExpanderTable.tableInTime positive G H (clearRegister state).1 [] | |
| let returned : State ρ d := (called.finalState, ()) | |
| have eta : ((clearRegister state).1, ()) = clearRegister state := by | |
| rcases state with ⟨state, extra⟩ | |
| cases extra | |
| rfl | |
| have call : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inl (.inr .initialize)), clearRegister state, | |
| copyFrame remaining v oldWord suffix⟩ | |
| (some ⟨some (.inr .clearOldTable), returned, | |
| returnFrame remaining v oldWord newWord suffix⟩) | |
| ((MachineExpanderTable.timePolynomial d).eval oldWord.length) := by | |
| simpa only [MachineEmbedding.configuration, MachineEmbedding.label, tableReturn, eta, | |
| copyFrame, returnFrame, oldWord, newWord, returned] using | |
| tableExecution positive H growth (extraFrame remaining v suffix) called.execution | |
| have install := installTableInTime positive H growth | |
| (returnFrame remaining v oldWord newWord suffix) newWord | |
| (by rw [returnFrame_eq_cycleTapes, toBool_cycleTapes]; rfl) | |
| (by rw [returnFrame_eq_cycleTapes, toBool_cycleTapes]; rfl) returned | |
| rw [installed_returnFrame] at install | |
| have installRun : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr .clearOldTable), returned, returnFrame remaining v oldWord newWord suffix⟩ | |
| (some ⟨some (.inr (.affine .multiplySize .seed)), clearRegister returned, | |
| installedFrame remaining v newWord suffix⟩) | |
| (oldWord.length + 2 * newWord.length + (v + 1) + 4) := by | |
| simpa only [returnFrame_eq_cycleTapes, toBool_cycleTapes, cycleWords, tableTape, | |
| encodeWord_length] using install | |
| have multiply := multiplySizeInTime positive H growth | |
| (installedFrame remaining v newWord suffix) v rfl rfl rfl (clearRegister returned) | |
| rw [clearRegister_idempotent, multipliedFrame_eq_update] at multiply | |
| have clean := cleanupCountersInTime positive H growth | |
| (multipliedFrame d remaining v newWord suffix) (clearRegister returned) | |
| rw [clearRegister_idempotent, cleaned_multipliedFrame] at clean | |
| have cleanRun : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) | |
| ⟨some (.inr .drainInputVertex), clearRegister returned, | |
| multipliedFrame d remaining v newWord suffix⟩ | |
| (some ⟨some (.inr .levelGuard), clearRegister returned, | |
| boundaryTapes remaining (v * cloudSize d) newWord suffix⟩) (v + 4) := by | |
| simpa only [multipliedFrame, toBool_cycleTapes, cycleWords, inputVertexTape, | |
| vertexCountTape, encodeWord_length, Nat.zero_add, Nat.add_assoc] using clean | |
| let a := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) | |
| _ _ _ _ _ copy call | |
| let b := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) | |
| _ _ _ _ _ a installRun | |
| let c := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) | |
| _ _ _ _ _ b multiply | |
| let all := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) | |
| _ _ _ _ _ c cleanRun | |
| refine ⟨clearRegister returned, ?_, ?_⟩ | |
| · exact (caller_clearRegister returned).trans | |
| (called.caller_preserved.trans (caller_clearRegister state)) | |
| · refine { toEvalsTo := all.toEvalsTo, steps_le_m := ?_ } | |
| have bound := all.steps_le_m | |
| unfold resizeCost | |
| change _ ≤ (MachineExpanderTable.timePolynomial d).eval oldWord.length + | |
| 6 * v + oldWord.length + 2 * newWord.length + 15 | |
| omega | |
| end | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl | |
| 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 | |
| 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] | |
| 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 ρ] | |
| 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 | |
| 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 | |
| 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 | |
| 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 IndependentSetsGames.Foundations.Complexity.MachineExpanderFamily | |
| end OAI | |
Xet Storage Details
- Size:
- 16.6 kB
- Xet hash:
- 47984c3556b40737eb8eec46d32f6639bc0c02ee0c85bb47a8e1c6163e6b8280
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.