Exact block routing and aggregate work for 3SUM when one operand lies in a short arithmetic progression
ProvedThreeSumFuture.one_lattice_operand_target_blocksSuppose the first list consists of arbitrary values in an arithmetic progression, with positive integers and . The second list and the target list may contain arbitrary signed integers, repetitions and empty lists. Write each integer uniquely as with and , and let its block be . Use the unshifted values of and subtract from each target.
The equality holds precisely when the residues agree and either the two blocks coincide with , or the target is in the next block with .
For each occupied block , let be its multiplicity, the number of targets in , and the number in its successor. For every real ,
This bounds the aggregate cost of choosing pair enumeration or a dense convolution separately at each matched pair of blocks. The stride, the origin, and the magnitudes of and do not enter this bound.
import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Algebra.BigOperators.Field import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Real.Basic import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity import Mathlib.Tactic.Ring open scoped BigOperators
theorem ThreeSumFuture.one_lattice_operand_target_blocks {nx ny nz : ℕ} (a d W : ℤ) (hd : 0<d) (hw : 0<W)
(x : Fin nx → ℤ) (y : Fin ny → ℤ) (z : Fin nz → ℤ)
(hx : ∀ i, 0≤x i ∧ x i<W) :
let key := fun v : ℤ => (v%d, (v/d)/W)
let lo := fun v : ℤ => (v/d)%W
let down := fun b : ℤ × ℤ => (b.1,b.2-1)
let fy := fun j => key (y j)
let fz := fun k => key (z k-a)
let byCount := fun b => ((Finset.univ.filter (fun j => fy j=b)).card : ℝ)
let bzCount := fun b => ((Finset.univ.filter (fun k => fz k=b)).card : ℝ)
let prevCount := fun b => ((Finset.univ.filter (fun k => down (fz k)=b)).card : ℝ)
(∀ i j k, a+d*x i+y j=z k ↔
(fz k=fy j ∧ lo (z k-a)=lo (y j)+x i) ∨
(down (fz k)=fy j ∧ lo (z k-a)=lo (y j)+x i-W)) ∧
∀ (s : ℝ), 0≤s →
∑ b ∈ Finset.univ.image fy, (min (byCount b*bzCount b) (s^2) +
min (byCount b*prevCount b) (s^2)) ≤ s*(ny+nz) := by sorry