Packing a digit list into one integer: cost
ProvedNLogN.packOne_costUnder the hypotheses of the packing result (stack holds the reversed list of digits with , CR holds , CM holds , registers distinct), and , , the program packOne E_i X costs at most .
Formalization Note. 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 open NLogN open IntMul IntMul.HvdH IntMul.HvdH.Ref set_option maxHeartbeats 1000000
theorem NLogN.packOne_cost (M : MulSpec) (Ei X : Fin HS) (s : IState HS) (b Q : ℕ) (L : List ℤ)
(Ri LR LM : List Item)
(hEi : s.G Ei = ints L.reverse ++ Ri) (hR : s.G CR = .int (2 ^ b) :: LR)
(hM : s.G CM = .int L.length :: LM) (hL : ∀ x ∈ L, 0 ≤ x ∧ x < 2 ^ b)
(hb1 : 1 ≤ b) (hbQ : b ≤ Q) (hMQ : zsz (L.length : ℤ) ≤ Q)
(h1 : Ei ≠ CA) (h2 : Ei ≠ CY) (h3 : Ei ≠ CR) (h4 : Ei ≠ CM) (h5 : Ei ≠ EC) (h6 : Ei ≠ X)
(h7 : X ≠ CA) (h8 : X ≠ CY) (h9 : X ≠ CR) (h10 : X ≠ CM) (h11 : X ≠ EC) :
(packOne Ei X).cost M s ≤ 200000 * (L.length + 1) * (Q + 3) +
30000 * (b * L.length + Q + 4) := by sorry