Decoding Fermat-ring residues back into Gaussian-integer blocks
ProvedNLogN.FW.dcL_specLet be a list of canonical residues modulo on stack XD, , and let the registers hold , , , , , . For , , , , the program dcL consumes and pushes on KO the (reversed) concatenation of decBlk F P r applied to each scaled residue scl (4rP) l c , within cost dcCost N r P Q W.
Formalization Note. decBlk (unpacking a residue into Gaussian integers with signed -bit digits) is from Def_IntMul_HvdH_MachineRef. The machine layer: IState HS is a state with stacks of items (Item = integer or mark), an input position and an output; RM programs (straight-line register code RS, loops rep, conditionals, calls of the multiplication procedure through a MulSpec giving its domain and cost) have a functional semantics p.run s, a definedness predicate p.ok M s and a cost p.cost M s; Spec M p s s' c abbreviates p.ok M s ∧ p.run s = s' ∧ p.cost M s ≤ c. ints L / gints U push an integer list / a list of pairs as items (head = top); zsz z is the bit length of . MulBnd M m Φ says the multiplication procedure accepts all pairs of integers of bit length at cost . Register names (GU, CR, KB, XN, …) are fixed stack indices.
-- Harvey–van der Hoeven multitape-TM development (NLogN), generated by skeleton subtraction. import Definitions.Def_IntMul_HvdH_M_Defs4 set_option autoImplicit false set_option relaxedAutoImplicit false set_option maxHeartbeats 1000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false open NLogN open NLogN.FW open IntMul IntMul.HvdH NLogN
theorem NLogN.FW.dcL_spec (M : MulSpec) (P r l N W : ℕ) (hP : 1 ≤ P) (hr1 : 1 ≤ r) (hl : l ≤ 4 * r * P) (s : IState HS)
(C : List ℤ) (RD LN LS LXN LXF LB LKN LR : List Item) (hCl : C.length = N)
(hCc : Canon (2 ^ (4 * r * P) + 1) C) (hX : s.G XD = ints C ++ RD)
(hN : s.G NN = .int (N : ℤ) :: LN) (hS : s.G SH = .int (2 ^ (4 * r * P - l)) :: LS)
(hXN : s.G NLogN.FW.XN = .int (2 ^ (4 * r * P)) :: LXN)
(hXF : s.G XF = .int (2 ^ (4 * r * P) + 1) :: LXF)
(hB : s.G KB = .int (2 ^ P) :: LB) (hKN : s.G KN = .int (2 ^ (4 * r * P)) :: LKN)
(hR : s.G KR = .int (r : ℤ) :: LR)
(hW : 2 * (4 * r * P) + 3 ≤ W) (hNW : zsz (N : ℤ) ≤ W) (Q : ℕ) (hPQ : P ≤ Q) (hrQ : zsz (r : ℤ) ≤ Q) :
Spec M dcL s ((s.upd XD RD).upd KO
(gints ((C.map (scl (4 * r * P) l)).flatMap (Ref.decBlk (2 ^ (4 * r * P) + 1) P r)).reverse ++
s.G KO)) (dcCost N r P Q W) := by sorry