openAI-math-dataset / lean /OAI /Computability /DirectedFeedback /Machines /MachineExpanderTableLoop.lean
roseking's picture
Add lean source and binary files (part 61)
ea76aac verified
Raw History Blame Contribute Delete
36.9 kB
import Mathlib
import OAI.Computability.DirectedFeedback.Machines.MachineExpanderRow
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.MachineExpanderTable
open Turing MachineComposition
open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords
open PCP.ExpanderTableEnumeration
def oldTableWord {v d : Nat} (G : Table v (degree d)) : List Bool :=
encodeWords (rotationWords G)
def accumulatedVertices {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) (current : Nat) : List Bool :=
accumulate (priorVertices G H current) []
@[simp] theorem accumulatedVertices_zero {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) : accumulatedVertices G H 0 = [] := by
simp [accumulatedVertices, accumulate]
theorem accumulatedVertices_succ {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) (current : Nat) (valid : current < v) :
accumulatedVertices G H (current + 1) =
accumulate (vertexWords G H ⟨current, valid⟩) (accumulatedVertices G H current) := by
simp only [accumulatedVertices, priorVertices_succ G H current valid, accumulate_append]
theorem accumulatedVertices_full {v d : Nat} (G : Table v (degree d))
(H : Table (cloudSize d) d) : accumulatedVertices G H v =
(encodeWords (rotationWords (step G H))).reverse := by
simp [accumulatedVertices, accumulate_generatedWords]
def vertexBodyBudget {v d : Nat} (G : Table v (degree d)) : Nat :=
rowFactor d * (80 * ((oldTableWord G).length + 1) + 2)
def vertexLoopBudget {v d : Nat} (G : Table v (degree d)) (remaining : Nat) : Nat :=
remaining * (vertexBodyBudget G + 1) + 1
def vertexLoopTapes {v d : Nat} (G : Table v (degree d)) (H : Table (cloudSize d) d)
(current remaining : Nat) (suffix : List Bool) : ∀ tape, List (Alphabet tape) :=
boundaryTapes current remaining (oldTableWord G) (accumulatedVertices G H current) suffix []
structure VertexLoopRun {v d : Nat} {ρ : Type} [Fintype ρ]
(positive : 0 < d) (G : Table v (degree d)) (H : Table (cloudSize d) d)
(current remaining : Nat) (state : State ρ d) (suffix : List Bool) where
finalState : State ρ d
caller_preserved : caller finalState = caller state
position_zero : finalState.2 = zeroPosition positive
execution : StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .vertexGuard), state, vertexLoopTapes G H current remaining suffix⟩
(some ⟨some (.inr .reverseOutput), finalState, vertexLoopTapes G H v 0 suffix⟩)
(vertexLoopBudget G remaining)
private def boundarySingleStep_inline_MachineExpanderTableLoop {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 _
def vertexLoopInTime {v d : Nat} {ρ : Type} [Fintype ρ]
(positive : 0 < d) (G : Table v (degree d)) (H : Table (cloudSize d) d)
(current remaining : Nat) (state : State ρ d) (suffix : List Bool)
(count : current + remaining = v) (position : state.2 = zeroPosition positive) :
VertexLoopRun positive G H current remaining state suffix := by
induction remaining generalizing current state with
| zero =>
have hc : current = v := by omega
subst current
refine ⟨clearRegister state, caller_clearRegister state, ?_, ?_⟩
· simpa only [clearRegister] using position
· simpa only [vertexLoopBudget, Nat.zero_mul, Nat.zero_add, vertexLoopTapes] using
boundarySingleStep_inline_MachineExpanderTableLoop _ _ _ (vertexGuard_boundary_zeroStep positive H v (oldTableWord G)
(accumulatedVertices G H v) suffix [] state)
| succ remaining ih =>
have valid : current < v := by omega
let vertex : Fin v := ⟨current, valid⟩
let body := vertexInTime positive G H vertex (clearRegister state)
(by simpa only [clearRegister] using position) remaining
(accumulatedVertices G H current) suffix []
have nextCount : current + 1 + remaining = v := by omega
let rest := ih (current + 1) body.finalState nextCount body.position_zero
have output_eq : accumulate (vertexWords G H vertex)
(accumulatedVertices G H current) = accumulatedVertices G H (current + 1) :=
(accumulatedVertices_succ G H current valid).symm
let guard := boundarySingleStep_inline_MachineExpanderTableLoop _ _ _
(vertexGuard_boundary_succStep positive H current remaining (oldTableWord G)
(accumulatedVertices G H current) suffix [] state)
have bodyRun : StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .prepareRow), clearRegister state,
boundaryTapes current remaining (oldTableWord G)
(accumulatedVertices G H current) suffix []⟩
(some ⟨some (.inr .vertexGuard), body.finalState,
vertexLoopTapes G H (current + 1) remaining suffix⟩)
(vertexBodyBudget G) := by
simpa only [vertexLoopTapes, vertexBodyBudget, oldTableWord, output_eq] using body.execution
let first := StateTransition.EvalsToInTime.trans (TM2.step (program positive H))
_ _ _ _ _ guard bodyRun
let all := StateTransition.EvalsToInTime.trans (TM2.step (program positive H))
_ _ _ _ _ first rest.execution
refine ⟨rest.finalState, ?_, rest.position_zero, ?_⟩
· exact rest.caller_preserved.trans
(body.caller_preserved.trans (caller_clearRegister state))
· refine { toEvalsTo := all.toEvalsTo, steps_le_m := ?_ }
have bound := all.steps_le_m
simp only [vertexLoopBudget, Nat.succ_mul] at bound ⊢
omega
end DFVSGames.Foundations.Complexity.MachineExpanderTable
end
section
namespace DFVSGames.Foundations.Complexity.MachineExpanderTable
open Turing
open MachineComposition
open PCP.ExpanderTables PCP.ExpanderRowControl
variable {ρ : Type} {d : Nat}
@[simp] theorem clearRegister_position (state : State ρ d) :
(clearRegister state).2 = state.2 := rfl
@[simp] theorem clearRegister_register (state : State ρ d) :
(clearRegister state).1.2 = none := rfl
@[simp] theorem clearRegister_idempotent (state : State ρ d) :
clearRegister (clearRegister state) = clearRegister state := rfl
theorem boundaryTapes_reverse_update (vertex remaining : Nat)
(oldTable output countSuffix result nextOutput nextResult : List Bool) :
Function.update
(Function.update (boundaryTapes vertex remaining oldTable output countSuffix result)
(.inl .output) nextOutput)
(.inr .result) nextResult =
boundaryTapes vertex remaining oldTable nextOutput countSuffix nextResult := by
funext tape
rcases tape with row | extra
· cases row <;>
simp [boundaryTapes, rowTapes, MachineEmbedding.tapes, Function.update]
· cases extra <;>
simp [boundaryTapes, extraTapes, MachineEmbedding.tapes, Function.update]
variable [Fintype ρ]
theorem reverseOutputTrace (positive : 0 < d) (H : Table (cloudSize d) d)
(vertex remaining : Nat) (oldTable output countSuffix result : List Bool)
(state : State ρ d) :
(advance (TM2.step (program positive H)))^[output.length + 1]
(some ⟨some (.inr .reverseOutput), state,
boundaryTapes vertex remaining oldTable output countSuffix result⟩) =
some ⟨some (.inr .done), clearRegister state,
boundaryTapes vertex remaining oldTable [] countSuffix (output.reverse ++ result)⟩ := by
induction output generalizing result state with
| nil =>
simpa only [List.length_nil, Nat.zero_add, Function.iterate_one, advance_some,
List.reverse_nil, List.nil_append] using
reverseOutput_nilStep positive H
(boundaryTapes vertex remaining oldTable [] countSuffix result) state rfl
| cons symbol output ih =>
rw [List.length_cons, Function.iterate_succ_apply]
simp only [advance_some]
rw [reverseOutput_consStep positive H
(boundaryTapes vertex remaining oldTable (symbol :: output) countSuffix result)
state symbol output rfl]
change (advance (TM2.step (program positive H)))^[output.length + 1]
(some ⟨some (.inr .reverseOutput), ((state.1.1, some symbol), state.2),
Function.update
(Function.update
(boundaryTapes vertex remaining oldTable (symbol :: output) countSuffix result)
(.inl .output) output)
(.inr .result) (symbol :: result)⟩) = _
rw [boundaryTapes_reverse_update]
simpa only [clearRegister, List.reverse_cons, List.append_assoc,
List.singleton_append] using
ih (symbol :: result) ((state.1.1, some symbol), state.2)
theorem reverseOutputHaltTrace (positive : 0 < d) (H : Table (cloudSize d) d)
(vertex remaining : Nat) (oldTable output countSuffix result : List Bool)
(state : State ρ d) :
(advance (TM2.step (program positive H)))^[output.length + 2]
(some ⟨some (.inr .reverseOutput), state,
boundaryTapes vertex remaining oldTable output countSuffix result⟩) =
some ⟨none, clearRegister state,
boundaryTapes vertex remaining oldTable [] countSuffix (output.reverse ++ result)⟩ := by
rw [show output.length + 2 = (output.length + 1) + 1 by omega,
Function.iterate_succ_apply',
reverseOutputTrace positive H vertex remaining oldTable output countSuffix result state]
exact doneStep positive H
(boundaryTapes vertex remaining oldTable [] countSuffix (output.reverse ++ result))
(clearRegister state)
def reverseOutputInTime (positive : 0 < d) (H : Table (cloudSize d) d)
(vertex remaining : Nat) (oldTable output countSuffix result : List Bool)
(state : State ρ d) :
StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .reverseOutput), state,
boundaryTapes vertex remaining oldTable output countSuffix result⟩
(some ⟨some (.inr .done), clearRegister state,
boundaryTapes vertex remaining oldTable [] countSuffix (output.reverse ++ result)⟩)
(output.length + 1) where
steps := output.length + 1
evals_in_steps := reverseOutputTrace positive H vertex remaining oldTable output countSuffix result state
steps_le_m := Nat.le_refl _
def reverseOutputHaltInTime (positive : 0 < d) (H : Table (cloudSize d) d)
(vertex remaining : Nat) (oldTable output countSuffix result : List Bool)
(state : State ρ d) :
StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .reverseOutput), state,
boundaryTapes vertex remaining oldTable output countSuffix result⟩
(some ⟨none, clearRegister state,
boundaryTapes vertex remaining oldTable [] countSuffix (output.reverse ++ result)⟩)
(output.length + 2) where
steps := output.length + 2
evals_in_steps := reverseOutputHaltTrace positive H vertex remaining oldTable output countSuffix result state
steps_le_m := Nat.le_refl _
end DFVSGames.Foundations.Complexity.MachineExpanderTable
end
section
namespace DFVSGames.Foundations.Complexity.MachineExpanderTable
open Turing MachineComposition
open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords
open PCP.ExpanderTableEnumeration
def completeBudget {v d : Nat} (G : Table v (degree d)) (H : Table (cloudSize d) d) : Nat :=
1 + vertexLoopBudget G v + ((encodeWords (rotationWords (step G H))).length + 2)
def timeCoefficient (d : Nat) : Nat :=
rowFactor d * (rowFactor d + 1) + 82 * rowFactor d + 5
noncomputable def timePolynomial (d : Nat) : Polynomial Nat :=
Polynomial.C (timeCoefficient d) * (Polynomial.X + 1) ^ 2
theorem vertices_le_word_length {v d : Nat} (positive : 0 < d)
(G : Table v (degree d)) : v ≤ (oldTableWord G).length := by
have hq : 1 ≤ degree d := Nat.mul_pos positive positive
have hv : v ≤ v * degree d := by simpa using Nat.mul_le_mul_left v hq
have hr : v * degree d ≤ (oldTableWord G).length := by
simp only [oldTableWord, encodeWords_length, rotationWords_length]
omega
exact hv.trans hr
theorem completeBudget_le {v d : Nat} (positive : 0 < d)
(G : Table v (degree d)) (H : Table (cloudSize d) d) :
completeBudget G H ≤ (timePolynomial d).eval (oldTableWord G).length := by
let L := (oldTableWord G).length
let M := rowFactor d
have vBound : v ≤ L + 1 := (vertices_le_word_length positive G).trans (Nat.le_succ L)
have emitBound : 80 * (L + 1) + 2 ≤ 82 * (L + 1) := by omega
have bodyBound : vertexBodyBudget G + 1 ≤ (82 * M + 1) * (L + 1) := by
have mulBound := Nat.mul_le_mul_left M emitBound
change M * (80 * (L + 1) + 2) + 1 ≤ _
nlinarith
have iterations := Nat.mul_le_mul vBound bodyBound
have loopBound : v * (vertexBodyBudget G + 1) ≤ (82 * M + 1) * (L + 1)^2 := by
calc
_ ≤ (L + 1) * ((82 * M + 1) * (L + 1)) := iterations
_ = _ := by ring
have rowBound : v * M ≤ M * (L + 1) := by
simpa only [Nat.mul_comm v M] using Nat.mul_le_mul_left M vBound
have rowSuccBound : v * M + 1 ≤ (M + 1) * (L + 1) := by nlinarith
have productBound := Nat.mul_le_mul rowBound rowSuccBound
have lengthBound : (encodeWords (rotationWords (step G H))).length ≤
M * (M + 1) * (L + 1)^2 := by
calc
_ ≤ (v * M) * (v * M + 1) := by
simpa only [generatedWords_eq_rotationWords] using encode_generatedWords_length_le G H
_ ≤ (M * (L + 1)) * ((M + 1) * (L + 1)) := productBound
_ = _ := by ring
have oneBound : 1 ≤ (L + 1)^2 := by nlinarith
have combined := Nat.add_le_add loopBound lengthBound
simp only [timePolynomial, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow,
Polynomial.eval_add, Polynomial.eval_X, Polynomial.eval_one]
change completeBudget G H ≤ (M * (M + 1) + 82 * M + 5) * (L + 1)^2
unfold completeBudget vertexLoopBudget
nlinarith
structure TableRun {v d : Nat} {ρ : Type} [Fintype ρ]
(positive : 0 < d) (G : Table v (degree d)) (H : Table (cloudSize d) d)
(state : State ρ d) (suffix : List Bool) where
finalState : State ρ d
caller_preserved : caller finalState = caller state
position_zero : finalState.2 = zeroPosition positive
execution : StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .initialize), state, initialTapes v (oldTableWord G) suffix⟩
(some ⟨none, finalState,
finalTapes v (oldTableWord G) (encodeWords (rotationWords (step G H))) suffix⟩)
((timePolynomial d).eval (oldTableWord G).length)
private def initializeInTime_inline_MachineExpanderTable {v d : Nat} {ρ : Type} [Fintype ρ]
(positive : 0 < d) (G : Table v (degree d)) (H : Table (cloudSize d) d)
(state : State ρ d) (suffix : List Bool) :
StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .initialize), state, initialTapes v (oldTableWord G) suffix⟩
(some ⟨some (.inr .vertexGuard), initialState positive H (caller state),
vertexLoopTapes G H 0 v suffix⟩) 1 where
steps := 1
evals_in_steps := by
change TM2.step (program (ρ := ρ) positive H)
⟨some (.inr .initialize), state, initialTapes v (oldTableWord G) suffix⟩ =
some ⟨some (.inr .vertexGuard), initialState positive H (caller state),
vertexLoopTapes G H 0 v suffix⟩
simpa only [vertexLoopTapes, accumulatedVertices_zero] using
initialize_boundaryStep positive H v (oldTableWord G) suffix state
steps_le_m := Nat.le_refl _
def tableInTime {v d : Nat} {ρ : Type} [Fintype ρ]
(positive : 0 < d) (G : Table v (degree d)) (H : Table (cloudSize d) d)
(state : State ρ d) (suffix : List Bool) : TableRun positive G H state suffix := by
let loop := vertexLoopInTime positive G H 0 v
(initialState positive H (caller state)) suffix (by omega) rfl
let initialRun := initializeInTime_inline_MachineExpanderTable positive G H state suffix
have finish : StateTransition.EvalsToInTime (TM2.step (program positive H))
⟨some (.inr .reverseOutput), loop.finalState, vertexLoopTapes G H v 0 suffix⟩
(some ⟨none, clearRegister loop.finalState,
finalTapes v (oldTableWord G) (encodeWords (rotationWords (step G H))) suffix⟩)
((encodeWords (rotationWords (step G H))).length + 2) := by
simpa only [vertexLoopTapes, finalTapes, accumulatedVertices_full, List.reverse_reverse,
List.append_nil, List.length_reverse] using
reverseOutputHaltInTime positive H v 0 (oldTableWord G)
(accumulatedVertices G H v) suffix [] loop.finalState
let first := StateTransition.EvalsToInTime.trans (TM2.step (program positive H))
_ _ _ _ _ initialRun loop.execution
let all := StateTransition.EvalsToInTime.trans (TM2.step (program positive H))
_ _ _ _ _ first finish
refine ⟨clearRegister loop.finalState, ?_, ?_, ?_⟩
· exact (caller_clearRegister loop.finalState).trans loop.caller_preserved
· simpa only [clearRegister] using loop.position_zero
· refine { toEvalsTo := all.toEvalsTo, steps_le_m := ?_ }
have bound := all.steps_le_m
have polynomialBound := completeBudget_le positive G H
unfold completeBudget at polynomialBound
omega
end DFVSGames.Foundations.Complexity.MachineExpanderTable
end
section
namespace DFVSGames.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 DFVSGames.Foundations.Complexity.MachineExpanderFamily
end
section
namespace DFVSGames.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 DFVSGames.Foundations.Complexity.MachineExpanderFamilyBounds
end
section
namespace DFVSGames.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 DFVSGames.Foundations.Complexity.MachineExpanderFamily
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