cfahlgren1's picture
download
raw
4.46 kB
11
inductive Instr (r s l : ℕ) where
body · 13 lines
  | halt
  | goto (next : Fin l)
  | set (dst : Fin r) (value : Bool) (next : Fin l)
  | copy (dst src : Fin r) (next : Fin l)
  | bnot (dst src : Fin r) (next : Fin l)
  | band (dst left right : Fin r) (next : Fin l)
  | bor (dst left right : Fin r) (next : Fin l)
  | bxor (dst left right : Fin r) (next : Fin l)
  | branch (test : Fin r) (yes no : Fin l)
  | push (stack : Fin s) (src : Fin r) (next : Fin l)
  | peek (stack : Fin s) (value present : Fin r) (next : Fin l)
  | pop (stack : Fin s) (value present : Fin r) (next : Fin l)
  deriving DecidableEq, Fintype
26
structure Program (r s l : ℕ) where
body · 4 lines
  inputStack : Fin s
  outputStack : Fin s
  entry : Fin l
  code : Fin l → Instr r s l
32
structure Cfg (r s l : ℕ) where
body · 3 lines
  pc : Option (Fin l)
  regs : Fin r → Bool
  «stacks» : Fin s → List Bool
37
def readRegs {r : ℕ} (regs : Fin r → Bool) (value present : Fin r)
    (top : Option Bool) : Fin r → Bool :=
body · 1 line
  Function.update (Function.update regs value (top.getD false)) present top.isSome

One source instruction performs at most one stack operation.

42
def execInstr {r s l : ℕ} (instr : Instr r s l) (c : Cfg r s l) : Cfg r s l :=
body · 22 lines
  match instr with
  | .halt => { c with pc := none }
  | .goto next => { c with pc := some next }
  | .set dst value next =>
      { c with pc := some next, regs := Function.update c.regs dst value }
  | .copy dst src next =>
      { c with pc := some next, regs := Function.update c.regs dst (c.regs src) }
  | .bnot dst src next =>
      { c with pc := some next, regs := Function.update c.regs dst (!(c.regs src)) }
  | .band dst a b next =>
      { c with pc := some next, regs := Function.update c.regs dst (c.regs a && c.regs b) }
  | .bor dst a b next =>
      { c with pc := some next, regs := Function.update c.regs dst (c.regs a || c.regs b) }
  | .bxor dst a b next =>
      { c with pc := some next, regs := Function.update c.regs dst (c.regs a ^^ c.regs b) }
  | .branch test yes no => { c with pc := some (if c.regs test then yes else no) }
  | .push stack src next =>
      { c with pc := some next, «stacks» := Function.update c.stacks stack (c.regs src :: c.stacks stack) }
  | .peek stack value present next =>
      { c with pc := some next, regs := readRegs c.regs value present (c.stacks stack).head? }
  | .pop stack value present next =>
      { pc := some next, regs := readRegs c.regs value present (c.stacks stack).head?, «stacks» := Function.update c.stacks stack (c.stacks stack).tail }
66
abbrev step {r s l : ℕ} (p : Program r s l) (c : Cfg r s l) : Option (Cfg r s l) :=
body · 1 line
  c.pc.map fun label => execInstr (p.code label) c
69
abbrev initial {r s l : ℕ} (p : Program r s l) (input : List Bool) : Cfg r s l :=
body · 1 line
  ⟨some p.entry, fun _ => false, fun stack => if stack = p.inputStack then input else []⟩

A canonical output boundary, for the strong TM2 input/output convention.

73
abbrev terminal {r s l : ℕ} (p : Program r s l) (output : List Bool) : Cfg r s l :=
body · 1 line
  ⟨none, fun _ => false, fun stack => if stack = p.outputStack then output else []⟩
76
abbrev Trace {r s l : ℕ} (p : Program r s l) := SubexponentialSAT.Computation.Trace (step p)
77
abbrev RunsIn {r s l : ℕ} (p : Program r s l) := SubexponentialSAT.Computation.RunsIn (step p)
79
@[simp] theorem step_none {r s l : ℕ} (p : Program r s l) (c : Cfg r s l)
    (h : c.pc = none) : step p c = none := by simp [step, h]
82
theorem step_code {r s l : ℕ} (p : Program r s l) (c : Cfg r s l)
    (label : Fin l) (instr : Instr r s l) (hp : c.pc = some label)
    (hc : p.code label = instr) : step p c = some (execInstr instr c) := by
proof · 1 line
  simp [step, hp, hc]
87
@[simp] theorem readRegs_present {r : ℕ} (regs : Fin r → Bool)
    (value present : Fin r) (top : Option Bool) :
    readRegs regs value present top present = top.isSome := by
proof · 1 line
  simp [readRegs]
92
theorem readRegs_value {r : ℕ} (regs : Fin r → Bool)
    (value present : Fin r) (top : Option Bool) (h : value ≠ present) :
    readRegs regs value present top value = top.getD false := by
proof · 1 line
  simp [readRegs, h]

Xet Storage Details

Size:
4.46 kB
·
Xet hash:
516340c29915bb93941d6220daccdb259a6e3ab854145d02fb7619fc8d41db62

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