openAI-math-dataset / lean /OAI /Computability /BinPacking /Computation /MachinePaddedExpanderFamily.lean
roseking's picture
Add lean source and binary files (part 59)
8df23f4 verified
Raw History Blame Contribute Delete
50.2 kB
import OAI.Computability.BinPacking.Computation.MachineExpanderFamilyBoundary
import OAI.Computability.BinPacking.Computation.MachineExpanderTable
namespace OAI
namespace BinPackingGames.Foundations.Complexity.MachineExpanderFamily
open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords
def cycleWords (remaining : Nat) (word current vertex count result suffix : List Bool) :
Tape → List Bool
| .inl (.inl .table) => word
| .inl (.inl .inputVertex) => vertex
| .inl (.inr .vertexCount) => count
| .inl (.inr .result) => result
| .inr .remainingLevel => encodeWord remaining ++ suffix
| .inr .currentSize => current
| _ => []
def cycleTapes (remaining : Nat) (word current vertex count result suffix : List Bool) :
(tape : Tape) → List (Alphabet tape) :=
fromBoolTapes (cycleWords remaining word current vertex count result suffix)
@[simp] theorem toBool_cycleTapes (remaining : Nat)
(word current vertex count result suffix : List Bool) :
toBoolTapes (cycleTapes remaining word current vertex count result suffix) =
cycleWords remaining word current vertex count result suffix := toBool_fromBool _
theorem boundaryTapes_eq_cycleTapes (remaining current : Nat) (word suffix : List Bool) :
boundaryTapes remaining current word suffix =
cycleTapes remaining word (encodeWord current) [] [] [] suffix := by
funext tape
rcases tape with tape | tape
· rcases tape with row | extra
· cases row <;> rfl
· cases extra <;> rfl
· cases tape <;> rfl
def copyFrame (remaining current : Nat) (word suffix : List Bool) :
(tape : Tape) → List (Alphabet tape) :=
MachineEmbedding.tapes (MachineExpanderTable.initialTapes current word [])
(extraFrame remaining current suffix)
def returnFrame (remaining current : Nat) (oldWord newWord suffix : List Bool) :
(tape : Tape) → List (Alphabet tape) :=
MachineEmbedding.tapes (MachineExpanderTable.finalTapes current oldWord newWord [])
(extraFrame remaining current suffix)
def installedFrame (remaining current : Nat) (newWord suffix : List Bool) :
(tape : Tape) → List (Alphabet tape) :=
cycleTapes remaining newWord [] (encodeWord current) (encodeWord 0) [] suffix
def multipliedFrame (d remaining current : Nat) (newWord suffix : List Bool) :
(tape : Tape) → List (Alphabet tape) :=
cycleTapes remaining newWord (encodeWord (cloudSize d * current))
(encodeWord current) (encodeWord 0) [] suffix
theorem copyFrame_eq_cycleTapes (remaining current : Nat) (word suffix : List Bool) :
copyFrame remaining current word suffix =
cycleTapes remaining word (encodeWord current) [] (encodeWord current) [] suffix := by
funext tape
rcases tape with tape | tape
· rcases tape with row | extra
· cases row <;> rfl
· cases extra <;> simp [copyFrame, MachineEmbedding.tapes,
MachineExpanderTable.initialTapes, MachineExpanderTable.extraTapes,
cycleTapes, fromBoolTapes, boolWord, cycleWords]
· cases tape <;> rfl
theorem returnFrame_eq_cycleTapes (remaining current : Nat)
(oldWord newWord suffix : List Bool) :
returnFrame remaining current oldWord newWord suffix =
cycleTapes remaining oldWord (encodeWord current) (encodeWord current)
(encodeWord 0) newWord suffix := by
funext tape
rcases tape with tape | tape
· rcases tape with row | extra
· cases row <;> rfl
· cases extra <;> simp [returnFrame, MachineEmbedding.tapes,
MachineExpanderTable.finalTapes, MachineExpanderTable.boundaryTapes,
MachineExpanderTable.extraTapes, cycleTapes, fromBoolTapes, boolWord, cycleWords]
· cases tape <;> rfl
theorem copyFrame_eq_update (remaining current : Nat) (word suffix : List Bool) :
Function.update (boundaryTapes remaining current word suffix)
vertexCountTape (encodeWord current) = copyFrame remaining current word suffix := by
rw [boundaryTapes_eq_cycleTapes, copyFrame_eq_cycleTapes]
funext tape
rcases tape with tape | tape
· rcases tape with row | extra
· cases row <;> rfl
· cases extra <;> rfl
· cases tape <;> rfl
theorem multipliedFrame_eq_update (d remaining current : Nat) (word suffix : List Bool) :
Function.update (installedFrame remaining current word suffix)
(.inr .currentSize) (encodeWord (cloudSize d * current)) =
multipliedFrame d remaining current word suffix := by
funext tape
rcases tape with tape | tape
· rcases tape with row | extra
· cases row <;> rfl
· cases extra <;> rfl
· cases tape <;> rfl
end BinPackingGames.Foundations.Complexity.MachineExpanderFamily
namespace BinPackingGames.Foundations.Complexity.MachineExpanderFamilyBounds
open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords
noncomputable def resizeCost {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) : Nat :=
(MachineExpanderTable.timePolynomial d).eval (MachineExpanderTable.oldTableWord G).length +
6 * v + (MachineExpanderTable.oldTableWord G).length +
2 * (encodeWords (rotationWords (step G H))).length + 15
def resizeCoefficient (d : Nat) : Nat :=
MachineExpanderTable.timeCoefficient d * (degree d + 1) ^ 4 +
3 * (degree d + 1) ^ 2 + 21
theorem wordLength_add_one_le {v q N : Nat} (G : Table v q) (hv : v ≤ N) :
(encodeWords (rotationWords G)).length + 1 ≤ (q + 1)^2 * (N + 1)^2 := by
have hlength := encode_rotationWords_length_le G
have hrow : v * q + 1 ≤ (q + 1) * (N + 1) := by
have h := Nat.mul_le_mul_right q hv
nlinarith
calc
_ ≤ (v * q + 1)^2 := by nlinarith
_ ≤ ((q + 1) * (N + 1))^2 := Nat.pow_le_pow_left hrow 2
_ = _ := by ring
theorem resizeCost_le {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) (N : Nat) (hv : v ≤ N)
(hnext : v * cloudSize d ≤ N) :
resizeCost G H ≤ resizeCoefficient d * (N + 1)^4 := by
let oldL := (MachineExpanderTable.oldTableWord G).length
let newL := (encodeWords (rotationWords (step G H))).length
have oldBound : oldL + 1 ≤ (degree d + 1)^2 * (N + 1)^2 :=
wordLength_add_one_le G hv
have newBound : newL + 1 ≤ (degree d + 1)^2 * (N + 1)^2 :=
wordLength_add_one_le (step G H) hnext
have timeBound : (MachineExpanderTable.timePolynomial d).eval oldL ≤
MachineExpanderTable.timeCoefficient d * (degree d + 1)^4 * (N + 1)^4 := by
simp only [MachineExpanderTable.timePolynomial, Polynomial.eval_mul,
Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_add,
Polynomial.eval_X, Polynomial.eval_one]
calc
_ ≤ MachineExpanderTable.timeCoefficient d *
((degree d + 1)^2 * (N + 1)^2)^2 :=
Nat.mul_le_mul_left _ (Nat.pow_le_pow_left oldBound 2)
_ = _ := by ring
have pow24 : (N + 1)^2 ≤ (N + 1)^4 :=
Nat.pow_le_pow_right (Nat.succ_pos N) (by decide)
have overheadBound : oldL + 2 * newL ≤
3 * (degree d + 1)^2 * (N + 1)^4 := by
have h := Nat.mul_le_mul_left ((degree d + 1)^2) pow24
calc
_ ≤ 3 * ((degree d + 1)^2 * (N + 1)^2) := by omega
_ ≤ 3 * ((degree d + 1)^2 * (N + 1)^4) := Nat.mul_le_mul_left 3 h
_ = _ := by ring
have npow : N + 1 ≤ (N + 1)^4 := by
simpa only [pow_one] using
Nat.pow_le_pow_right (Nat.succ_pos N) (show 1 ≤ 4 by decide)
have linearBound : 6 * v + 15 ≤ 21 * (N + 1)^4 := by omega
change (MachineExpanderTable.timePolynomial d).eval oldL + 6 * v + oldL +
2 * newL + 15 ≤ _
unfold resizeCoefficient
nlinarith only [timeBound, overheadBound, linearBound]
theorem vertexCount_monotone {q : Nat} (positive : 0 < q) :
Monotone (vertexCount q) := by
intro m n hmn
rw [vertexCount_eq, vertexCount_eq]
exact Nat.pow_le_pow_right (Nat.mul_pos positive positive) hmn
theorem level_le_vertexCount {q : Nat} (growth : 1 < q * q) (level : Nat) :
level ≤ vertexCount q level := by
have positive : 0 < q := by nlinarith
induction level with
| zero => exact Nat.zero_le _
| succ level ih =>
have hpos := vertexCount_positive positive level
have hmul := Nat.mul_le_mul_left (vertexCount q level)
(show 2 ≤ q * q by omega)
change level + 1 ≤ vertexCount q level * (q * q)
nlinarith
noncomputable def resizeSum {d : Nat} (H : Table (cloudSize d) d) (level : Nat) : Nat :=
∑ i ∈ Finset.range level, resizeCost (family H i) H
@[simp] theorem resizeSum_zero {d : Nat} (H : Table (cloudSize d) d) :
resizeSum H 0 = 0 := by simp [resizeSum]
theorem resizeSum_succ {d : Nat} (H : Table (cloudSize d) d) (level : Nat) :
resizeSum H (level + 1) = resizeSum H level + resizeCost (family H level) H := by
simp only [resizeSum, Finset.sum_range_succ]
theorem resizeSum_add {d : Nat} (H : Table (cloudSize d) d) (start count : Nat) :
resizeSum H (start + count) = resizeSum H start +
∑ i ∈ Finset.range count, resizeCost (family H (start + i)) H :=
Finset.sum_range_add (fun i => resizeCost (family H i) H) start count
noncomputable def familyBudget {d : Nat} (H : Table (cloudSize d) d) (level : Nat) : Nat :=
resizeSum H level + level + 3
@[simp] theorem familyBudget_zero {d : Nat} (H : Table (cloudSize d) d) :
familyBudget H 0 = 3 := by simp [familyBudget]
theorem familyBudget_succ {d : Nat} (H : Table (cloudSize d) d) (level : Nat) :
familyBudget H (level + 1) =
familyBudget H level + resizeCost (family H level) H + 1 := by
simp only [familyBudget, resizeSum_succ]
omega
theorem resizeSum_le {d : Nat} (H : Table (cloudSize d) d)
(growth : 1 < cloudSize d) (level : Nat) :
resizeSum H level ≤ resizeCoefficient d * (vertexCount (degree d) level + 1)^5 := by
let N := vertexCount (degree d) level
have positive : 0 < degree d := by
have h : 1 < degree d * degree d := growth
nlinarith
have hmono := vertexCount_monotone positive
have hlevel : level ≤ N := level_le_vertexCount growth level
have eachBound : ∀ i ∈ Finset.range level,
resizeCost (family H i) H ≤ resizeCoefficient d * (N + 1)^4 := by
intro i hi
have hi' : i < level := Finset.mem_range.mp hi
apply resizeCost_le (family H i) H N
· exact hmono (by omega)
· exact hmono (show i + 1 ≤ level by omega)
have sumBound : resizeSum H level ≤ level * (resizeCoefficient d * (N + 1)^4) := by
calc
_ ≤ ∑ _i ∈ Finset.range level, resizeCoefficient d * (N + 1)^4 :=
Finset.sum_le_sum eachBound
_ = _ := by simp
calc
_ ≤ level * (resizeCoefficient d * (N + 1)^4) := sumBound
_ ≤ (N + 1) * (resizeCoefficient d * (N + 1)^4) :=
Nat.mul_le_mul_right _ (hlevel.trans (Nat.le_succ N))
_ = _ := by ring
theorem familyBudget_le {d : Nat} (H : Table (cloudSize d) d)
(growth : 1 < cloudSize d) (level : Nat) :
familyBudget H level ≤
(resizeCoefficient d + 4) * (vertexCount (degree d) level + 1)^5 := by
have hsum := resizeSum_le H growth level
have hlevel := level_le_vertexCount growth level
have hpow : vertexCount (degree d) level + 1 ≤
(vertexCount (degree d) level + 1)^5 := by
simpa only [pow_one] using Nat.pow_le_pow_right
(Nat.succ_pos (vertexCount (degree d) level)) (show 1 ≤ 5 by decide)
have overhead : level + 3 ≤ 4 * (vertexCount (degree d) level + 1)^5 := by omega
unfold familyBudget
nlinarith only [hsum, overhead]
theorem paddedSize_le_succ_input (k : Nat) :
PCP.PreprocessingLevels.paddedSize k ≤ PCP.ExpanderFamily.growth * (k + 1) := by
by_cases hk : k = 0
· subst k
have h := PCP.ExpanderFamily.growth_gt_one
simp only [PCP.PreprocessingLevels.paddedSize_zero, Nat.zero_add, Nat.mul_one]
omega
· exact (PCP.PreprocessingLevels.paddedSize_bounds (Nat.pos_of_ne_zero hk)).2.trans
(Nat.mul_le_mul_left _ (Nat.le_succ k))
def inputCoefficient : Nat :=
(resizeCoefficient PCP.Expanders.baseDegree + 4) * (PCP.ExpanderFamily.growth + 1)^5
theorem familyBudget_at_boundedLevel_le
(H : Table (cloudSize PCP.Expanders.baseDegree) PCP.Expanders.baseDegree) (k : Nat) :
familyBudget H (PCP.PreprocessingLevels.boundedLevel k) ≤ inputCoefficient * (k + 1)^5 := by
have hg : cloudSize PCP.Expanders.baseDegree = PCP.ExpanderFamily.growth := by
unfold cloudSize degree PCP.ExpanderFamily.growth
ring
have growth : 1 < cloudSize PCP.Expanders.baseDegree := by
rw [hg]
exact PCP.ExpanderFamily.growth_gt_one
have bound := familyBudget_le H growth (PCP.PreprocessingLevels.boundedLevel k)
rw [PCP.PreprocessingLevels.table_vertexCount_eq_paddedSize] at bound
have sizeBound : PCP.PreprocessingLevels.paddedSize k + 1 ≤
(PCP.ExpanderFamily.growth + 1) * (k + 1) := by
have h := paddedSize_le_succ_input k
nlinarith
calc
_ ≤ (resizeCoefficient PCP.Expanders.baseDegree + 4) *
(PCP.PreprocessingLevels.paddedSize k + 1)^5 := bound
_ ≤ (resizeCoefficient PCP.Expanders.baseDegree + 4) *
((PCP.ExpanderFamily.growth + 1) * (k + 1))^5 :=
Nat.mul_le_mul_left _ (Nat.pow_le_pow_left sizeBound 5)
_ = _ := by unfold inputCoefficient; ring
end BinPackingGames.Foundations.Complexity.MachineExpanderFamilyBounds
namespace BinPackingGames.Foundations.Complexity.MachineExpanderFamily
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 BinPackingGames.Foundations.Complexity.MachineExpanderFamily
namespace BinPackingGames.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 BinPackingGames.Foundations.Complexity.MachinePaddedExpanderFamilyBounds
namespace BinPackingGames.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 BinPackingGames.Foundations.Complexity.MachineExpanderFamily
namespace BinPackingGames.Foundations.Complexity.MachinePaddedExpanderFamily
section
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
section
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
open Turing
open MachineCloudPadding
open MachineComposition
variable {ρ : Type} [Fintype ρ]
noncomputable def ceilingInTime (H : SmallTable) (requested : Nat)
(state : MachineExpanderFamily.State ρ fixedDegree) (register : Option Bool) :
StateTransition.EvalsToInTime (TM2.step (program H))
⟨some main, initialState state register, initialTapes requested⟩
(some ⟨some familyEntry, (state, (false, none)), handoffTapes requested⟩)
((MachineCeilingPower.timePolynomial PCP.ExpanderFamily.growth).eval
(encodeWord requested).length) := by
let original := MachineCeilingPower.paddingInTime requested state register
let renamed := MachineStateEquiv.execution (ceilingStates ρ)
(MachineCeilingPower.program PCP.ExpanderFamily.growth) original
let placed := liftExecutionInTime (TM2.step (ceilingSource (ρ := ρ)))
(TM2.step (program H))
(Placement.configuration ceilingView ceilingLabel (some familyEntry) (fun _ => []))
(Placement.step_simulation ceilingTape ceilingView ceilingView_left ceilingView_right
ceilingLabel (some familyEntry) (fun _ => []) (ceilingSource (ρ := ρ))
(program H) (program_ceiling H)) renamed
have initialEq := ceiling_initial_configuration requested state register
have finalEq := ceiling_handoff_configuration requested state
unfold ceilingInput at initialEq
unfold ceilingOutput at finalEq
simpa only [initialEq, finalEq] using placed
noncomputable def materializeInTime (H : SmallTable) (requested : Nat)
(state : MachineExpanderFamily.State ρ fixedDegree) :
StateTransition.EvalsToInTime (TM2.step (program H))
⟨some familyEntry, (state, (false, none)), handoffTapes requested⟩
(some ⟨none, finalState H state, finalTapes H requested⟩)
(MachineExpanderFamilyBounds.inputCoefficient * (requested + 1)^5) := by
let original := MachineExpanderFamily.paddedFamilyInTime H requested state []
let boolean := MachineAlphabetTransport.executionInTime MachineExpanderFamily.alphabet_eq
(MachineExpanderFamily.program MachineExpanderFamily.baseDegree_positive H
MachineExpanderFamily.baseDegree_cloud_gt_one) original
let framed := MachineStateFrame.frameExecution
(MachineExpanderFamily.boolView MachineExpanderFamily.baseDegree_positive H
MachineExpanderFamily.baseDegree_cloud_gt_one) (false, (none : Option Bool)) boolean
let placed := liftExecutionInTime (TM2.step (familySource H)) (TM2.step (program H))
(Placement.configuration familyView familyLabel none (retainedFrame requested))
(Placement.step_simulation familyTape familyView familyView_left familyView_right
familyLabel none (retainedFrame requested) (familySource H) (program H)
(program_family H)) framed
simpa only [family_initial_configuration, family_final_configuration] using placed
noncomputable def paddedInTime (H : SmallTable) (requested : Nat)
(state : MachineExpanderFamily.State ρ fixedDegree) (register : Option Bool) :
StateTransition.EvalsToInTime (TM2.step (program H))
⟨some main, initialState state register, initialTapes requested⟩
(some ⟨none, finalState H state, finalTapes H requested⟩)
(MachinePaddedExpanderFamilyBounds.timePolynomial.eval (encodeWord requested).length) := by
let first := ceilingInTime H requested state register
let second := materializeInTime H requested state
let all := StateTransition.EvalsToInTime.trans (TM2.step (program H))
_ _ _ _ _ first second
exact
{ toEvalsTo := all.toEvalsTo
steps_le_m := all.steps_le_m.trans
(by simpa only [Nat.add_comm] using
MachinePaddedExpanderFamilyBounds.combinedCost_le requested) }
noncomputable def placedInTime {K Λ : Type} [DecidableEq K]
(tape : Tape → K) (view : K → Option Tape)
(left : ∀ t, view (tape t) = some t)
(right : ∀ j t, view j = some t → tape t = j)
(labels : Label → Λ) (exit : Option Λ) (extra : K → List Bool)
(H : SmallTable) (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ))
(code : ∀ l, target (labels l) = Placement.statement tape labels exit (program H l))
(requested : Nat) (state : MachineExpanderFamily.State ρ fixedDegree)
(register : Option Bool) :
StateTransition.EvalsToInTime (TM2.step target)
(Placement.configuration view labels exit extra
⟨some main, initialState state register, initialTapes requested⟩)
(some (Placement.configuration view labels exit extra
⟨none, finalState H state, finalTapes H requested⟩))
(MachinePaddedExpanderFamilyBounds.timePolynomial.eval (encodeWord requested).length) :=
liftExecutionInTime (TM2.step (program H)) (TM2.step target)
(Placement.configuration view labels exit extra)
(Placement.step_simulation tape view left right labels exit extra (program H) target code)
(paddedInTime H requested state register)
end BinPackingGames.Foundations.Complexity.MachinePaddedExpanderFamily
end OAI