import Mathlib import OAI.Computability.DirectedFeedback.Machines.MachineExpanderTableLoop namespace OAI section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section namespace DFVSGames.Foundations.Complexity.MachineExpanderFamily 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 DFVSGames.Foundations.Complexity.MachineExpanderFamily end section namespace DFVSGames.Foundations.Complexity.MachineExpanderFamily open Turing open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords open MachineExpanderFamilyBounds noncomputable def levelLoopCost {d : Nat} (H : Table (cloudSize d) d) : Nat → Nat → Nat | _, 0 => 1 | start, remaining + 1 => 1 + resizeCost (family H start) H + levelLoopCost H (start + 1) remaining theorem levelLoopCost_prefix {d : Nat} (H : Table (cloudSize d) d) (start remaining : Nat) : levelLoopCost H start remaining + resizeSum H start = resizeSum H (start + remaining) + remaining + 1 := by induction remaining generalizing start with | zero => simp [levelLoopCost, Nat.add_comm] | succ remaining ih => have h := ih (start + 1) rw [resizeSum_succ] at h have index : start + 1 + remaining = start + (remaining + 1) := by omega rw [index] at h simp only [levelLoopCost] omega theorem levelLoopCost_zero_start {d : Nat} (H : Table (cloudSize d) d) (remaining : Nat) : levelLoopCost H 0 remaining = resizeSum H remaining + remaining + 1 := by simpa only [resizeSum_zero, Nat.add_zero, Nat.zero_add] using levelLoopCost_prefix H 0 remaining def levelLoopTapes {d : Nat} (H : Table (cloudSize d) d) (completed remaining : Nat) (suffix : List Bool) : ∀ tape, List (Alphabet tape) := boundaryTapes remaining (vertexCount (degree d) completed) (encodeWords (rotationWords (family H completed))) suffix structure LevelLoopRun {d : Nat} {ρ : Type} [Fintype ρ] (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) (completed 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 .levelGuard), state, levelLoopTapes H completed remaining suffix⟩ (some ⟨some (.inr .done), finalState, familyTapes H (completed + remaining) suffix⟩) (levelLoopCost H completed remaining) private def familySingleStep_inline_MachineExpanderFamilyLoop {S : Type*} (f : S → Option S) (a b : S) (h : f a = some b) : StateTransition.EvalsToInTime f a (some b) 1 where steps := 1 evals_in_steps := by change f a = some b; exact h steps_le_m := Nat.le_refl _ noncomputable def levelLoopInTime {d : Nat} {ρ : Type} [Fintype ρ] (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) (completed remaining : Nat) (state : State ρ d) (suffix : List Bool) : LevelLoopRun positive H growth completed remaining state suffix := by induction remaining generalizing completed state with | zero => refine ⟨clearRegister state, caller_clearRegister state, ?_⟩ simpa only [levelLoopCost, levelLoopTapes, familyTapes, Nat.add_zero] using familySingleStep_inline_MachineExpanderFamilyLoop _ _ _ (levelGuard_boundary_zeroStep positive H growth (vertexCount (degree d) completed) (encodeWords (rotationWords (family H completed))) suffix state) | succ remaining ih => let cycle := resizeInTime positive H growth (family H completed) remaining (clearRegister state) suffix let rest := ih (completed + 1) cycle.finalState let guard := familySingleStep_inline_MachineExpanderFamilyLoop _ _ _ (levelGuard_boundary_succStep positive H growth remaining (vertexCount (degree d) completed) (encodeWords (rotationWords (family H completed))) suffix state) have cycleRun : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr (.affine .copyCount .seed)), clearRegister state, levelLoopTapes H completed remaining suffix⟩ (some ⟨some (.inr .levelGuard), cycle.finalState, levelLoopTapes H (completed + 1) remaining suffix⟩) (resizeCost (family H completed) H) := cycle.execution let first := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) _ _ _ _ _ guard cycleRun let all := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) _ _ _ _ _ first rest.execution have index : completed + 1 + remaining = completed + (remaining + 1) := by omega refine ⟨rest.finalState, ?_, ?_⟩ · exact rest.caller_preserved.trans (cycle.caller_preserved.trans (caller_clearRegister state)) · rw [index] at all refine { toEvalsTo := all.toEvalsTo, steps_le_m := ?_ } have bound := all.steps_le_m simp only [levelLoopCost] omega end DFVSGames.Foundations.Complexity.MachineExpanderFamily end section namespace DFVSGames.Foundations.Complexity.MachineExpanderFamily open Turing open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords open MachineExpanderFamilyBounds private def singleFamilyStep_inline_MachineExpanderFamily {S : Type*} (f : S → Option S) (a b : S) (h : f a = some b) : StateTransition.EvalsToInTime f a (some b) 1 where steps := 1 evals_in_steps := by change f a = some b; exact h steps_le_m := Nat.le_refl _ noncomputable def familyInTime {d : Nat} {ρ : Type} [Fintype ρ] (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) (level : Nat) (state : State ρ d) (suffix : List Bool) : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr .initialize), state, initialTapes level suffix⟩ (some ⟨none, initialState positive H (caller state), familyTapes H level suffix⟩) (familyBudget H level) := by let loop := levelLoopInTime positive H growth 0 level (initialState positive H (caller state)) suffix have initialRun : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr .initialize), state, initialTapes level suffix⟩ (some ⟨some (.inr .levelGuard), initialState positive H (caller state), levelLoopTapes H 0 level suffix⟩) 1 := singleFamilyStep_inline_MachineExpanderFamily _ _ _ (initialize_boundaryStep positive H growth level suffix state) have finalCaller : caller loop.finalState = caller state := loop.caller_preserved have done : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr .done), loop.finalState, familyTapes H level suffix⟩ (some ⟨none, initialState positive H (caller state), familyTapes H level suffix⟩) 1 := by simpa only [normalizeState, finalCaller] using singleFamilyStep_inline_MachineExpanderFamily _ _ _ (doneStep positive H growth (familyTapes H level suffix) loop.finalState) have loopRun : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr .levelGuard), initialState positive H (caller state), levelLoopTapes H 0 level suffix⟩ (some ⟨some (.inr .done), loop.finalState, familyTapes H level suffix⟩) (levelLoopCost H 0 level) := by simpa only [Nat.zero_add] using loop.execution let first := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) _ _ _ _ _ initialRun loopRun let all := StateTransition.EvalsToInTime.trans (TM2.step (program positive H growth)) _ _ _ _ _ first done refine { toEvalsTo := all.toEvalsTo, steps_le_m := ?_ } have bound := all.steps_le_m have costEquality := levelLoopCost_zero_start H level unfold familyBudget omega noncomputable def familyInOutputSizeTime {d : Nat} {ρ : Type} [Fintype ρ] (positive : 0 < d) (H : Table (cloudSize d) d) (growth : 1 < cloudSize d) (level : Nat) (state : State ρ d) (suffix : List Bool) : StateTransition.EvalsToInTime (TM2.step (program positive H growth)) ⟨some (.inr .initialize), state, initialTapes level suffix⟩ (some ⟨none, initialState positive H (caller state), familyTapes H level suffix⟩) ((resizeCoefficient d + 4) * (vertexCount (degree d) level + 1)^5) where toEvalsTo := (familyInTime positive H growth level state suffix).toEvalsTo steps_le_m := (familyInTime positive H growth level state suffix).steps_le_m.trans (familyBudget_le H growth level) theorem baseDegree_cloud_growth : cloudSize PCP.Expanders.baseDegree = PCP.ExpanderFamily.growth := by unfold cloudSize degree PCP.ExpanderFamily.growth ring theorem baseDegree_cloud_gt_one : 1 < cloudSize PCP.Expanders.baseDegree := by rw [baseDegree_cloud_growth] exact PCP.ExpanderFamily.growth_gt_one theorem baseDegree_positive : 0 < PCP.Expanders.baseDegree := by have h := baseDegree_cloud_gt_one unfold cloudSize degree at h by_contra hn have hz : PCP.Expanders.baseDegree = 0 := by omega rw [hz] at h norm_num at h noncomputable def paddedFamilyInTime {ρ : Type} [Fintype ρ] (H : Table (cloudSize PCP.Expanders.baseDegree) PCP.Expanders.baseDegree) (requested : Nat) (state : State ρ PCP.Expanders.baseDegree) (suffix : List Bool) : StateTransition.EvalsToInTime (TM2.step (program baseDegree_positive H baseDegree_cloud_gt_one)) ⟨some (.inr .initialize), state, initialTapes (PCP.PreprocessingLevels.boundedLevel requested) suffix⟩ (some ⟨none, initialState baseDegree_positive H (caller state), familyTapes H (PCP.PreprocessingLevels.boundedLevel requested) suffix⟩) (inputCoefficient * (requested + 1)^5) where toEvalsTo := (familyInTime baseDegree_positive H baseDegree_cloud_gt_one (PCP.PreprocessingLevels.boundedLevel requested) state suffix).toEvalsTo steps_le_m := (familyInTime baseDegree_positive H baseDegree_cloud_gt_one (PCP.PreprocessingLevels.boundedLevel requested) state suffix).steps_le_m.trans (familyBudget_at_boundedLevel_le H requested) end DFVSGames.Foundations.Complexity.MachineExpanderFamily end section namespace DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamily open Turing open PCP.ExpanderTables PCP.ExpanderRowControl abbrev fixedDegree := PCP.Expanders.baseDegree abbrev SmallTable := Table (cloudSize fixedDegree) fixedDegree abbrev Tape := MachineExpanderFamily.Tape ⊕ MachineCeilingPower.Tape abbrev Alphabet (_ : Tape) := Bool abbrev Label := MachineExpanderFamily.Label fixedDegree ⊕ MachineCeilingPower.Label abbrev State (ρ : Type) := MachineExpanderFamily.State ρ fixedDegree × (Bool × Option Bool) def familyTape (tape : MachineExpanderFamily.Tape) : Tape := .inl tape def familyView : Tape → Option MachineExpanderFamily.Tape | .inl tape => some tape | .inr _ => none @[simp] theorem familyView_left (tape : MachineExpanderFamily.Tape) : familyView (familyTape tape) = some tape := rfl theorem familyView_right (j : Tape) (tape : MachineExpanderFamily.Tape) (h : familyView j = some tape) : familyTape tape = j := by cases j with | inl j => have hj : j = tape := Option.some.inj h subst tape rfl | inr j => simp [familyView] at h def ceilingTape : MachineCeilingPower.Tape → Tape | .level => .inl (.inr .remainingLevel) | tape => .inr tape def ceilingView : Tape → Option MachineCeilingPower.Tape | .inl (.inr .remainingLevel) => some .level | .inl _ => none | .inr .level => none | .inr tape => some tape @[simp] theorem ceilingView_left (tape : MachineCeilingPower.Tape) : ceilingView (ceilingTape tape) = some tape := by cases tape <;> rfl theorem ceilingView_right (j : Tape) (tape : MachineCeilingPower.Tape) (h : ceilingView j = some tape) : ceilingTape tape = j := by cases j with | inl j => cases j with | inl j => simp [ceilingView] at h | inr j => cases j <;> simp_all [ceilingView, ceilingTape] ; cases h ; rfl | inr j => cases j <;> simp_all [ceilingView, ceilingTape] <;> cases h <;> rfl def familyLabel (label : MachineExpanderFamily.Label fixedDegree) : Label := .inl label def ceilingLabel (label : MachineCeilingPower.Label) : Label := .inr label def main : Label := .inr .init def familyEntry : Label := .inl (.inr .initialize) def ceilingStates (ρ : Type) : MachineCeilingPower.State (MachineExpanderFamily.State ρ fixedDegree) ≃ State ρ := Equiv.prodAssoc _ _ _ @[simp] theorem ceilingStates_apply (ρ : Type) (state : MachineCeilingPower.State (MachineExpanderFamily.State ρ fixedDegree)) : ceilingStates ρ state = (state.1.1, (state.1.2, state.2)) := rfl variable {ρ : Type} [Fintype ρ] def familySource (H : SmallTable) : MachineExpanderFamily.Label fixedDegree → TM2.Stmt MachineExpanderFamily.BoolAlphabet (MachineExpanderFamily.Label fixedDegree) (State ρ) := MachineStateFrame.frameProgram (τ := Bool × Option Bool) (MachineExpanderFamily.boolView MachineExpanderFamily.baseDegree_positive H MachineExpanderFamily.baseDegree_cloud_gt_one) def ceilingSource : MachineCeilingPower.Label → TM2.Stmt MachineCeilingPower.Alphabet MachineCeilingPower.Label (State ρ) := MachineStateEquiv.program (ceilingStates ρ) (MachineCeilingPower.program PCP.ExpanderFamily.growth) def program (H : SmallTable) : Label → TM2.Stmt Alphabet Label (State ρ) | .inl label => MachineCloudPadding.Placement.statement familyTape familyLabel none (familySource H label) | .inr label => MachineCloudPadding.Placement.statement ceilingTape ceilingLabel (some familyEntry) (ceilingSource (ρ := ρ) label) @[simp] theorem program_family (H : SmallTable) (label : MachineExpanderFamily.Label fixedDegree) : program (ρ := ρ) H (familyLabel label) = MachineCloudPadding.Placement.statement familyTape familyLabel none (familySource H label) := rfl @[simp] theorem program_ceiling (H : SmallTable) (label : MachineCeilingPower.Label) : program (ρ := ρ) H (ceilingLabel label) = MachineCloudPadding.Placement.statement ceilingTape ceilingLabel (some familyEntry) (ceilingSource (ρ := ρ) label) := rfl def initialState (state : MachineExpanderFamily.State ρ fixedDegree) (register : Option Bool) : State ρ := (state, (false, register)) def finalState (H : SmallTable) (state : MachineExpanderFamily.State ρ fixedDegree) : State ρ := (MachineExpanderFamily.initialState MachineExpanderFamily.baseDegree_positive H (MachineExpanderFamily.caller state), (false, none)) def initialTapes (requested : Nat) : Tape → List Bool | .inr .input => encodeWord requested | _ => [] def retainedCeilingTapes (requested : Nat) : MachineCeilingPower.Tape → List Bool := MachineCeilingPower.memory (encodeWord requested) [] (encodeWord (PCP.PreprocessingLevels.paddedSize requested)) [] [] [] [] [] def handoffTapes (requested : Nat) : Tape → List Bool | .inl tape => MachineExpanderFamily.toBoolTapes (MachineExpanderFamily.initialTapes (PCP.PreprocessingLevels.boundedLevel requested) []) tape | .inr tape => retainedCeilingTapes requested tape def finalTapes (H : SmallTable) (requested : Nat) : Tape → List Bool | .inl tape => MachineExpanderFamily.toBoolTapes (MachineExpanderFamily.familyTapes H (PCP.PreprocessingLevels.boundedLevel requested) []) tape | .inr tape => retainedCeilingTapes requested tape @[simp] theorem initialTapes_input (requested : Nat) : initialTapes requested (.inr .input) = encodeWord requested := rfl @[simp] theorem finalTapes_input (H : SmallTable) (requested : Nat) : finalTapes H requested (.inr .input) = encodeWord requested := rfl @[simp] theorem finalTapes_power (H : SmallTable) (requested : Nat) : finalTapes H requested (.inr .power) = encodeWord (PCP.PreprocessingLevels.paddedSize requested) := rfl end DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamily end section namespace DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamily open Turing open MachineCloudPadding open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords def ceilingInput (requested : Nat) : MachineCeilingPower.Tape → List Bool := MachineCeilingPower.memory (encodeWord requested) [] [] [] [] [] [] [] def ceilingOutput (requested : Nat) : MachineCeilingPower.Tape → List Bool := MachineCeilingPower.memory (encodeWord requested) [] (encodeWord (PCP.PreprocessingLevels.paddedSize requested)) [] (encodeWord (PCP.PreprocessingLevels.boundedLevel requested)) [] [] [] def retainedFrame (requested : Nat) : Tape → List Bool | .inl _ => [] | .inr tape => retainedCeilingTapes requested tape theorem ceiling_initial_tapes (requested : Nat) : Placement.tapes ceilingView (ceilingInput requested) (fun _ => []) = initialTapes requested := by funext tape rcases tape with tape | tape · rcases tape with tape | tape · rfl · cases tape <;> rfl · cases tape <;> rfl theorem ceiling_handoff_tapes (requested : Nat) : Placement.tapes ceilingView (ceilingOutput requested) (fun _ => []) = handoffTapes requested := by funext tape rcases tape with tape | tape · rcases tape with tape | tape · rcases tape with tape | tape · cases tape <;> rfl · cases tape <;> rfl · cases tape <;> simp [Placement.tapes, ceilingView, ceilingOutput, handoffTapes, MachineExpanderFamily.toBoolTapes, MachineExpanderFamily.toBoolWord, MachineExpanderFamily.initialTapes, MachineEmbedding.tapes, MachineCeilingPower.memory] · cases tape <;> rfl theorem family_initial_tapes (requested : Nat) : Placement.tapes familyView (MachineExpanderFamily.toBoolTapes (MachineExpanderFamily.initialTapes (PCP.PreprocessingLevels.boundedLevel requested) [])) (retainedFrame requested) = handoffTapes requested := by funext tape cases tape <;> rfl theorem family_final_tapes (H : SmallTable) (requested : Nat) : Placement.tapes familyView (MachineExpanderFamily.toBoolTapes (MachineExpanderFamily.familyTapes H (PCP.PreprocessingLevels.boundedLevel requested) [])) (retainedFrame requested) = finalTapes H requested := by funext tape cases tape <;> rfl theorem ceiling_initial_configuration {ρ : Type} (requested : Nat) (state : MachineExpanderFamily.State ρ fixedDegree) (register : Option Bool) : Placement.configuration ceilingView ceilingLabel (some familyEntry) (fun _ => []) (MachineStateEquiv.configuration (ceilingStates ρ) ⟨some .init, ((state, false), register), ceilingInput requested⟩) = ⟨some main, initialState state register, initialTapes requested⟩ := by simp only [Placement.configuration, Placement.label, MachineStateEquiv.configuration, ceilingStates_apply, ceiling_initial_tapes, ceilingLabel, main, initialState] theorem ceiling_handoff_configuration {ρ : Type} (requested : Nat) (state : MachineExpanderFamily.State ρ fixedDegree) : Placement.configuration ceilingView ceilingLabel (some familyEntry) (fun _ => []) (MachineStateEquiv.configuration (ceilingStates ρ) ⟨none, ((state, false), none), ceilingOutput requested⟩) = ⟨some familyEntry, (state, (false, none)), handoffTapes requested⟩ := by simp only [Placement.configuration, Placement.label, MachineStateEquiv.configuration, ceilingStates_apply, ceiling_handoff_tapes] theorem family_initial_configuration {ρ : Type} (requested : Nat) (state : MachineExpanderFamily.State ρ fixedDegree) (metadata : Bool × Option Bool) : Placement.configuration familyView familyLabel none (retainedFrame requested) (MachineStateFrame.frameConfiguration metadata (MachineAlphabetTransport.configuration MachineExpanderFamily.alphabet_eq ⟨some (.inr .initialize), state, MachineExpanderFamily.initialTapes (PCP.PreprocessingLevels.boundedLevel requested) []⟩)) = ⟨some familyEntry, (state, metadata), handoffTapes requested⟩ := by rw [MachineExpanderFamily.configuration_toBool] simp only [MachineStateFrame.frameConfiguration, Placement.configuration, Placement.label, family_initial_tapes, familyEntry, familyLabel] theorem family_final_configuration {ρ : Type} (H : SmallTable) (requested : Nat) (state : MachineExpanderFamily.State ρ fixedDegree) : Placement.configuration familyView familyLabel none (retainedFrame requested) (MachineStateFrame.frameConfiguration (false, none) (MachineAlphabetTransport.configuration MachineExpanderFamily.alphabet_eq ⟨none, MachineExpanderFamily.initialState MachineExpanderFamily.baseDegree_positive H (MachineExpanderFamily.caller state), MachineExpanderFamily.familyTapes H (PCP.PreprocessingLevels.boundedLevel requested) []⟩)) = ⟨none, finalState H state, finalTapes H requested⟩ := by rw [MachineExpanderFamily.configuration_toBool] simp only [MachineStateFrame.frameConfiguration, Placement.configuration, Placement.label, family_final_tapes, finalState] @[simp] theorem handoffTapes_level (requested : Nat) : handoffTapes requested (ceilingTape .level) = encodeWord (PCP.PreprocessingLevels.boundedLevel requested) := by simp [handoffTapes, ceilingTape, MachineExpanderFamily.toBoolTapes, MachineExpanderFamily.toBoolWord, MachineExpanderFamily.initialTapes, MachineEmbedding.tapes] @[simp] theorem handoffTapes_level_shadow (requested : Nat) : handoffTapes requested (.inr .level) = [] := rfl @[simp] theorem finalTapes_level_shadow (H : SmallTable) (requested : Nat) : finalTapes H requested (.inr .level) = [] := rfl @[simp] theorem finalTapes_remainingLevel (H : SmallTable) (requested : Nat) : finalTapes H requested (ceilingTape .level) = encodeWord 0 := by simp [finalTapes, ceilingTape, MachineExpanderFamily.toBoolTapes, MachineExpanderFamily.toBoolWord, MachineExpanderFamily.familyTapes, MachineExpanderFamily.boundaryTapes, MachineExpanderFamily.extraFrame, MachineEmbedding.tapes] theorem finalTapes_currentSize (H : SmallTable) (requested : Nat) : finalTapes H requested (familyTape (.inr .currentSize)) = encodeWord (PCP.PreprocessingLevels.paddedSize requested) := by change encodeWord (vertexCount (degree fixedDegree) (PCP.PreprocessingLevels.boundedLevel requested)) = _ exact congrArg encodeWord (PCP.PreprocessingLevels.table_vertexCount_eq_paddedSize requested) theorem finalTapes_table (H : SmallTable) (requested : Nat) : finalTapes H requested (familyTape MachineExpanderFamily.tableTape) = encodeWords (rotationWords (family H (PCP.PreprocessingLevels.boundedLevel requested))) := rfl end DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamily end section namespace DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamilyBounds open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords def timeCoefficient : Nat := MachineExpanderFamilyBounds.inputCoefficient + PCP.ExpanderFamily.growth + 29 noncomputable def timePolynomial : Polynomial Nat := Polynomial.C timeCoefficient * Polynomial.X^5 theorem timePolynomial_encoding (k : Nat) : timePolynomial.eval (encodeWord k).length = timeCoefficient * (k + 1)^5 := by simp only [timePolynomial, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X, encodeWord_length] theorem ceilingCost_le (g k : Nat) : (MachineCeilingPower.timePolynomial g).eval (encodeWord k).length ≤ (g + 29) * (k + 1)^5 := by rw [MachineCeilingPower.timePolynomial_encoding] have squareBound : (k + 1)^2 ≤ (k + 1)^5 := Nat.pow_le_pow_right (Nat.succ_pos k) (by decide) have linearBound : k + 1 ≤ (k + 1)^5 := by simpa only [pow_one] using Nat.pow_le_pow_right (Nat.succ_pos k) (show 1 ≤ 5 by decide) have constantBound : 1 ≤ (k + 1)^5 := by omega have squareCost := Nat.mul_le_mul_left (g + 8) squareBound have linearCost := Nat.mul_le_mul_left 18 linearBound have constantCost := Nat.mul_le_mul_left 3 constantBound unfold MachineCeilingPower.timeBound nlinarith only [squareCost, linearCost, constantCost] theorem combinedCost_le (k : Nat) : (MachineCeilingPower.timePolynomial PCP.ExpanderFamily.growth).eval (encodeWord k).length + MachineExpanderFamilyBounds.inputCoefficient * (k + 1)^5 ≤ timePolynomial.eval (encodeWord k).length := by rw [timePolynomial_encoding] have h := ceilingCost_le PCP.ExpanderFamily.growth k unfold timeCoefficient nlinarith only [h] theorem familyCost_le (H : Table (cloudSize PCP.Expanders.baseDegree) PCP.Expanders.baseDegree) (k : Nat) : (MachineCeilingPower.timePolynomial PCP.ExpanderFamily.growth).eval (encodeWord k).length + MachineExpanderFamilyBounds.familyBudget H (PCP.PreprocessingLevels.boundedLevel k) ≤ timePolynomial.eval (encodeWord k).length := by exact (Nat.add_le_add_left (MachineExpanderFamilyBounds.familyBudget_at_boundedLevel_le H k) _).trans (combinedCost_le k) def outputWord (H : Table (cloudSize PCP.Expanders.baseDegree) PCP.Expanders.baseDegree) (k : Nat) : List Bool := encodeWords (rotationWords (family H (PCP.PreprocessingLevels.boundedLevel k))) def outputCoefficient : Nat := (PCP.ExpanderFamily.growth * degree PCP.Expanders.baseDegree + 1)^2 theorem outputWord_length_le (H : Table (cloudSize PCP.Expanders.baseDegree) PCP.Expanders.baseDegree) (k : Nat) : (outputWord H k).length ≤ outputCoefficient * (k + 1)^2 := by let q := degree PCP.Expanders.baseDegree let N := vertexCount q (PCP.PreprocessingLevels.boundedLevel k) have sizeBound : N ≤ PCP.ExpanderFamily.growth * (k + 1) := by change vertexCount (PCP.Expanders.baseDegree * PCP.Expanders.baseDegree) (PCP.PreprocessingLevels.boundedLevel k) ≤ _ rw [PCP.PreprocessingLevels.table_vertexCount_eq_paddedSize] exact MachineExpanderFamilyBounds.paddedSize_le_succ_input k have rowBound := Nat.mul_le_mul_right q sizeBound have rowSuccBound : N * q + 1 ≤ (PCP.ExpanderFamily.growth * q + 1) * (k + 1) := by nlinarith only [rowBound, Nat.zero_le k] have lengthBound : (outputWord H k).length ≤ (N * q) * (N * q + 1) := encode_rotationWords_length_le (family H (PCP.PreprocessingLevels.boundedLevel k)) calc _ ≤ (N * q + 1)^2 := by nlinarith only [lengthBound, Nat.zero_le (N * q)] _ ≤ ((PCP.ExpanderFamily.growth * q + 1) * (k + 1))^2 := Nat.pow_le_pow_left rowSuccBound 2 _ = _ := by unfold outputCoefficient; dsimp [q]; ring end DFVSGames.Foundations.Complexity.MachinePaddedExpanderFamilyBounds end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end OAI