Gaussian resampling maps of Harvey–van der Hoeven
DefinitionIntMul_HvdH_ResamplingThis file defines the linear maps of §4.1–§4.2 of Harvey–van der Hoeven used in Gaussian resampling. For , a vector is indexed by , so means for every integer . Vectors carry the supremum norm , and linear maps carry the corresponding operator norm.
Let and .
- The DFT , .
- The resampling maps , for :
- The permutations on and on .
- The nearest integer , and .
- The row-deleting map , , and the diagonal map .
- , , and .
These maps relate a DFT of length to a DFT of length . They underlie the resampling identity (Theorem 4.2) and the norm estimates (Lemmas 4.5, 4.6) that make power-of-two transforms usable for prime-length ones.
Formalization Note Each sum over is written as a matrix acting on . The entry in row , column is the lattice sum over the residue class of , and it equals the source's sum for every . Row indices and are taken as their representatives in and respectively. The norm on vectors is Mathlib's supremum norm on ZMod n → ℂ.
import Mathlib
/-!
# Gaussian resampling maps of Harvey–van der Hoeven
D. Harvey, J. van der Hoeven, *Integer multiplication in time O(n log n)*,
Ann. of Math. 193 (2021), §2.2, §2.4, §4.1, §4.2.
Vectors in `ℂⁿ` are functions `ZMod n → ℂ`; this realizes the paper's convention that `u_j`
means `u_{j mod n}` for every integer `j`. Mathlib's norm on `ZMod n → ℂ` is the supremum norm
`‖u‖ = max_j |u_j|` of §2.2, and the norm of a continuous linear map is the operator norm
of §2.6. A sum `∑_{j ∈ ℤ} c_j u_j` is written as a matrix acting on `ℂ^s` by grouping the
indices `j` by their residue mod `s`.
-/
namespace IntMul.HvdH
open Complex Real
/-- The linear map `ℂ^s → ℂ^t` with matrix `A`. -/
noncomputable def toCLM {s t : ℕ} [NeZero s] [NeZero t] (A : Matrix (ZMod t) (ZMod s) ℂ) :
(ZMod s → ℂ) →L[ℂ] (ZMod t → ℂ) :=
LinearMap.toContinuousLinearMap (Matrix.toLin' A)
/-- The complex DFT `𝓕ₙ : ℂⁿ → ℂⁿ` (§2.4),
`(𝓕ₙ u)_j = (1/n) ∑_{k=0}^{n-1} e^{-2πijk/n} u_k`. -/
noncomputable def dft (n : ℕ) [NeZero n] : (ZMod n → ℂ) →L[ℂ] (ZMod n → ℂ) :=
toCLM (Matrix.of fun j k : ZMod n =>
(1 / (n : ℂ)) * exp (-2 * π * I * (j.val : ℂ) * (k.val : ℂ) / (n : ℂ)))
/-- Matrix of the map `u ↦ (∑_{j ∈ ℤ} g(k, j) · u_{j mod s})_{0 ≤ k < t}`: the entry in row `k`,
column `r` is `∑_{m ∈ ℤ} g(k, r + m s)`. -/
noncomputable def latticeMatrix (s t : ℕ) (g : ℕ → ℤ → ℝ) : Matrix (ZMod t) (ZMod s) ℂ :=
Matrix.of fun k r => ((∑' m : ℤ, g k.val ((r.val : ℤ) + m * s) : ℝ) : ℂ)
/-- The resampling map `𝓢 : ℂ^s → ℂ^t` (§4.1),
`(𝓢u)_k = α⁻¹ ∑_{j∈ℤ} e^{-π α^{-2} s² (k/t - j/s)²} u_j` for `0 ≤ k < t`. -/
noncomputable def resS (s t : ℕ) [NeZero s] [NeZero t] (α : ℝ) :
(ZMod s → ℂ) →L[ℂ] (ZMod t → ℂ) :=
toCLM (latticeMatrix s t fun k j =>
α⁻¹ * Real.exp (-π * α⁻¹ ^ 2 * (s : ℝ) ^ 2 * ((k : ℝ) / t - (j : ℝ) / s) ^ 2))
/-- The resampling map `𝓣 : ℂ^s → ℂ^t` (§4.1),
`(𝓣u)_k = ∑_{j∈ℤ} e^{-π α² t² (k/t - j/s)²} u_j` for `0 ≤ k < t`. -/
noncomputable def resT (s t : ℕ) [NeZero s] [NeZero t] (α : ℝ) :
(ZMod s → ℂ) →L[ℂ] (ZMod t → ℂ) :=
toCLM (latticeMatrix s t fun k j =>
Real.exp (-π * α ^ 2 * (t : ℝ) ^ 2 * ((k : ℝ) / t - (j : ℝ) / s) ^ 2))
/-- The permutation map `𝓟_s : ℂ^s → ℂ^s`, `(𝓟_s u)_j = u_{tj}` (§4.1). -/
noncomputable def permS (s t : ℕ) [NeZero s] : (ZMod s → ℂ) →L[ℂ] (ZMod s → ℂ) :=
LinearMap.toContinuousLinearMap (LinearMap.funLeft ℂ ℂ fun j : ZMod s => (t : ZMod s) * j)
/-- The permutation map `𝓟_t : ℂ^t → ℂ^t`, `(𝓟_t u)_k = u_{-sk}` (§4.1). -/
noncomputable def permT (s t : ℕ) [NeZero t] : (ZMod t → ℂ) →L[ℂ] (ZMod t → ℂ) :=
LinearMap.toContinuousLinearMap (LinearMap.funLeft ℂ ℂ fun k : ZMod t => -(s : ZMod t) * k)
/-- Nearest integer, rounding ties upward: `[x] = ⌊x + 1/2⌋` (§4). -/
noncomputable def nearest (x : ℝ) : ℤ := ⌊x + 1 / 2⌋
/-- `β_ℓ = tℓ/s - [tℓ/s]` (§4.2). -/
noncomputable def beta (s t : ℕ) (ℓ : ℤ) : ℝ :=
(t : ℝ) * ℓ / s - nearest ((t : ℝ) * ℓ / s)
/-- The row-deleting map `𝓒 : ℂ^t → ℂ^s`, `(𝓒u)_ℓ = u_{[tℓ/s]}` for `0 ≤ ℓ < s` (§4.2). -/
noncomputable def rowDel (s t : ℕ) [NeZero s] [NeZero t] : (ZMod t → ℂ) →L[ℂ] (ZMod s → ℂ) :=
toCLM (Matrix.of fun ℓ (k : ZMod t) =>
if k = ((nearest ((t : ℝ) * (ℓ.val : ℕ) / s) : ℤ) : ZMod t) then (1 : ℂ) else 0)
/-- The diagonal map `𝓓 : ℂ^s → ℂ^s`, `(𝓓u)_ℓ = d_ℓ u_ℓ` with `d_ℓ = e^{π α² β_ℓ²}` (§4.2). -/
noncomputable def diagD (s t : ℕ) [NeZero s] (α : ℝ) : (ZMod s → ℂ) →L[ℂ] (ZMod s → ℂ) :=
toCLM (Matrix.diagonal fun ℓ : ZMod s =>
((Real.exp (π * α ^ 2 * beta s t (ℓ.val : ℕ) ^ 2) : ℝ) : ℂ))
/-- `𝓝 = 𝓣′𝓓 = 𝓒𝓣𝓓 : ℂ^s → ℂ^s` (§4.2). -/
noncomputable def normN (s t : ℕ) [NeZero s] [NeZero t] (α : ℝ) :
(ZMod s → ℂ) →L[ℂ] (ZMod s → ℂ) :=
(rowDel s t).comp ((resT s t α).comp (diagD s t α))
/-- `𝓔 = 𝓝 - 𝓘` (§4.2). -/
noncomputable def errE (s t : ℕ) [NeZero s] [NeZero t] (α : ℝ) :
(ZMod s → ℂ) →L[ℂ] (ZMod s → ℂ) :=
normN s t α - ContinuousLinearMap.id ℂ _
/-- `θ = t/s - 1` (§4.2). -/
noncomputable def theta (s t : ℕ) : ℝ := (t : ℝ) / s - 1
end IntMul.HvdH
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Read-back: Def_IntMul_HvdH_Resampling.lean
All declarations live in the namespace IntMul.HvdH. Only Mathlib is imported. Throughout, is the real number , is the imaginary unit, is the real exponential unless it is applied to a complex argument.
Conventions used by every declaration
Index sets. For a natural number , the index set is (Mathlib's ZMod n). When this is the finite ring of residues mod ; when it is itself. A "vector in " is a function ; indices are residues, so for any integer means . For a residue with , denotes its canonical representative (Mathlib's ZMod.val). (For , val is the absolute value of the integer.) Whenever a formula below uses an index as a number, it is this canonical representative that is used, not an arbitrary lift.
Norms. On (with ) Mathlib's norm is the supremum norm
On continuous linear maps the norm is the operator norm with respect to these sup norms,
which for a matrix map equals the maximum over rows of the sum of absolute values of the row's entries. None of the declarations in this file mention a norm; this is only the structure the types carry.
Infinite sums. denotes Mathlib's unconditional sum over . For real-valued terms, it equals the usual sum when the series is absolutely summable, and it is defined to be when the series is not summable (no error is raised).
1. toCLM — the linear map of a matrix
Given natural numbers with and (both are required as hypotheses), and a complex matrix whose rows are indexed by and columns by , is the continuous -linear map given by matrix–vector multiplication:
(The linear map is promoted to a continuous linear map using finite-dimensionality; nothing else changes.)
2. dft — the discrete Fourier transform
For , is of the matrix with entries
so
Note the normalisation factor is (not ) and the exponent has a minus sign. Because only depends on mod , using the canonical representatives does not matter here.
3. latticeMatrix — periodised kernel matrix
Inputs: natural numbers (no non-zero hypothesis) and a real-valued function . Output: a complex matrix with rows indexed by and columns by , with entries
The first argument of is the canonical representative of the row index; the second runs over the integers congruent to mod . Edge cases:
- If for some the series over is not (absolutely) summable, that entry is .
- If then for all , so each series is a constant series over ; it is summable only if the constant is , hence every entry is .
- Consequently, applying of this matrix to gives ; this coincides with "" only when the per-residue series are summable.
4. resS — the Gaussian resampling map
For and a real parameter (no sign or non-zero hypothesis), is of with kernel
so the entry in row , column is
and . Divisions by and are real divisions by non-zero numbers. Edge cases:
- For the Gaussian series is summable, so the sum is a genuine sum.
- For , Mathlib's convention makes , so is the zero map.
- For the prefactor is negative while ; thus .
- is allowed.
5. resT — the Gaussian resampling map
For and real (no hypothesis), is of with kernel
i.e. entries
There is no prefactor. Edge cases:
- For the series is summable.
- For every term equals , the series over is not summable, so every entry is and is the zero map.
- depends on only through , so .
- Since shifting by is absorbed by re-indexing , the entry formula would give the same value for any integer lift of .
6. permS — the map
For and any natural number (no hypothesis on ), is precomposition with multiplication by in :
It is linear for every ; it is a permutation of coordinates exactly when multiplication by is a bijection of , i.e. when . No coprimality is assumed. If (e.g. or ), for all .
7. permT — the map
For and any natural number (no hypothesis on ), is
Again no coprimality is assumed; it is a coordinate permutation exactly when , and if it sends to the constant vector .
8. nearest — nearest integer
For real ,
Ties round up: , , . It satisfies .
9. beta
For natural numbers (no hypotheses) and an integer ,
computed in the reals as . Its value always lies in . Edge case: if , real division by zero returns , so for every .
10. rowDel — the row-deleting map
For , is of the matrix (rows , columns )
so
Each row has exactly one . The nearest-integer value lies in ; it can equal (when and ), in which case it is reduced to the index . No relation between and is assumed; if , distinct may pick the same coordinate.
11. diagD — the diagonal map
For , any natural , and real , is of the diagonal matrix
where is item 9 with the same evaluated at the canonical representative . So . The real numbers satisfy . If , is the identity. (The toCLM call carries the hypothesis that for both index sets, which holds.)
12. normN — the map
For and real ,
with from item 10, from item 5 and from item 11 (all with the same ). Explicitly, writing for the canonical representative of ,
Edge case: for , (item 5), hence .
13. errE — the map
For and real ,
where is the identity map of ; i.e. . For , .
14. theta
For natural numbers (no hypotheses),
Edge case: if , real division by zero gives , so . If , ; no sign of is assumed.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.