cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Machines /MachineExpanderFamilyLoop.lean
cfahlgren1's picture
download
raw
9.55 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.MachineExpanderFamilyCycle
namespace OAI
namespace IndependentSetsGames.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 {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 _ _ _ (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 _ _ _ (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
private def singleFamilyStep {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 _ _ _ (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 _ _ _ (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 IndependentSetsGames.Foundations.Complexity.MachineExpanderFamily
end OAI

Xet Storage Details

Size:
9.55 kB
·
Xet hash:
6669e928dacf058c474cddc67a14023cd14ffc7aec9c6a1d2bcba9f8a8007ef5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.