Imports
Control semantics and closure
@[expose] public section
Instruction semantics
sectionnamespace ConjectureMachines.Riemann95.Controlopen ConjectureMachines.Riemann120.Layer2open Schemainductive Effect where
| halt
| inc (r : Fin 5)
| decnz (r : Fin 5)
| jump (isContinue : Bool) (k : Nat)
deriving Inhabited, DecidableEq, Reprinductive Instr where
| halt
| jump (next : ControlWord)
| inc (r : Fin 5) (next : ControlWord)
| decnz (r : Fin 5) (positive zero : ControlWord)
deriving Inhabited, DecidableEq, Reprdef localEffects : Array Effect := #[
.decnz 4,
.decnz 4,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 4,
.decnz 4,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 2,
.decnz 2,
.inc 1,
.jump true 2,
.decnz 1,
.inc 2,
.jump true 1,
.decnz 2]def outsideEffects : Array Effect := #[
.decnz 3,
.inc 2,
.jump true 1,
.inc 4,
.decnz 4,
.inc 1,
.jump true 1,
.decnz 3,
.inc 0,
.jump true 1,
.decnz 0,
.decnz 1,
.inc 4,
.jump false 1,
.decnz 4,
.inc 1,
.jump true 1,
.inc 3,
.jump true 1,
.decnz 1,
.inc 1,
.decnz 3,
.inc 0,
.jump true 1,
.decnz 4,
.inc 3,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 0,
.inc 3,
.jump true 2,
.decnz 3,
.inc 0,
.jump true 1,
.decnz 4,
.inc 3,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 0,
.inc 3,
.jump true 2,
.decnz 3,
.inc 0,
.jump true 1,
.decnz 4,
.inc 3,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 0,
.inc 3,
.jump true 2,
.decnz 2,
.jump true 1,
.decnz 4,
.inc 2,
.inc 1,
.jump true 2,
.decnz 3,
.decnz 4,
.inc 1,
.jump true 1,
.decnz 3,
.inc 0,
.jump true 1,
.decnz 0,
.decnz 1,
.inc 4,
.jump false 1,
.decnz 4,
.inc 1,
.jump true 1,
.inc 3,
.jump true 1,
.decnz 2,
.jump false 0,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 4,
.inc 3,
.inc 1,
.jump true 2,
.decnz 1,
.inc 4,
.jump true 1,
.decnz 2,
.halt]def outsideInstrs : Array Instr := #[
.decnz 3 (.outside 1) (.outside 3),
.inc 2 (.outside 2),
.jump (.outside 0),
.inc 4 (.outside 4),
.decnz 4 (.outside 5) (.outside 7),
.inc 1 (.outside 6),
.jump (.outside 4),
.decnz 3 (.outside 8) (.outside 10),
.inc 0 (.outside 9),
.jump (.outside 7),
.decnz 0 (.outside 11) (.outside 19),
.decnz 1 (.outside 12) (.outside 14),
.inc 4 (.outside 13),
.jump (.outside 18),
.decnz 4 (.outside 15) (.outside 17),
.inc 1 (.outside 16),
.jump (.outside 14),
.inc 3 (.outside 18),
.jump (.outside 10),
.decnz 1 (.outside 20) (.outside 34),
.inc 1 (.outside 21),
.decnz 3 (.outside 22) (.outside 24),
.inc 0 (.outside 23),
.jump (.outside 21),
.decnz 4 (.outside 25) (.outside 28),
.inc 3 (.outside 26),
.inc 1 (.outside 27),
.jump (.outside 24),
.decnz 1 (.outside 29) (.outside 31),
.inc 4 (.outside 30),
.jump (.outside 28),
.decnz 0 (.outside 32) (.outside 34),
.inc 3 (.outside 33),
.jump (.outside 24),
.decnz 3 (.outside 35) (.outside 37),
.inc 0 (.outside 36),
.jump (.outside 34),
.decnz 4 (.outside 38) (.outside 41),
.inc 3 (.outside 39),
.inc 1 (.outside 40),
.jump (.outside 37),
.decnz 1 (.outside 42) (.outside 44),
.inc 4 (.outside 43),
.jump (.outside 41),
.decnz 0 (.outside 45) (.outside 47),
.inc 3 (.outside 46),
.jump (.outside 37),
.decnz 3 (.outside 48) (.outside 50),
.inc 0 (.outside 49),
.jump (.outside 47),
.decnz 4 (.outside 51) (.outside 54),
.inc 3 (.outside 52),
.inc 1 (.outside 53),
.jump (.outside 50),
.decnz 1 (.outside 55) (.outside 57),
.inc 4 (.outside 56),
.jump (.outside 54),
.decnz 0 (.outside 58) (.outside 60),
.inc 3 (.outside 59),
.jump (.outside 50),
.decnz 2 (.outside 61) (.outside 62),
.jump (.outside 3),
.decnz 4 (.outside 63) (.outside 66),
.inc 2 (.outside 64),
.inc 1 (.outside 65),
.jump (.outside 62),
.decnz 3 (.outside 67) (.outside 85),
.decnz 4 (.outside 68) (.outside 70),
.inc 1 (.outside 69),
.jump (.outside 67),
.decnz 3 (.outside 71) (.outside 73),
.inc 0 (.outside 72),
.jump (.outside 70),
.decnz 0 (.outside 74) (.outside 82),
.decnz 1 (.outside 75) (.outside 77),
.inc 4 (.outside 76),
.jump (.outside 81),
.decnz 4 (.outside 78) (.outside 80),
.inc 1 (.outside 79),
.jump (.outside 77),
.inc 3 (.outside 81),
.jump (.outside 73),
.decnz 2 (.outside 83) (.outside 84),
.jump (.outside 84),
.jump (.outside 66),
.decnz 1 (.outside 86) (.outside 88),
.inc 4 (.outside 87),
.jump (.outside 85),
.decnz 4 (.outside 89) (.outside 92),
.inc 3 (.outside 90),
.inc 1 (.outside 91),
.jump (.outside 88),
.decnz 1 (.outside 93) (.entry 0),
.inc 4 (.outside 94),
.jump (.outside 92),
.decnz 2 (.outside 96) (.outside 0),
.halt]def localInstr (d : Nat) (s : Fin 22) : Instr :=
match s.val with
| 0 => .decnz 4 (.local d 1) (.local d 4)
| 1 => .decnz 4 (.local d 2) (.local d 4)
| 2 => .inc 1 (.local d 3)
| 3 => .jump (.local d 0)
| 4 => .decnz 1 (.local d 5) (.local d 7)
| 5 => .inc 4 (.local d 6)
| 6 => .jump (.local d 4)
| 7 => .decnz 4 (.local d 8) (.local d 11)
| 8 => .decnz 4 (.local d 9) (.local d 11)
| 9 => .inc 1 (.local d 10)
| 10 => .jump (.local d 7)
| 11 => .decnz 1 (.local d 12) (.local d 14)
| 12 => .inc 4 (.local d 13)
| 13 => .jump (.local d 11)
| 14 => .decnz 2 (.local d 15) (.local d 18)
| 15 => .decnz 2 (.local d 16) (.local d 18)
| 16 => .inc 1 (.local d 17)
| 17 => .jump (.local d 14)
| 18 => .decnz 1 (.local d 19) (.entry (d+1))
| 19 => .inc 2 (.local d 20)
| 20 => .jump (.local d 18)
| 21 =>
match d with
| 0 => .decnz 2 (.outside 95) (.outside 0)
| 1 => .decnz 2 (.local 0 21) (.outside 95)
| d+2 => .decnz 2 (.local (d+1) 21) (.local d 21)
| _ => .haltdef instruction : ControlWord → Instr
| .outside s => outsideInstrs.getD s.val .halt
| .entry 0 => .decnz 4 (.local 0 0) (.outside 95)
| .entry (d+1) => .decnz 4 (.local (d+1) 0) (.local d 21)
| .local d s => localInstr d sdef effect : ControlWord → Effect
| .outside s => outsideEffects.getD s.val .halt
| .entry _ => .decnz 4
| .local _ s => localEffects.getD s.val .haltdef walked : ControlWord → Word
| .outside s => outsideWalk s
| .entry d => callerPrefix d ++ [0]
| .local d s => localWalk d sdef returned (isContinue : Bool) (k : Nat) (w : Word) : Word :=
if isContinue then (popContinueRev k w.reverse).reverse
else (popBreakRev k w.reverse).reversedef rawInstr (c : ControlWord) : RhInstr :=
let w := walked c
match effect c with
| .halt => .halt
| .inc r => .inc r.val (returned false 0 w)
| .decnz r => .decnz r.val (returned false 0 w) (returned false 1 w)
| .jump cont k => .jump (returned cont k w)def toRhInstr : Instr → RhInstr
| .halt => .halt
| .jump n => .jump (word n)
| .inc r n => .inc r.val (word n)
| .decnz r p z => .decnz r.val (word p) (word z)end ConjectureMachines.Riemann95.Controlnamespace ConjectureMachines.Riemann95.Controlopen ConjectureMachines.Riemann120.Layer2open Schematheorem outside_instruction_words : ∀ s : Fin 97,
rawInstr (.outside s) = toRhInstr (instruction (.outside s)) := ⊢ ∀ (s : Fin 97), rawInstr (ControlWord.outside s) = toRhInstr (instruction (ControlWord.outside s)) All goals completed! 🐙theorem entry_instruction_words (d : Nat) :
rawInstr (.entry d) = toRhInstr (instruction (.entry d)) := d:ℕ⊢ rawInstr (ControlWord.entry d) = toRhInstr (instruction (ControlWord.entry d))
cases d with
⊢ rawInstr (ControlWord.entry 0) = toRhInstr (instruction (ControlWord.entry 0)) All goals completed! 🐙
d:ℕ⊢ rawInstr (ControlWord.entry (d + 1)) = toRhInstr (instruction (ControlWord.entry (d + 1)))
All goals completed! 🐙theorem local_instruction_words (d : Nat) (s : Fin 22) :
rawInstr (.local d s) = toRhInstr (instruction (.local d s)) := d:ℕs:Fin 22⊢ rawInstr (ControlWord.local d s) = toRhInstr (instruction (ControlWord.local d s))
cases d with
s:Fin 22⊢ rawInstr (ControlWord.local 0 s) = toRhInstr (instruction (ControlWord.local 0 s)) ⊢ ∀ (s : Fin 22), rawInstr (ControlWord.local 0 s) = toRhInstr (instruction (ControlWord.local 0 s)); All goals completed! 🐙
s:Fin 22d:ℕ⊢ rawInstr (ControlWord.local (d + 1) s) = toRhInstr (instruction (ControlWord.local (d + 1) s))
cases d with
s:Fin 22⊢ rawInstr (ControlWord.local (0 + 1) s) = toRhInstr (instruction (ControlWord.local (0 + 1) s)) ⊢ ∀ (s : Fin 22), rawInstr (ControlWord.local (0 + 1) s) = toRhInstr (instruction (ControlWord.local (0 + 1) s)); All goals completed! 🐙
s:Fin 22d:ℕ⊢ rawInstr (ControlWord.local (d + 1 + 1) s) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) s))
d:ℕsv:ℕhsv:sv < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨sv, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨sv, hsv⟩))
d:ℕsv:ℕhsv:0 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨0, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨0, hsv⟩))d:ℕsv:ℕhsv:1 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨1, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨1, hsv⟩))d:ℕsv:ℕhsv:2 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨2, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨2, hsv⟩))d:ℕsv:ℕhsv:3 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨3, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨3, hsv⟩))d:ℕsv:ℕhsv:4 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨4, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨4, hsv⟩))d:ℕsv:ℕhsv:5 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨5, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨5, hsv⟩))d:ℕsv:ℕhsv:6 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨6, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨6, hsv⟩))d:ℕsv:ℕhsv:7 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨7, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨7, hsv⟩))d:ℕsv:ℕhsv:8 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨8, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨8, hsv⟩))d:ℕsv:ℕhsv:9 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨9, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨9, hsv⟩))d:ℕsv:ℕhsv:10 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨10, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨10, hsv⟩))d:ℕsv:ℕhsv:11 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨11, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨11, hsv⟩))d:ℕsv:ℕhsv:12 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨12, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨12, hsv⟩))d:ℕsv:ℕhsv:13 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨13, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨13, hsv⟩))d:ℕsv:ℕhsv:14 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨14, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨14, hsv⟩))d:ℕsv:ℕhsv:15 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨15, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨15, hsv⟩))d:ℕsv:ℕhsv:16 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨16, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨16, hsv⟩))d:ℕsv:ℕhsv:17 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨17, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨17, hsv⟩))d:ℕsv:ℕhsv:18 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨18, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨18, hsv⟩))d:ℕsv:ℕhsv:19 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨19, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨19, hsv⟩))d:ℕsv:ℕhsv:20 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨20, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨20, hsv⟩))d:ℕsv:ℕhsv:21 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨21, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨21, hsv⟩)) d:ℕsv:ℕhsv:0 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨0, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨0, hsv⟩))d:ℕsv:ℕhsv:1 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨1, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨1, hsv⟩))d:ℕsv:ℕhsv:2 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨2, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨2, hsv⟩))d:ℕsv:ℕhsv:3 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨3, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨3, hsv⟩))d:ℕsv:ℕhsv:4 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨4, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨4, hsv⟩))d:ℕsv:ℕhsv:5 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨5, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨5, hsv⟩))d:ℕsv:ℕhsv:6 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨6, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨6, hsv⟩))d:ℕsv:ℕhsv:7 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨7, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨7, hsv⟩))d:ℕsv:ℕhsv:8 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨8, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨8, hsv⟩))d:ℕsv:ℕhsv:9 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨9, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨9, hsv⟩))d:ℕsv:ℕhsv:10 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨10, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨10, hsv⟩))d:ℕsv:ℕhsv:11 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨11, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨11, hsv⟩))d:ℕsv:ℕhsv:12 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨12, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨12, hsv⟩))d:ℕsv:ℕhsv:13 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨13, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨13, hsv⟩))d:ℕsv:ℕhsv:14 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨14, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨14, hsv⟩))d:ℕsv:ℕhsv:15 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨15, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨15, hsv⟩))d:ℕsv:ℕhsv:16 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨16, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨16, hsv⟩))d:ℕsv:ℕhsv:17 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨17, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨17, hsv⟩))d:ℕsv:ℕhsv:18 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨18, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨18, hsv⟩))d:ℕsv:ℕhsv:19 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨19, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨19, hsv⟩))d:ℕsv:ℕhsv:20 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨20, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨20, hsv⟩))d:ℕsv:ℕhsv:21 < 22⊢ rawInstr (ControlWord.local (d + 1 + 1) ⟨21, hsv⟩) = toRhInstr (instruction (ControlWord.local (d + 1 + 1) ⟨21, hsv⟩))
All goals completed! 🐙
all_goals All goals completed! 🐙theorem instruction_words (c : ControlWord) :
rawInstr c = toRhInstr (instruction c) := c:ControlWord⊢ rawInstr c = toRhInstr (instruction c)
cases c with
s:Fin 97⊢ rawInstr (ControlWord.outside s) = toRhInstr (instruction (ControlWord.outside s)) All goals completed! 🐙
d:ℕ⊢ rawInstr (ControlWord.entry d) = toRhInstr (instruction (ControlWord.entry d)) All goals completed! 🐙
d:ℕs:Fin 22⊢ rawInstr (ControlWord.local d s) = toRhInstr (instruction (ControlWord.local d s)) All goals completed! 🐙end ConjectureMachines.Riemann95.Controlend
Control flow labels
Configuration closure
sectionnamespace ConjectureMachines.Riemann95.Controlopen Turing StateTransitionopen ConjectureMachines.Riemann120.Layer2open Schemaattribute [local irreducible] localEffects outsideEffects outsideInstrs localInstr
instruction effect walked rawInstrstructure Cfg where
control : ControlWord
regs : List Nat
deriving DecidableEq, Reprdef encodeCfg (c : Cfg) : RhRegCfg := ⟨word c.control,c.regs⟩def applyInstr (i : RhInstr) (regs : List Nat) : Option RhRegCfg :=
match i with
| .halt => none
| .jump n => some ⟨n,regs⟩
| .inc r n => some ⟨n,regs.set r (regs.getD r 0 + 1)⟩
| .decnz r p z =>
if regs.getD r 0 == 0 then some ⟨z,regs⟩
else some ⟨p,regs.set r (regs.getD r 0 - 1)⟩def step (c : Cfg) : Option Cfg :=
match instruction c.control with
| .halt => none
| .jump n => some ⟨n,c.regs⟩
| .inc r n => some ⟨n,c.regs.set r.val (c.regs.getD r.val 0 + 1)⟩
| .decnz r p z =>
if c.regs.getD r.val 0 == 0 then some ⟨z,c.regs⟩
else some ⟨p,c.regs.set r.val (c.regs.getD r.val 0 - 1)⟩theorem step_encode (c : Cfg) :
(step c).map encodeCfg = applyInstr (rawInstr c.control) c.regs := c:Cfg⊢ Option.map encodeCfg (step c) = applyInstr (rawInstr c.control) c.regs
c:Cfg⊢ Option.map encodeCfg (step c) = applyInstr (toRhInstr (instruction c.control)) c.regs
unfold stepc:Cfg⊢ Option.map encodeCfg
(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
applyInstr (toRhInstr (instruction c.control)) c.regs
cases instruction c.control with
| halt =>haltc:Cfg⊢ Option.map encodeCfg
(match Instr.halt with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
applyInstr (toRhInstr Instr.halt) c.regs rflAll goals completed! 🐙
| jump n =>jumpc:Cfgn:ControlWord⊢ Option.map encodeCfg
(match Instr.jump n with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
applyInstr (toRhInstr (Instr.jump n)) c.regs rflAll goals completed! 🐙
| inc r n =>incc:Cfgr:Fin 5n:ControlWord⊢ Option.map encodeCfg
(match Instr.inc r n with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
applyInstr (toRhInstr (Instr.inc r n)) c.regs rflAll goals completed! 🐙
| decnz r p z =>decnzc:Cfgr:Fin 5p:ControlWordz:ControlWord⊢ Option.map encodeCfg
(match Instr.decnz r p z with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
applyInstr (toRhInstr (Instr.decnz r p z)) c.regs
simp only [toRhInstr,applyInstr]decnzc:Cfgr:Fin 5p:ControlWordz:ControlWord⊢ Option.map encodeCfg
(if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
if (c.regs.getD (↑r) 0 == 0) = true then some { stack := word z, regs := c.regs }
else some { stack := word p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }
splitdecnz.isTruec:Cfgr:Fin 5p:ControlWordz:ControlWordh✝:(c.regs.getD (↑r) 0 == 0) = true⊢ Option.map encodeCfg (some { control := z, regs := c.regs }) = some { stack := word z, regs := c.regs }decnz.isFalsec:Cfgr:Fin 5p:ControlWordz:ControlWordh✝:¬(c.regs.getD (↑r) 0 == 0) = true⊢ Option.map encodeCfg (some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some { stack := word p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } <;>decnz.isTruec:Cfgr:Fin 5p:ControlWordz:ControlWordh✝:(c.regs.getD (↑r) 0 == 0) = true⊢ Option.map encodeCfg (some { control := z, regs := c.regs }) = some { stack := word z, regs := c.regs }decnz.isFalsec:Cfgr:Fin 5p:ControlWordz:ControlWordh✝:¬(c.regs.getD (↑r) 0 == 0) = true⊢ Option.map encodeCfg (some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some { stack := word p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } rflAll goals completed! 🐙theorem decoded_next_word_schema (c : ControlWord) (regs : List Nat) (next : RhRegCfg)
(hs : applyInstr (rawInstr c) regs = some next) :
∃ nextControl : ControlWord, word nextControl = next.stack := byc:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some next⊢ ∃ nextControl, word nextControl = next.stack
have hm : (step ⟨c,regs⟩).map encodeCfg = some next := (step_encode _).trans hsc:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nexthm:Option.map encodeCfg (step { control := c, regs := regs }) = some next⊢ ∃ nextControl, word nextControl = next.stack
cases ht : step ⟨c,regs⟩ with
| none =>nonec:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nexthm:Option.map encodeCfg (step { control := c, regs := regs }) = some nextht:step { control := c, regs := regs } = none⊢ ∃ nextControl, word nextControl = next.stack simp only [ht,Option.map_none] at hmnonec:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nextht:step { control := c, regs := regs } = nonehm:none = some next⊢ ∃ nextControl, word nextControl = next.stack; contradictionAll goals completed! 🐙
| some nc =>somec:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nexthm:Option.map encodeCfg (step { control := c, regs := regs }) = some nextnc:Cfght:step { control := c, regs := regs } = some nc⊢ ∃ nextControl, word nextControl = next.stack
simp only [ht,Option.map_some,Option.some.injEq] at hmsomec:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nextnc:Cfght:step { control := c, regs := regs } = some nchm:encodeCfg nc = next⊢ ∃ nextControl, word nextControl = next.stack
exact ⟨nc.control,congrArg RhRegCfg.stack hm⟩All goals completed! 🐙theorem decoded_next_noThree (c : ControlWord) (regs : List Nat) (next : RhRegCfg)
(hs : applyInstr (rawInstr c) regs = some next) :
ConjectureMachines.Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack) = true ∧
ConjectureMachines.Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack).reverse = true := byc:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some next⊢ Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack) = true ∧
Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack).reverse = true
obtain ⟨nc,hc⟩ := decoded_next_word_schema c regs next hsc:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nextnc:ControlWordhc:word nc = next.stack⊢ Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack) = true ∧
Riemann104.OnePassGuard.NoThreeZeros (1 :: next.stack).reverse = true
rw [←hcc:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nextnc:ControlWordhc:word nc = next.stack⊢ Riemann104.OnePassGuard.NoThreeZeros (1 :: word nc) = true ∧
Riemann104.OnePassGuard.NoThreeZeros (1 :: word nc).reverse = true]c:ControlWordregs:List ℕnext:RhRegCfghs:applyInstr (rawInstr c) regs = some nextnc:ControlWordhc:word nc = next.stack⊢ Riemann104.OnePassGuard.NoThreeZeros (1 :: word nc) = true ∧
Riemann104.OnePassGuard.NoThreeZeros (1 :: word nc).reverse = true
exact word_noThree ncAll goals completed! 🐙theorem step_regs_length (c next : Cfg) (hs : step c = some next) :
next.regs.length = c.regs.length := byc:Cfgnext:Cfghs:step c = some next⊢ next.regs.length = c.regs.length
unfold step at hsc:Cfgnext:Cfghs:(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some next⊢ next.regs.length = c.regs.length
cases hi : instruction c.control with
| halt =>haltc:Cfgnext:Cfghs:(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some nexthi:instruction c.control = Instr.halt⊢ next.regs.length = c.regs.length simp only [hi] at hshaltc:Cfgnext:Cfghi:instruction c.control = Instr.halths:none = some next⊢ next.regs.length = c.regs.length; contradictionAll goals completed! 🐙
| jump n =>jumpc:Cfgnext:Cfghs:(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some nextn:ControlWordhi:instruction c.control = Instr.jump n⊢ next.regs.length = c.regs.length simp only [hi,Option.some.injEq] at hsjumpc:Cfgnext:Cfgn:ControlWordhi:instruction c.control = Instr.jump nhs:{ control := n, regs := c.regs } = next⊢ next.regs.length = c.regs.length; subst nextjumpc:Cfgn:ControlWordhi:instruction c.control = Instr.jump n⊢ { control := n, regs := c.regs }.regs.length = c.regs.length; rflAll goals completed! 🐙
| inc r n =>incc:Cfgnext:Cfghs:(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some nextr:Fin 5n:ControlWordhi:instruction c.control = Instr.inc r n⊢ next.regs.length = c.regs.length simp only [hi,Option.some.injEq] at hsincc:Cfgnext:Cfgr:Fin 5n:ControlWordhi:instruction c.control = Instr.inc r nhs:{ control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) } = next⊢ next.regs.length = c.regs.length; subst nextincc:Cfgr:Fin 5n:ControlWordhi:instruction c.control = Instr.inc r n⊢ { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }.regs.length = c.regs.length; simpAll goals completed! 🐙
| decnz r p z =>decnzc:Cfgnext:Cfghs:(match instruction c.control with
| Instr.halt => none
| Instr.jump n => some { control := n, regs := c.regs }
| Instr.inc r n => some { control := n, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 + 1) }
| Instr.decnz r p z =>
if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some nextr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p z⊢ next.regs.length = c.regs.length
simp only [hi] at hsdecnzc:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zhs:(if (c.regs.getD (↑r) 0 == 0) = true then some { control := z, regs := c.regs }
else some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }) =
some next⊢ next.regs.length = c.regs.length
split at hsdecnz.isTruec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:(c.regs.getD (↑r) 0 == 0) = truehs:some { control := z, regs := c.regs } = some next⊢ next.regs.length = c.regs.lengthdecnz.isFalsec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = truehs:some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } = some next⊢ next.regs.length = c.regs.length <;>decnz.isTruec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:(c.regs.getD (↑r) 0 == 0) = truehs:some { control := z, regs := c.regs } = some next⊢ next.regs.length = c.regs.lengthdecnz.isFalsec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = truehs:some { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } = some next⊢ next.regs.length = c.regs.length simp only [Option.some.injEq] at hsdecnz.isFalsec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = truehs:{ control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } = next⊢ next.regs.length = c.regs.length <;>decnz.isTruec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:(c.regs.getD (↑r) 0 == 0) = truehs:{ control := z, regs := c.regs } = next⊢ next.regs.length = c.regs.lengthdecnz.isFalsec:Cfgnext:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = truehs:{ control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) } = next⊢ next.regs.length = c.regs.length subst nextdecnz.isFalsec:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = true⊢ { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }.regs.length = c.regs.length <;>decnz.isTruec:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:(c.regs.getD (↑r) 0 == 0) = true⊢ { control := z, regs := c.regs }.regs.length = c.regs.lengthdecnz.isFalsec:Cfgr:Fin 5p:ControlWordz:ControlWordhi:instruction c.control = Instr.decnz r p zh✝:¬(c.regs.getD (↑r) 0 == 0) = true⊢ { control := p, regs := c.regs.set (↑r) (c.regs.getD (↑r) 0 - 1) }.regs.length = c.regs.length simpAll goals completed! 🐙theorem initial_word : word (.outside 0) = [] := by⊢ word (ControlWord.outside 0) = [] decide +kernelAll goals completed! 🐙end ConjectureMachines.Riemann95.Controlend