cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Machines /MachineRegularDummyRow.lean
cfahlgren1's picture
download
raw
8.95 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.MachineUnaryAffine
import OAI.Combinatorics.IndependentSets.Machines.MachineCloudPadding
import OAI.Combinatorics.IndependentSets.Machines.MachineDummyRows
namespace OAI
namespace IndependentSetsGames.Foundations.Complexity.MachineRegularDummyRow
open Turing MachineComposition PCP.GraphTables
abbrev Tape := Fin 6
abbrev Alphabet (_ : Tape) := Bool
abbrev State (σ : Type) := σ × Option Bool
inductive Label
| affine (stage : MachineUnaryAffineAt.Label)
| row (stage : MachineDummyRows.Label 1)
| reverse | relation
deriving DecidableEq, Fintype
def reverseIndex (q x : Nat) : Nat := (q + 1) * x + q
def emittedBits (q x : Nat) : List Bool :=
MachineDummyRows.rowBits x (reverseIndex q x)
def instruction {σ Λ : Type} (q : Nat) (labels : Label → Λ) (exit : Option Λ) :
Label → TM2.Stmt Alphabet Λ (State σ)
| .affine .seed => MachineUnaryAffineAt.seed 1 q (labels (.affine .scan))
| .affine .scan => MachineUnaryAffineAt.scan 0 3 1 (q + 1)
(labels (.affine .scan)) (labels (.affine .restore))
| .affine .restore => Reduction.MachineTransfer.loopAt 3 0 id false
(labels (.affine .restore)) (some (labels (.row (MachineDummyRows.start 1))))
| .row stage => MachineCloudPadding.Placement.statement (id : Tape → Tape)
(fun l => labels (.row l)) (some (labels .reverse))
(MachineDummyRows.program 1 stage)
| .reverse => MachineDrain.drain 1 (labels .reverse) (some (labels .relation))
| .relation => MachineDrain.drain 2 (labels .relation) exit
structure Input (x : Nat) (base : Tape → List Bool) : Prop where
source : base 0 = encodeWord x
reverseEmpty : base 1 = []
relationEmpty : base 2 = []
scratchEmpty : base 3 = []
rowEmpty : base 5 = []
def memory (x : Nat) (output : List Bool) : Tape → List Bool :=
![encodeWord x, [], [], [], output, []]
theorem memory_input (x : Nat) (output : List Bool) : Input x (memory x output) :=
⟨rfl, rfl, rfl, rfl, rfl⟩
private theorem join_trace {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 affine_frame (x e : Nat) (base : Tape → List Bool) (input : Input x base) :
Function.update base 1 (encodeWord e) =
MachineDummyRows.initialTapes x e (base 4) := by
funext k
fin_cases k <;>
simp [MachineDummyRows.initialTapes, MachineDummyRows.fieldTapes,
input.source, input.relationEmpty, input.scratchEmpty, input.rowEmpty]
theorem cleanup_frame (x e : Nat) (output : List Bool)
(base : Tape → List Bool) (input : Input x base) :
Function.update (Function.update (MachineDummyRows.fieldTapes x e output) 1 []) 2 [] =
Function.update base 4 output := by
funext k
fin_cases k <;>
simp [MachineDummyRows.fieldTapes, input.source, input.reverseEmpty,
input.relationEmpty, input.scratchEmpty, input.rowEmpty]
theorem rowTraceAt {σ Λ : Type} (q : Nat) (labels : Label → Λ) (exit : Option Λ)
(program : Λ → TM2.Stmt Alphabet Λ (State σ))
(code : ∀ l, program (labels l) = instruction q labels exit l)
(x e : Nat) (output : List Bool) (ambient : σ) (register : Option Bool) :
(advance (TM2.step program))^[MachineDummyRows.steps x e output 1 + 1]
(some ⟨some (labels (.row (MachineDummyRows.start 1))), (ambient, register),
MachineDummyRows.initialTapes x e output⟩) =
some ⟨some (labels .reverse), (ambient, none),
MachineDummyRows.fieldTapes x (e + 1) (output ++ MachineDummyRows.rowBits x e)⟩ := by
have run := MachineDummyRows.allTrace 1 x e output ambient register
have placed := MachineCloudPadding.Placement.trace (id : Tape → Tape) (fun k => some k)
(fun _ => rfl) (fun _ _ h => (Option.some.inj h).symm)
(fun l => labels (.row l)) (some (labels .reverse)) (fun _ => [])
(MachineDummyRows.program 1) program
(fun l => code (.row l)) _ _ _ run
have identityTapes (source : Tape → List Bool) :
MachineCloudPadding.Placement.tapes (fun k : Tape => some k) source
(fun _ : Tape => []) = source := rfl
simpa only [MachineCloudPadding.Placement.configuration,
MachineCloudPadding.Placement.label, identityTapes,
MachineDummyRows.rowsBits, List.append_nil] using placed
theorem cleanupTraceAt {σ Λ : Type} (q : Nat) (labels : Label → Λ) (exit : Option Λ)
(program : Λ → TM2.Stmt Alphabet Λ (State σ))
(code : ∀ l, program (labels l) = instruction q labels exit l)
(x e : Nat) (output : List Bool) (ambient : σ) (register : Option Bool) :
(advance (TM2.step program))^[
((encodeWord e).length + 1) + (MachineDummyRows.trueBits.length + 1)]
(some ⟨some (labels .reverse), (ambient, register),
MachineDummyRows.fieldTapes x e output⟩) =
some ⟨exit, (ambient, none),
Function.update (Function.update (MachineDummyRows.fieldTapes x e output) 1 []) 2 []⟩ := by
let base := MachineDummyRows.fieldTapes x e output
let mid := Function.update base (1 : Tape) []
have first := MachineDrain.drainTrace (1 : Tape) (labels .reverse)
(some (labels .relation)) program (code .reverse) base (base 1) ambient register
have second := MachineDrain.drainTrace (2 : Tape) (labels .relation)
exit program (code .relation) mid (mid 2) ambient none
simp only [Function.update_eq_self] at first second
have hreverse : base 1 = encodeWord e := rfl
have hrelation : mid 2 = MachineDummyRows.trueBits := by
simp only [mid, Function.update_of_ne (by decide : (2 : Tape) ≠ 1)]
rfl
rw [hreverse] at first
rw [hrelation] at second
exact join_trace first second
def steps (q x : Nat) (output : List Bool) : Nat :=
((2 * (x + 1) + 1) + (MachineDummyRows.steps x (reverseIndex q x) output 1 + 1)) +
(((encodeWord (reverseIndex q x + 1)).length + 1) +
(MachineDummyRows.trueBits.length + 1))
def timeBound (q x outputLength : Nat) : Nat :=
(5 * q + 11) * x + 2 * outputLength + 5 * q + 40986
theorem steps_eq (q x : Nat) (output : List Bool) :
steps q x output = timeBound q x output.length := by
simp only [steps, MachineDummyRows.steps, encodeWord_length, MachineDummyRows.trueBits_length,
reverseIndex, timeBound]
ring
theorem traceAt {σ Λ : Type} (q : Nat) (labels : Label → Λ) (exit : Option Λ)
(program : Λ → TM2.Stmt Alphabet Λ (State σ))
(code : ∀ l, program (labels l) = instruction q labels exit l)
(x : Nat) (base : Tape → List Bool) (input : Input x base)
(ambient : σ) (register : Option Bool) :
(advance (TM2.step program))^[steps q x (base 4)]
(some ⟨some (labels (.affine .seed)), (ambient, register), base⟩) =
some ⟨exit, (ambient, none), Function.update base 4 (base 4 ++ emittedBits q x)⟩ := by
have affine := MachineUnaryAffineAt.seededAffineTrace (0 : Tape) 3 1
(by decide) (by decide) (by decide) (q + 1) q
(labels (.affine .seed)) (labels (.affine .scan)) (labels (.affine .restore))
(some (labels (.row (MachineDummyRows.start 1)))) program
(code (.affine .seed)) (code (.affine .scan)) (code (.affine .restore))
base x [] (by simpa only [List.append_nil] using input.source)
input.scratchEmpty ambient register
simp only [input.reverseEmpty, List.append_nil] at affine
change (advance (TM2.step program))^[2 * (x + 1) + 1]
(some ⟨some (labels (.affine .seed)), (ambient, register), base⟩) =
some ⟨some (labels (.row (MachineDummyRows.start 1))), (ambient, none),
Function.update base 1 (encodeWord (reverseIndex q x))⟩ at affine
rw [affine_frame x (reverseIndex q x) base input] at affine
have row := rowTraceAt q labels exit program code x (reverseIndex q x) (base 4) ambient none
have clean := cleanupTraceAt q labels exit program code x (reverseIndex q x + 1)
(base 4 ++ MachineDummyRows.rowBits x (reverseIndex q x)) ambient none
rw [cleanup_frame x (reverseIndex q x + 1) _ base input] at clean
exact join_trace (join_trace affine row) clean
def machine (q : Nat) : FinTM2 where
K := Tape
k₀ := 0
k₁ := 4
Γ := Alphabet
Λ := Label
main := .affine .seed
σ := State Unit
initialState := ((), none)
m := instruction q id none
def machineInTime (q x : Nat) (base : Tape → List Bool) (input : Input x base)
(register : Option Bool) :
StateTransition.EvalsToInTime (machine q).step
⟨some (.affine .seed), ((), register), base⟩
(some ⟨none, ((), none), Function.update base (4 : Tape)
(base 4 ++ emittedBits q x)⟩)
(timeBound q x (base 4).length) where
steps := steps q x (base 4)
evals_in_steps := traceAt q id none (instruction q id none)
(fun _ => rfl) x base input () register
steps_le_m := (steps_eq q x (base 4)).le
end IndependentSetsGames.Foundations.Complexity.MachineRegularDummyRow
end OAI

Xet Storage Details

Size:
8.95 kB
·
Xet hash:
766ace40c63fcbaf218144525995d173fcd65287f2155606abc489974221bb6f

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