Skip to content
Imports
@[expose] public sectionnamespace ConjectureMachines.Riemann95.ReferenceLogicalopen Turing StateTransition ConjectureMachines.Riemann120open ConjectureMachines.Riemann120.Layer2attribute [local irreducible] rows row word oldWord rowInstr role decoded instructiondef incReg (r : Nat) (regs : List Nat) : List Nat :=
regs.set r (regs.getD r 0 + 1)def applyInstr (i : RhInstr) (regs : List Nat) : Option RhRegCfg :=
match i with
| .halt => none
| .jump target => some ⟨target,regs⟩
| .inc r target => some ⟨target,incReg r regs⟩
| .decnz r positive zero =>
if regs.getD r 0 == 0 then some ⟨zero,regs⟩
else some ⟨positive,regs.set r (regs.getD r 0 - 1)⟩theorem step_effect (c : RhRegCfg) :
step c = applyInstr (instruction c.stack) c.regs := c:RhRegCfg⊢ step c = applyInstr (instruction c.stack) c.regs
c:RhRegCfg⊢ (match instruction c.stack with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (instruction c.stack) c.regs
c:RhRegCfg⊢ (match RhInstr.halt with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr RhInstr.halt c.regsc:RhRegCfgstack'✝:List (Fin 2)⊢ (match RhInstr.jump stack'✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.jump stack'✝) c.regsc:RhRegCfgr✝:ℕstack_succ✝:List (Fin 2)⊢ (match RhInstr.inc r✝ stack_succ✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.inc r✝ stack_succ✝) c.regsc:RhRegCfgr✝:ℕstack_succ✝:List (Fin 2)stack_fail✝:List (Fin 2)⊢ (match RhInstr.decnz r✝ stack_succ✝ stack_fail✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.decnz r✝ stack_succ✝ stack_fail✝) c.regs c:RhRegCfg⊢ (match RhInstr.halt with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr RhInstr.halt c.regsc:RhRegCfgstack'✝:List (Fin 2)⊢ (match RhInstr.jump stack'✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.jump stack'✝) c.regsc:RhRegCfgr✝:ℕstack_succ✝:List (Fin 2)⊢ (match RhInstr.inc r✝ stack_succ✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.inc r✝ stack_succ✝) c.regsc:RhRegCfgr✝:ℕstack_succ✝:List (Fin 2)stack_fail✝:List (Fin 2)⊢ (match RhInstr.decnz r✝ stack_succ✝ stack_fail✝ with
| RhInstr.halt => none
| RhInstr.jump target => some { stack := target, regs := c.regs }
| RhInstr.inc r target => some { stack := target, regs := c.regs.set r (c.regs.getD r 0 + 1) }
| RhInstr.decnz r positive zero =>
if (c.regs.getD r 0 == 0) = true then some { stack := zero, regs := c.regs }
else some { stack := positive, regs := c.regs.set r (c.regs.getD r 0 - 1) }) =
applyInstr (RhInstr.decnz r✝ stack_succ✝ stack_fail✝) c.regs All goals completed! 🐙theorem step_on_word (s : Fin 121) (regs : List Nat) :
step ⟨word s,regs⟩ = applyInstr (decoded s) regs := s:Fin 121regs:List ℕ⊢ step { stack := word s, regs := regs } = applyInstr (decoded s) regs
calc
_ = applyInstr (instruction (word s)) regs := step_effect _
_ = applyInstr (decoded s) regs := congrArg (fun i => applyInstr i regs) (instruction_word s)theorem old_step (w : Word) (i : RhInstr) (regs : List Nat)
(h : evalStackOf true w = i) :
rhRegStepOf true ⟨w,regs⟩ = applyInstr i regs := w:Wordi:RhInstrregs:List ℕh:evalStackOf true w = i⊢ rhRegStepOf true { stack := w, regs := regs } = applyInstr i regs
w:Wordi:RhInstrregs:List ℕh:evalStackOf true w = i⊢ (match i with
| RhInstr.halt => none
| RhInstr.jump stack' => some { stack := stack', regs := regs }
| RhInstr.inc r stack_succ => some { stack := stack_succ, regs := regs.set r (regs.getD r 0 + 1) }
| RhInstr.decnz r stack_succ stack_fail =>
if (regs.getD r 0 == 0) = true then some { stack := stack_fail, regs := regs }
else some { stack := stack_succ, regs := regs.set r (regs.getD r 0 - 1) }) =
applyInstr i regs
All goals completed! 🐙def RegRel (s : Fin 121) (fresh old : List Nat) : Prop :=
match role s with
| .secondSwap r => ∃ base : List Nat,
base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| _ => fresh.length = 5 ∧ old = freshtheorem regRel_ordinary (s : Fin 121) (ho : ordinary s)
(fresh old : List Nat) (hlen : fresh.length = 5) (heq : old = fresh) :
RegRel s fresh old := s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = fresh⊢ RegRel s fresh old
s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = fresh⊢ match role s with
| Role.secondSwap r => ∃ base, base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| x => fresh.length = 5 ∧ old = fresh
cases h : role s with
s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = freshr:ℕh:role s = Role.secondSwap r⊢ match Role.secondSwap r with
| Role.secondSwap r => ∃ base, base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| x => fresh.length = 5 ∧ old = fresh All goals completed! 🐙
s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = freshh:role s = Role.plain⊢ match Role.plain with
| Role.secondSwap r => ∃ base, base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| x => fresh.length = 5 ∧ old = fresh All goals completed! 🐙
s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = freshr:ℕh:role s = Role.firstSwap r⊢ match Role.firstSwap r with
| Role.secondSwap r => ∃ base, base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| x => fresh.length = 5 ∧ old = fresh All goals completed! 🐙
s:Fin 121ho:ordinary sfresh:List ℕold:List ℕhlen:fresh.length = 5heq:old = freshh:role s = Role.halfDec⊢ match Role.halfDec with
| Role.secondSwap r => ∃ base, base.length = 5 ∧ fresh = incReg r base ∧ old = incReg 4 base
| x => fresh.length = 5 ∧ old = fresh All goals completed! 🐙theorem inc_length (r : Nat) (regs : List Nat) :
(incReg r regs).length = regs.length := r:ℕregs:List ℕ⊢ (incReg r regs).length = regs.length All goals completed! 🐙theorem inc_commute (r : Nat) (regs : List Nat) (hlen : regs.length = 5)
(hr : r = 2 ∨ r = 3) :
incReg r (incReg 4 regs) = incReg 4 (incReg r regs) := r:ℕregs:List ℕhlen:regs.length = 5hr:r = 2 ∨ r = 3⊢ incReg r (incReg 4 regs) = incReg 4 (incReg r regs)
r:ℕhr:r = 2 ∨ r = 3hlen:[].length = 5⊢ incReg r (incReg 4 []) = incReg 4 (incReg r [])r:ℕhr:r = 2 ∨ r = 3m:ℕhlen:[m].length = 5⊢ incReg r (incReg 4 [m]) = incReg 4 (incReg r [m])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕhlen:[m, j].length = 5⊢ incReg r (incReg 4 [m, j]) = incReg 4 (incReg r [m, j])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕhlen:[m, j, x].length = 5⊢ incReg r (incReg 4 [m, j, x]) = incReg 4 (incReg r [m, j, x])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕhlen:[m, j, x, f].length = 5⊢ incReg r (incReg 4 [m, j, x, f]) = incReg 4 (incReg r [m, j, x, f])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕv:ℕrest:List ℕhlen:(m :: j :: x :: f :: v :: rest).length = 5⊢ incReg r (incReg 4 (m :: j :: x :: f :: v :: rest)) = incReg 4 (incReg r (m :: j :: x :: f :: v :: rest)) r:ℕhr:r = 2 ∨ r = 3hlen:[].length = 5⊢ incReg r (incReg 4 []) = incReg 4 (incReg r [])r:ℕhr:r = 2 ∨ r = 3m:ℕhlen:[m].length = 5⊢ incReg r (incReg 4 [m]) = incReg 4 (incReg r [m])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕhlen:[m, j].length = 5⊢ incReg r (incReg 4 [m, j]) = incReg 4 (incReg r [m, j])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕhlen:[m, j, x].length = 5⊢ incReg r (incReg 4 [m, j, x]) = incReg 4 (incReg r [m, j, x])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕhlen:[m, j, x, f].length = 5⊢ incReg r (incReg 4 [m, j, x, f]) = incReg 4 (incReg r [m, j, x, f])r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕv:ℕrest:List ℕhlen:(m :: j :: x :: f :: v :: rest).length = 5⊢ incReg r (incReg 4 (m :: j :: x :: f :: v :: rest)) = incReg 4 (incReg r (m :: j :: x :: f :: v :: rest))
r:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕv:ℕrest:List ℕhlen:rest.length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg r (incReg 4 (m :: j :: x :: f :: v :: rest)) = incReg 4 (incReg r (m :: j :: x :: f :: v :: rest))
all_goals try All goals completed! 🐙
cons.cons.cons.cons.consr:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕv:ℕrest:List ℕhlen:rest.length + 1 + 1 + 1 + 1 + 1 = 5he:rest = []⊢ incReg r (incReg 4 (m :: j :: x :: f :: v :: rest)) = incReg 4 (incReg r (m :: j :: x :: f :: v :: rest))
subst restcons.cons.cons.cons.consr:ℕhr:r = 2 ∨ r = 3m:ℕj:ℕx:ℕf:ℕv:ℕhlen:[].length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg r (incReg 4 [m, j, x, f, v]) = incReg 4 (incReg r [m, j, x, f, v])
rcases hr with rfl | rflcons.cons.cons.cons.cons.inlm:ℕj:ℕx:ℕf:ℕv:ℕhlen:[].length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg 2 (incReg 4 [m, j, x, f, v]) = incReg 4 (incReg 2 [m, j, x, f, v])cons.cons.cons.cons.cons.inrm:ℕj:ℕx:ℕf:ℕv:ℕhlen:[].length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg 3 (incReg 4 [m, j, x, f, v]) = incReg 4 (incReg 3 [m, j, x, f, v]) <;>cons.cons.cons.cons.cons.inlm:ℕj:ℕx:ℕf:ℕv:ℕhlen:[].length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg 2 (incReg 4 [m, j, x, f, v]) = incReg 4 (incReg 2 [m, j, x, f, v])cons.cons.cons.cons.cons.inrm:ℕj:ℕx:ℕf:ℕv:ℕhlen:[].length + 1 + 1 + 1 + 1 + 1 = 5⊢ incReg 3 (incReg 4 [m, j, x, f, v]) = incReg 4 (incReg 3 [m, j, x, f, v]) rflAll goals completed! 🐙end ConjectureMachines.Riemann95.ReferenceLogical