cfahlgren1's picture
download
raw
5.17 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.Machine
import OAI.Combinatorics.IndependentSets.Machines.MachineUnaryCounter
namespace OAI
namespace IndependentSetsGames.Foundations.Complexity.MachineLookup
open Turing
variable {K Λ σ : Type} [DecidableEq K]
abbrev Alphabet (_ : K) := Bool
def discard (source : K) (loopLabel returnLabel : Λ) :
TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) :=
.pop source (fun state head => (state.1, head))
(.branch (fun state => state.2.getD false)
(.goto fun _ => loopLabel)
(.load (fun state => (state.1, none)) (.goto fun _ => returnLabel)))
def select (source destination : K) (copyLabel rejected : Λ) :
TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) :=
.peek source (fun state head => (state.1, head))
(.branch (fun state => state.2.isSome)
(Hastad.SourceMachine.fieldStart destination copyLabel)
(.load (fun state => (state.1, none)) (.goto fun _ => rejected)))
inductive Label
| guard | skip | select | copy | accepted | rejected
deriving DecidableEq
instance : Fintype Label where
elems := {.guard, .skip, .select, .copy, .accepted, .rejected}
complete label := by cases label <;> simp
def program (index source destination : K) :
Label → TM2.Stmt (Alphabet (K := K)) Label (σ × Option Bool)
| .guard => MachineUnaryCounter.guard index .skip .select
| .skip => discard source .skip .guard
| .select => select source destination .copy .rejected
| .copy => Hastad.SourceMachine.fieldLoop source destination .copy (some .accepted)
| .accepted => .halt
| .rejected => .halt
def tapes (index source destination : K) (base : K → List Bool)
(counter input output : List Bool) : K → List Bool :=
Function.update (Function.update (Function.update base index counter) source input)
destination output
@[simp] theorem tapes_index (index source destination : K)
(his : index ≠ source) (hid : index ≠ destination)
(base : K → List Bool) (counter input output : List Bool) :
tapes index source destination base counter input output index = counter := by
simp [tapes, his, hid]
@[simp] theorem tapes_source (index source destination : K)
(hsd : source ≠ destination) (base : K → List Bool)
(counter input output : List Bool) :
tapes index source destination base counter input output source = input := by
simp [tapes, hsd]
@[simp] theorem tapes_destination (index source destination : K)
(base : K → List Bool) (counter input output : List Bool) :
tapes index source destination base counter input output destination = output := by
simp [tapes]
theorem tapes_other (index source destination p : K)
(hi : p ≠ index) (hs : p ≠ source) (hd : p ≠ destination)
(base : K → List Bool) (counter input output : List Bool) :
tapes index source destination base counter input output p = base p := by
simp [tapes, hi, hs, hd]
theorem update_index (index source destination : K)
(his : index ≠ source) (hid : index ≠ destination)
(base : K → List Bool) (counter input output replacement : List Bool) :
Function.update (tapes index source destination base counter input output) index replacement =
tapes index source destination base replacement input output := by
funext p
by_cases hi : p = index
· subst p; simp [tapes, his, hid]
· by_cases hs : p = source
· subst p; by_cases hs : source = destination <;> simp [tapes, hi, hs, Ne.symm hid]
· by_cases hd : p = destination
· subst p; simp [tapes, hi]
· simp [tapes, hi, hs, hd]
theorem update_source (index source destination : K) (hsd : source ≠ destination)
(base : K → List Bool) (counter input output replacement : List Bool) :
Function.update (tapes index source destination base counter input output) source replacement =
tapes index source destination base counter replacement output := by
funext p
by_cases hs : p = source
· subst p; simp [tapes, hsd]
· by_cases hd : p = destination
· subst p; simp [tapes, hs]
· simp [tapes, hs, hd]
theorem update_destination (index source destination : K)
(base : K → List Bool) (counter input output replacement : List Bool) :
Function.update (tapes index source destination base counter input output)
destination replacement = tapes index source destination base counter input replacement := by
simp [tapes]
theorem fieldTapes_eq (index source destination : K) (hsd : source ≠ destination)
(base : K → List Bool) (counter input output input' output' : List Bool) :
Hastad.SourceMachine.fieldTapes source destination
(tapes index source destination base counter input output) input' output' =
tapes index source destination base counter input' output' := by
rw [Hastad.SourceMachine.fieldTapes, update_source _ _ _ hsd, update_destination]
def machine : FinTM2 where
K := Fin 3
k₀ := 1
k₁ := 2
Γ _ := Bool
Λ := Label
main := .guard
σ := Unit × Option Bool
initialState := ((), none)
m := program 0 1 2
end IndependentSetsGames.Foundations.Complexity.MachineLookup
end OAI

Xet Storage Details

Size:
5.17 kB
·
Xet hash:
6144f97e312e679daa2ffd0ea1c10b689241bcc32a6ecfac3d75e633b4304c00

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