cfahlgren1's picture
download
raw
20.2 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.MachineRegularLift
import OAI.Combinatorics.IndependentSets.Expansion.PreprocessingRegularLoopWords
import OAI.Combinatorics.IndependentSets.Machines.ComputeTime
namespace OAI
namespace IndependentSetsGames.Foundations.Complexity.MachineRegularTable
open Turing MachineComposition
open IndependentSetsGames.Foundations.PCP
namespace Top
def headerStates :
(Header.State Unit × (MachineRegularOriginalBody.CoreState ×
(MachineRegularOriginalBody.FamilyState × Option Bool))) ≃ State where
toFun p := (((p.2.1, p.1), p.2.2.1), p.2.2.2)
invFun p := (p.1.1.2, (p.1.1.1, (p.1.2, p.2)))
left_inv _ := rfl
right_inv _ := rfl
def readyState (H : BaseTable) : State := (MachineRegularOriginalBody.readyState H, none)
inductive CopyPhase | old | owner
deriving DecidableEq
instance : Fintype CopyPhase where
elems := {.old, .owner}
complete phase := by cases phase <;> simp
def copySource : CopyPhase → Tape
| .old => coreTape 6
| .owner => headerTape Header.nTape
def copyTarget : CopyPhase → Tape
| .old => oldFuel
| .owner => ownerFuel
inductive Label
| header (l : Header.Label)
| oldSeed
| copyFirst (phase : CopyPhase)
| copySecond (phase : CopyPhase)
| oldGuard
| oldBody (l : MachineRegularOriginalBody.Label)
| oldIncrement
| ownerSeed
| ownerGuard
| ownerBody (l : MachineRegularOwnerBody.Label)
| ownerIncrement
| clear (i : Fin 7)
deriving DecidableEq, Fintype
def copyExit : CopyPhase → Label
| .old => .oldGuard
| .owner => .ownerGuard
def clearTape : Fin 7 → Tape :=
![coreTape 1, coreTape 2, coreTape 5, coreTape 6,
headerTape Header.nTape, headerTape Header.verticesTape, headerTape Header.dartsTape]
def clearEntry (k : Nat) : Option Label :=
if h : k < 7 then some (.clear ⟨k, h⟩) else none
def program (H : BaseTable) : Label → TM2.Stmt Alphabet Label State
| .header l => Lift.statement headerTape Label.header (some .oldSeed) headerStates
(Header.program PreprocessingRegularTables.internalDegree l)
| .oldSeed => .push (coreTape 1) (fun _ => false) (.goto fun _ => Label.copyFirst CopyPhase.old)
| .copyFirst phase => Reduction.MachineTransfer.loopAt (copySource phase) scratch id false
(.copyFirst phase) (some (.copySecond phase))
| .copySecond phase => MachineCopy.forkLoop scratch (copySource phase) (copyTarget phase) false
(.copySecond phase) (some (copyExit phase))
| .oldGuard => Fuel.guard oldFuel (Label.oldBody MachineRegularOriginalBody.entry) (some Label.ownerSeed)
| .oldBody l => Lift.statement Sum.inl Label.oldBody (some .oldIncrement) (Equiv.refl _)
(MachineRegularOriginalBody.program H l)
| .oldIncrement => Fuel.increment (coreTape 1) Label.oldGuard
| .ownerSeed => .push (coreTape 2) (fun _ => false)
(.push (coreTape 5) (fun _ => false) (.goto fun _ => Label.copyFirst CopyPhase.owner))
| .ownerGuard => Fuel.guard ownerFuel (.ownerBody MachineRegularOwnerBody.entry) (clearEntry 0)
| .ownerBody l => MachineCloudPadding.Placement.statement ownerTape Label.ownerBody
(some .ownerIncrement) (MachineRegularOwnerBody.program H l)
| .ownerIncrement => Fuel.increment (coreTape 2) Label.ownerGuard
| .clear i => MachineDrain.drain (clearTape i) (.clear i) (clearEntry (i.val + 1))
def machine (H : BaseTable) : FinTM2 where
K := Tape
k₀ := coreTape 0
k₁ := coreTape 8
Γ _ := Bool
Λ := Label
main := .header .init
σ := State
initialState := readyState H
m := program H
def frame (data : Data) (header : Header.Tape → List Bool) (counters : Fin 4 → List Bool) :
Tape → List Bool
| .inl k => MachineRegularOriginalBody.frame data k
| .inr (.inl k) => header k
| .inr (.inr i) => counters i
def cfg (H : BaseTable) (label : Option Label) (data : Data)
(header : Header.Tape → List Bool) (counters : Fin 4 → List Bool) :
TM2.Cfg Alphabet Label State :=
⟨label, readyState H, frame data header counters⟩
@[simp] theorem frame_core (data : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) (i : Fin 27) :
frame data header counters (coreTape i) = MachineRegularMetadata.frame data (.inl i) := rfl
theorem bodyPlacement (data extra : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) :
MachineCloudPadding.Placement.tapes bodyView (MachineRegularOriginalBody.frame data)
(frame extra header counters) = frame data header counters := by
funext j
cases j with
| inl j => rfl
| inr j => cases j <;> rfl
def headerAux (n N R : List Bool) : Header.Tape → List Bool := fun k =>
if k = Header.nTape then n
else if k = Header.verticesTape then N
else if k = Header.dartsTape then R
else []
@[simp] theorem headerAux_empty : headerAux [] [] [] = (fun _ => []) := by
funext k
simp [headerAux]
theorem headerPlacement (data : Data) (t n m N R output : List Bool)
(counters : Fin 4 → List Bool) :
MachineCloudPadding.Placement.tapes headerView
(Header.frame t n [] [] [] m [] [] [] N R [] output)
(frame data (fun _ => []) counters) =
frame { data with table := t, darts := m, output := output } (headerAux n N R) counters := by
funext j
cases j with
| inl j =>
cases j with
| inl i => fin_cases i <;> rfl
| inr e => cases e with
| inl e => cases e <;> rfl
| inr e => rfl
| inr j =>
cases j with
| inl k =>
cases k with
| inl k =>
cases k with
| inner k => cases k <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr k => cases k <;> rfl
| inr i => rfl
def inputData (t : GraphTables.Table) (output : List Bool) : Data where
table := GraphTables.tableBits t
globalIndex := []
owner := []
localRank := []
count := []
offset := []
darts := []
rotor := []
output := output
padding := []
level := []
def headerData (t : GraphTables.Table) (output : List Bool) : Data :=
{ inputData t output with darts := encodeWord t.darts }
def headerStacks (t : GraphTables.Table) : Header.Tape → List Bool :=
headerAux (encodeWord t.vertices) (encodeWord (Header.vertexTotal t))
(encodeWord (Header.dartTotal PreprocessingRegularTables.internalDegree t))
theorem headerTrace (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(counters : Fin 4 → List Bool) :
(advance (TM2.step (program H)))^[Header.totalTime PreprocessingRegularTables.internalDegree t output]
(some (cfg H (some (.header .init)) (inputData t output) (fun _ => []) counters)) =
some (cfg H (some .oldSeed)
(headerData t (output ++ Header.headerBits PreprocessingRegularTables.internalDegree t))
(headerStacks t) counters) := by
have raw := Header.trace PreprocessingRegularTables.internalDegree t output () none
have placed := Lift.trace headerTape headerView headerView_left headerView_right
Label.header (some .oldSeed) headerStates
(MachineRegularInternalRow.coreInitialState PreprocessingRegularTables.internalDegree
MachineRegularOriginalBody.degree_positive (), (MachineRegularFamily.readyState H, none))
(frame (inputData t output) (fun _ => []) counters)
(Header.program PreprocessingRegularTables.internalDegree) (program H) (fun _ => rfl)
_ _ _ raw
simpa only [Lift.configuration, MachineCloudPadding.Placement.label, headerPlacement,
headerAux_empty, cfg, readyState, MachineRegularOriginalBody.readyState, headerStates,
Equiv.coe_fn_mk, headerData, inputData, headerStacks] using placed
def oldData (t : GraphTables.Table) (index : Nat) (output : List Bool) : Data :=
{ headerData t output with globalIndex := encodeWord index }
theorem originalData_eq (t : GraphTables.Table) (e : Fin t.darts) (output : List Bool) :
MachineRegularOriginalBody.initialData t e output = oldData t e.val output := rfl
theorem oldBodyTrace (H : BaseTable) (t : GraphTables.Table) (e : Fin t.darts)
(output : List Bool) (header : Header.Tape → List Bool) (counters : Fin 4 → List Bool) :
(advance (TM2.step (program H)))^[MachineRegularOriginalBody.totalSteps H t e output]
(some (cfg H (some (Label.oldBody MachineRegularOriginalBody.entry))
(oldData t e.val output) header counters)) =
some (cfg H (some .oldIncrement)
(oldData t e.val (output ++ MachineRegularOriginalBody.emittedBits H t e)) header counters) := by
have raw := MachineRegularOriginalBody.originalTrace H t e output
have placed := Lift.trace Sum.inl bodyView bodyView_left bodyView_right Label.oldBody
(some .oldIncrement) (Equiv.refl _) none
(frame (oldData t e.val output) header counters)
(MachineRegularOriginalBody.program H) (program H) (fun _ => rfl) _ _ _ raw
simpa only [Lift.configuration, MachineCloudPadding.Placement.label, bodyPlacement,
MachineRegularOriginalBody.cfg, originalData_eq, cfg, readyState, Equiv.refl_apply] using placed
def counterStacks (old owners dummy work : List Bool) : Fin 4 → List Bool :=
![old, owners, dummy, work]
@[simp] theorem frame_oldFuel (data : Data) (header : Header.Tape → List Bool)
(old owners dummy work : List Bool) :
frame data header (counterStacks old owners dummy work) oldFuel = old := rfl
@[simp] theorem frame_ownerFuel (data : Data) (header : Header.Tape → List Bool)
(old owners dummy work : List Bool) :
frame data header (counterStacks old owners dummy work) ownerFuel = owners := rfl
@[simp] theorem update_frame_oldFuel (data : Data) (header : Header.Tape → List Bool)
(old owners dummy work replacement : List Bool) :
Function.update (frame data header (counterStacks old owners dummy work)) oldFuel replacement =
frame data header (counterStacks replacement owners dummy work) := by
funext j
cases j with
| inl j => rfl
| inr j => cases j with
| inl j => rfl
| inr i => fin_cases i <;> rfl
@[simp] theorem update_frame_ownerFuel (data : Data) (header : Header.Tape → List Bool)
(old owners dummy work replacement : List Bool) :
Function.update (frame data header (counterStacks old owners dummy work)) ownerFuel replacement =
frame data header (counterStacks old replacement dummy work) := by
funext j
cases j with
| inl j => rfl
| inr j => cases j with
| inl j => rfl
| inr i => fin_cases i <;> rfl
@[simp] theorem update_frame_global (data : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) (replacement : List Bool) :
Function.update (frame data header counters) (coreTape 1) replacement =
frame { data with globalIndex := replacement } header counters := by
funext j
cases j with
| inl j => cases j with
| inl i => fin_cases i <;> rfl
| inr e => cases e with
| inl e => cases e <;> rfl
| inr e => rfl
| inr j => cases j <;> rfl
@[simp] theorem update_frame_owner (data : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) (replacement : List Bool) :
Function.update (frame data header counters) (coreTape 2) replacement =
frame { data with owner := replacement } header counters := by
funext j
cases j with
| inl j => cases j with
| inl i => fin_cases i <;> rfl
| inr e => cases e with
| inl e => cases e <;> rfl
| inr e => rfl
| inr j => cases j <;> rfl
theorem oldGuardStep (H : BaseTable) (data : Data) (header : Header.Tape → List Bool)
(remaining : Nat) :
(advance (TM2.step (program H)))^[1]
(some (cfg H (some .oldGuard) data header
(counterStacks (encodeWord (remaining + 1)) [] [] []))) =
some (cfg H (some (Label.oldBody MachineRegularOriginalBody.entry)) data header
(counterStacks (encodeWord remaining) [] [] [])) := by
change some (TM2.stepAux (Fuel.guard oldFuel (Label.oldBody MachineRegularOriginalBody.entry)
(some Label.ownerSeed)) (readyState H) _) = _
simp only [Fuel.guard, TM2.stepAux, frame_oldFuel, encodeWord, List.replicate_succ,
List.cons_append, List.head?_cons, List.tail_cons, Option.getD_some,
Bool.cond_true, update_frame_oldFuel]
rfl
theorem oldGuardExit (H : BaseTable) (data : Data) (header : Header.Tape → List Bool) :
(advance (TM2.step (program H)))^[1]
(some (cfg H (some .oldGuard) data header (counterStacks (encodeWord 0) [] [] []))) =
some (cfg H (some Label.ownerSeed) data header (counterStacks [] [] [] [])) := by
change some (TM2.stepAux (Fuel.guard oldFuel (Label.oldBody MachineRegularOriginalBody.entry)
(some Label.ownerSeed)) (readyState H) _) = _
simp only [Fuel.guard, TM2.stepAux, frame_oldFuel, encodeWord, List.replicate_zero,
List.nil_append, List.head?_cons, List.tail_cons, Option.getD_some,
Bool.cond_false, update_frame_oldFuel]
rfl
theorem oldIncrementStep (H : BaseTable) (t : GraphTables.Table) (index : Nat)
(output : List Bool) (header : Header.Tape → List Bool) (counters : Fin 4 → List Bool) :
(advance (TM2.step (program H)))^[1]
(some (cfg H (some .oldIncrement) (oldData t index output) header counters)) =
some (cfg H (some .oldGuard) (oldData t (index + 1) output) header counters) := by
change some (TM2.stepAux (Fuel.increment (coreTape 1) Label.oldGuard)
(readyState H) (frame (oldData t index output) header counters)) = _
simp only [Fuel.increment, TM2.stepAux, frame_core]
change some (⟨some Label.oldGuard, readyState H,
Function.update (frame (oldData t index output) header counters) (coreTape 1)
(true :: encodeWord index)⟩ : TM2.Cfg (fun _ : Tape => Bool) Label State) = _
rw [update_frame_global]
simp only [cfg, oldData, encodeWord, List.replicate_succ, List.cons_append]
def oldPrefix (H : BaseTable) (t : GraphTables.Table) (k : Nat) : List Bool :=
PreprocessingRegularLoopWords.blocksPrefix (MachineRegularOriginalBody.emittedBits H t) k
noncomputable def oldElapsed (H : BaseTable) (t : GraphTables.Table) (output : List Bool) : Nat → Nat
| 0 => 0
| k + 1 => oldElapsed H t output k +
if h : k < t.darts then
1 + MachineRegularOriginalBody.totalSteps H t ⟨k,h⟩ (output ++ oldPrefix H t k) + 1
else 0
theorem joinTrace {A : Type*} {f : A → A} {m n : Nat} {a b c : A}
(first : f^[m] a = b) (second : f^[n] b = c) : f^[m + n] a = c := by
rw [Nat.add_comm m n, Function.iterate_add_apply, first, second]
theorem oldPrefixTrace (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(header : Header.Tape → List Bool) (k : Nat) : k ≤ t.darts →
(advance (TM2.step (program H)))^[oldElapsed H t output k]
(some (cfg H (some .oldGuard) (oldData t 0 output) header
(counterStacks (encodeWord t.darts) [] [] []))) =
some (cfg H (some .oldGuard) (oldData t k (output ++ oldPrefix H t k)) header
(counterStacks (encodeWord (t.darts-k)) [] [] [])) := by
induction k with
| zero =>
intro _
simp [oldElapsed, oldPrefix]
| succ k ih =>
intro hk
have hlt : k < t.darts := by omega
have hremaining : t.darts-k = (t.darts-(k+1))+1 := by omega
have previous := ih (by omega)
have guard := oldGuardStep H (oldData t k (output ++ oldPrefix H t k)) header
(t.darts-(k+1))
rw [← hremaining] at guard
have body := oldBodyTrace H t ⟨k,hlt⟩ (output ++ oldPrefix H t k) header
(counterStacks (encodeWord (t.darts-(k+1))) [] [] [])
have increment := oldIncrementStep H t k
((output ++ oldPrefix H t k) ++ MachineRegularOriginalBody.emittedBits H t ⟨k,hlt⟩)
header (counterStacks (encodeWord (t.darts-(k+1))) [] [] [])
have combined := joinTrace (joinTrace (joinTrace previous guard) body) increment
have bits := PreprocessingRegularLoopWords.blocksPrefix_succ
(MachineRegularOriginalBody.emittedBits H t) k hlt
change oldPrefix H t (k+1) = oldPrefix H t k ++
MachineRegularOriginalBody.emittedBits H t ⟨k,hlt⟩ at bits
simpa only [oldElapsed, dite_eq_left hlt, bits, List.append_assoc, Nat.add_assoc] using combined
theorem oldLoopTrace (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(header : Header.Tape → List Bool) :
(advance (TM2.step (program H)))^[oldElapsed H t output t.darts + 1]
(some (cfg H (some .oldGuard) (oldData t 0 output) header
(counterStacks (encodeWord t.darts) [] [] []))) =
some (cfg H (some Label.ownerSeed)
(oldData t t.darts (output ++ oldPrefix H t t.darts)) header
(counterStacks [] [] [] [])) := by
have prefixRun := oldPrefixTrace H t output header t.darts (Nat.le_refl _)
simp only [Nat.sub_self] at prefixRun
exact joinTrace prefixRun (oldGuardExit H _ header)
@[simp] theorem frame_scratch (data : Data) (header : Header.Tape → List Bool)
(old owners dummy work : List Bool) :
frame data header (counterStacks old owners dummy work) scratch = work := rfl
@[simp] theorem frame_darts (data : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) : frame data header counters (coreTape 6) = data.darts := rfl
@[simp] theorem frame_header_n (data : Data) (n N R : List Bool)
(counters : Fin 4 → List Bool) :
frame data (headerAux n N R) counters (headerTape Header.nTape) = n := rfl
theorem oldSeedStep (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(header : Header.Tape → List Bool) (counters : Fin 4 → List Bool) :
(advance (TM2.step (program H)))^[1]
(some (cfg H (some .oldSeed) (headerData t output) header counters)) =
some (cfg H (some (.copyFirst .old)) (oldData t 0 output) header counters) := by
change some (TM2.stepAux (.push (coreTape 1) (fun _ => false)
(.goto fun _ => Label.copyFirst CopyPhase.old)) (readyState H) (frame (headerData t output) header counters)) = _
change some (⟨some (Label.copyFirst CopyPhase.old), readyState H,
Function.update (frame (headerData t output) header counters) (coreTape 1) [false]⟩ :
TM2.Cfg (fun _ : Tape => Bool) Label State) = _
rw [update_frame_global]
rfl
theorem copyOldTrace (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(header : Header.Tape → List Bool) :
(advance (TM2.step (program H)))^[2*(t.darts+2)]
(some (cfg H (some (.copyFirst .old)) (oldData t 0 output) header
(counterStacks [] [] [] []))) =
some (cfg H (some .oldGuard) (oldData t 0 output) header
(counterStacks (encodeWord t.darts) [] [] [])) := by
have h := MachineCopy.copyTrace (coreTape 6) oldFuel scratch
(by decide) (by decide) (by decide) false (.copyFirst .old) (.copySecond .old)
(some .oldGuard) (program H) rfl rfl
(frame (oldData t 0 output) header (counterStacks [] [] [] [])) rfl
(MachineRegularOriginalBody.readyState H) none
simpa only [frame_darts, oldData, headerData, inputData, encodeWord_length,
frame_oldFuel, List.append_nil, update_frame_oldFuel, cfg, readyState, Nat.add_assoc] using h
theorem oldStageTrace (H : BaseTable) (t : GraphTables.Table) (output : List Bool)
(header : Header.Tape → List Bool) :
(advance (TM2.step (program H)))^[1+2*(t.darts+2)+(oldElapsed H t output t.darts+1)]
(some (cfg H (some .oldSeed) (headerData t output) header (counterStacks [] [] [] []))) =
some (cfg H (some Label.ownerSeed)
(oldData t t.darts (output ++ oldPrefix H t t.darts)) header
(counterStacks [] [] [] [])) :=
joinTrace (joinTrace (oldSeedStep H t output header _) (copyOldTrace H t output header))
(oldLoopTrace H t output header)
@[simp] theorem update_frame_offset (data : Data) (header : Header.Tape → List Bool)
(counters : Fin 4 → List Bool) (replacement : List Bool) :
Function.update (frame data header counters) (coreTape 5) replacement =
frame { data with offset := replacement } header counters := by
funext j
cases j with
| inl j => cases j with
| inl i => fin_cases i <;> rfl
| inr e => cases e with
| inl e => cases e <;> rfl
| inr e => rfl
| inr j => cases j <;> rfl
end Top
end IndependentSetsGames.Foundations.Complexity.MachineRegularTable
end OAI

Xet Storage Details

Size:
20.2 kB
·
Xet hash:
d32c5b54ffad84c964a05873576e9907dd2a537028a178ec01c9eeac40f98e46

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