Stack-machine split of an integer item by a ruler 2^m (quotient and remainder)
ProvedNLogN.Runs.splitRLet be pairwise distinct stacks of a state . Assume stack is followed by and stack is followed by , where and the tops of do not start with a bit symbol. Then splitR q i j k t1 t2 runs from to the state where
with cost at most . Here is with the sign of , so this is the signed (truncating) division of by ; the ruler on is kept.
Splitting is used to cut inputs into -bit pieces, to reduce modulo (via ), and to extract carry digits; again the cost depends only on .
Formalization Note. Machine states are St S records: stacks stk : Fin S → List Sym over the 16-letter alphabet Sym = Fin 16 (head = top), input position ip and output out; σ.set i L replaces stack i. An integer item is stored as (Item.int z).enc: a sign header followed by the minimal binary magnitude, least significant bit nearest the header; bitOf detects bit symbols, and the hypotheses bitOf (…).head? = none say that the following stack content does not start with a bit (so item boundaries are recognisable). Runs I prog p σ σ' c means p runs from σ to exactly σ' with some cost ; the procedures prog and input I are arbitrary.
-- Schönhage–Strassen multitape-TM development (NLogN), generated by skeleton subtraction.
import Definitions.Def_IntMul_SS_Defs2
set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000
open NLogN
variable {S P : ℕ} {I : List Sym} {prog : Fin P → Stmt S P}
theorem NLogN.Runs.splitR {q i j k t1 t2 : Fin S} (hqi : q ≠ i) (hqj : q ≠ j) (hqk : q ≠ k)
(hqt1 : q ≠ t1) (hqt2 : q ≠ t2) (hij : i ≠ j) (hik : i ≠ k) (hit1 : i ≠ t1) (hit2 : i ≠ t2)
(hjk : j ≠ k) (hjt1 : j ≠ t1) (hjt2 : j ≠ t2) (hkt1 : k ≠ t1) (hkt2 : k ≠ t2)
(ht12 : t1 ≠ t2) (σ : St S) (z : ℤ) (m : ℕ) (Ri Rj : List Sym)
(hi : σ.stk i = (Item.int z).enc ++ Ri) (hj : σ.stk j = (Item.int ((2 : ℤ) ^ m)).enc ++ Rj)
(hRi : bitOf Ri.head? = none) (hk : bitOf (σ.stk k).head? = none)
(ht1 : bitOf (σ.stk t1).head? = none) (ht2 : bitOf (σ.stk t2).head? = none) :
NLogN.Runs I prog (NLogN.splitR q i j k t1 t2 : Stmt S P) σ
((σ.set i ((Item.int (sg z (z.natAbs / 2 ^ m))).enc ++ Ri)).set k
((Item.int (sg z (z.natAbs % 2 ^ m))).enc ++ σ.stk k)) (splitCost m + 17) := by sorry