Fixed-point rounding and scaling (Harvey–van der Hoeven §2.2)
DefinitionIntMul_HvdH_FixedPointinteger-multiplication
Fixed-point rounding used throughout the integer multiplication algorithm of Harvey and van der Hoeven.
- rounds towards zero: for and for .
- acts on real and imaginary parts: .
- For a precision , , so maps into .
scaleFP p c ũis the scaling procedure of Lemma 2.2: set ; if return , otherwise return with .
Definition code
import Mathlib
/-! Fixed-point rounding of Harvey–van der Hoeven, §2.2. -/
namespace IntMul.HvdH
/-- Round towards zero, `ℝ → ℤ`: `⌊x⌋` for `x ≥ 0` and `⌈x⌉` for `x < 0`. -/
noncomputable def rho0 (x : ℝ) : ℤ := if 0 ≤ x then ⌊x⌋ else ⌈x⌉
/-- Componentwise round towards zero on `ℂ`, landing in `ℤ[i]`. -/
noncomputable def rho0C (u : ℂ) : ℂ := ((rho0 u.re : ℤ) : ℂ) + ((rho0 u.im : ℤ) : ℂ) * Complex.I
/-- Round to precision `p`: `ρ(u) = 2^{-p} ρ₀(2^p u)`. -/
noncomputable def rho (p : ℕ) (u : ℂ) : ℂ := ((2 : ℂ) ^ p)⁻¹ * rho0C ((2 : ℂ) ^ p * u)
/-- The scaling step of Lemma 2.2: from an approximation `ũ` of `u`, produce an approximation of
`c u` that stays in the unit disc (renormalising by `⌈2^p |c ũ|⌉ / 2^p` when `c ũ` leaves it). -/
noncomputable def scaleFP (p c : ℕ) (ũ : ℂ) : ℂ :=
if ‖(c : ℂ) * ũ‖ ≤ 1 then (c : ℂ) * ũ
else rho p ((2 : ℂ) ^ p * ((c : ℂ) * ũ) / ((⌈(2 : ℝ) ^ p * ‖(c : ℂ) * ũ‖⌉ : ℤ) : ℂ))
end IntMul.HvdH
Source
Harvey, van der Hoeven, Integer multiplication in time O(n log n), Annals of Math. 193 (2021), https://hal.science/hal-02070778, Section 2.2 (definition of rho) and proof of Lemma 2.2
Human review
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.