Imports
/- Copyright (c) 2026 Google LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. -/ module public import Cryptids.ReductionSupport.Riemann95.ReferenceBridge95 public import Cryptids.ReductionSupport.Riemann95.PrecreditTrace95
@[expose] public sectionnamespace ConjectureMachines.Riemann95.TypedPrewidthopen ConjectureMachines.Riemann120.Layer2 (RhRegCfg RhInstr)def swapReg : Nat → Nat | 0 => 3 | 3 => 0 | r => rdef swapBank (regs : List Nat) : List Nat := [regs.getD 3 0, regs.getD 1 0, regs.getD 2 0, regs.getD 0 0, regs.getD 4 0]def swapCfg (c : RhRegCfg) : RhRegCfg := ⟨c.stack, swapBank c.regs⟩def swapInstr : RhInstr → RhInstr | .halt => .halt | .jump n => .jump n | .inc r n => .inc (swapReg r) n | .decnz r p z => .decnz (swapReg r) p ztheorem swapBank_twice (regs : List Nat) (hlen : regs.length = 5) : swapBank (swapBank regs) = regs := regs:List ℕhlen:regs.length = 5⊢ swapBank (swapBank regs) = regs a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank (swapBank [a, b, c, d, e]) = [a, b, c, d, e] All goals completed! 🐙theorem swapBank_getD (regs : List Nat) (hlen : regs.length = 5) (r : Nat) : (swapBank regs).getD r 0 = regs.getD (swapReg r) 0 := regs:List ℕhlen:regs.length = 5r:ℕ⊢ (swapBank regs).getD r 0 = regs.getD (swapReg r) 0 r:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD r 0 = [a, b, c, d, e].getD (swapReg r) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD 0 0 = [a, b, c, d, e].getD (swapReg 0) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD 0 0 = [a, b, c, d, e].getD (swapReg 0) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1)) 0 try a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1)) 0 try a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1 + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1 + 1)) 0 try a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1 + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1 + 1 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1 + 1 + 1)) 0 a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ (swapBank [a, b, c, d, e]).getD (0 + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (0 + 1 + 1 + 1)) 0a:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ (swapBank [a, b, c, d, e]).getD (r + 1 + 1 + 1 + 1) 0 = [a, b, c, d, e].getD (swapReg (r + 1 + 1 + 1 + 1)) 0 try All goals completed! 🐙theorem swapBank_set (regs : List Nat) (hlen : regs.length = 5) (r value : Nat) : swapBank (regs.set (swapReg r) value) = (swapBank regs).set r value := regs:List ℕhlen:regs.length = 5r:ℕvalue:ℕ⊢ swapBank (regs.set (swapReg r) value) = (swapBank regs).set r value r:ℕvalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg r) value) = (swapBank [a, b, c, d, e]).set r value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg 0) value) = (swapBank [a, b, c, d, e]).set 0 valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg 0) value) = (swapBank [a, b, c, d, e]).set 0 valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1) value try value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1) value try value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1) value try value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1 + 1) value try value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1 + 1 + 1) value value:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5⊢ swapBank ([a, b, c, d, e].set (swapReg (0 + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (0 + 1 + 1 + 1 + 1) valuevalue:ℕa:ℕb:ℕc:ℕd:ℕe:ℕhlen:[a, b, c, d, e].length = 5r:ℕ⊢ swapBank ([a, b, c, d, e].set (swapReg (r + 1 + 1 + 1 + 1 + 1)) value) = (swapBank [a, b, c, d, e]).set (r + 1 + 1 + 1 + 1 + 1) value All goals completed! 🐙theorem apply_swapInstr (i : RhInstr) (regs : List Nat) (hlen : regs.length = 5) : (Control.applyInstr (swapInstr i) regs).map swapCfg = Control.applyInstr i (swapBank regs) := i:RhInstrregs:List ℕhlen:regs.length = 5⊢ Option.map swapCfg (Control.applyInstr (swapInstr i) regs) = Control.applyInstr i (swapBank regs) cases i with regs:List ℕhlen:regs.length = 5⊢ Option.map swapCfg (Control.applyInstr (swapInstr RhInstr.halt) regs) = Control.applyInstr RhInstr.halt (swapBank regs) All goals completed! 🐙 regs:List ℕhlen:regs.length = 5n:List (Fin 2)⊢ Option.map swapCfg (Control.applyInstr (swapInstr (RhInstr.jump n)) regs) = Control.applyInstr (RhInstr.jump n) (swapBank regs) All goals completed! 🐙 regs:List ℕhlen:regs.length = 5r:ℕn:List (Fin 2)⊢ Option.map swapCfg (Control.applyInstr (swapInstr (RhInstr.inc r n)) regs) = Control.applyInstr (RhInstr.inc r n) (swapBank regs) regs:List ℕhlen:regs.length = 5r:ℕn:List (Fin 2)⊢ some { stack := n, regs := swapBank (regs.set (swapReg r) (regs.getD (swapReg r) 0 + 1)) } = some { stack := n, regs := (swapBank regs).set r (regs.getD (swapReg r) 0 + 1) } All goals completed! 🐙 regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)⊢ Option.map swapCfg (Control.applyInstr (swapInstr (RhInstr.decnz r p z)) regs) = Control.applyInstr (RhInstr.decnz r p z) (swapBank regs) regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)⊢ Option.map swapCfg (if (regs.getD (swapReg r) 0 == 0) = true then some { stack := z, regs := regs } else some { stack := p, regs := regs.set (swapReg r) (regs.getD (swapReg r) 0 - 1) }) = if (regs.getD (swapReg r) 0 == 0) = true then some { stack := z, regs := swapBank regs } else some { stack := p, regs := (swapBank regs).set r (regs.getD (swapReg r) 0 - 1) } regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)h✝:(regs.getD (swapReg r) 0 == 0) = true⊢ Option.map swapCfg (some { stack := z, regs := regs }) = some { stack := z, regs := swapBank regs }regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)h✝:¬(regs.getD (swapReg r) 0 == 0) = true⊢ Option.map swapCfg (some { stack := p, regs := regs.set (swapReg r) (regs.getD (swapReg r) 0 - 1) }) = some { stack := p, regs := (swapBank regs).set r (regs.getD (swapReg r) 0 - 1) } regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)h✝:(regs.getD (swapReg r) 0 == 0) = true⊢ Option.map swapCfg (some { stack := z, regs := regs }) = some { stack := z, regs := swapBank regs }regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)h✝:¬(regs.getD (swapReg r) 0 == 0) = true⊢ Option.map swapCfg (some { stack := p, regs := regs.set (swapReg r) (regs.getD (swapReg r) 0 - 1) }) = some { stack := p, regs := (swapBank regs).set r (regs.getD (swapReg r) 0 - 1) } regs:List ℕhlen:regs.length = 5r:ℕp:List (Fin 2)z:List (Fin 2)h✝:¬(regs.getD (swapReg r) 0 == 0) = true⊢ some { stack := p, regs := swapBank (regs.set (swapReg r) (regs.getD (swapReg r) 0 - 1)) } = some { stack := p, regs := (swapBank regs).set r (regs.getD (swapReg r) 0 - 1) } All goals completed! 🐙end ConjectureMachines.Riemann95.TypedPrewidth