Offline · exact source
Exact Lean source

Rounding

formalization/Cloning/Rounding.lean

Source hash: 5a42816b172be4cdc4b1e8d0838eb42e53deda9c156e73085af7705a0e7e3274

Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.

The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.

Declarations in this module
1import Mathlib.Algebra.Order.Floor.Ring
2import Mathlib.Algebra.Order.BigOperators.Group.Finset
3import Mathlib.Analysis.Normed.Group.Basic
4import Mathlib.Analysis.Normed.Group.Real
5import Mathlib.Analysis.Normed.Group.Continuity
6import Mathlib.Data.Real.Archimedean
7import Mathlib.Topology.Algebra.Monoid
8import Mathlib.Tactic.GCongr
9import Mathlib.Tactic.FieldSimp
10import Mathlib.Tactic.Linarith
11import Mathlib.Tactic.NormNum
12import Mathlib.Tactic.Ring
13 
14/-!
15# The elementary part of randomized Young-label dilation
16 
17This file checks the deterministic rounding estimates and finite-kernel
18estimates used in Appendix `app:young-rounding` of `cloning.tex`.  Its last
19section checks the three-error argument for dilation followed by averaging.
20The analytic hypotheses in that section are explicit: neither the Young
21local limit theorem nor the cellwise Poincaré estimate is asserted here.
22-/
23 
24open scoped BigOperators
25open Filter
26 
27namespace Cloning.Rounding
28 
29noncomputable def nearest (x : ℝ) : ℤ := ⌊x + 1 / 2⌋
30 
31/-- The half-open cells are exactly the fibers of the rounding map. -/
32theorem nearest_eq_iff (x : ℝ) (z : ℤ) :
33    nearest x = z ↔ (z : ℝ) - 1 / 2 ≤ x ∧ x < (z : ℝ) + 1 / 2 := by
34  rw [nearest, Int.floor_eq_iff]
35  constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor <;> linarith
36 
37theorem nearest_error (x : ℝ) : |(nearest x : ℝ) - x| ≤ 1 / 2 := by
38  have h := (nearest_eq_iff x (nearest x)).mp rfl
39  rw [abs_le]
40  constructor <;> linarith
41 
42/-- The first `d-1` coordinate errors in randomized rounding. -/
43theorem dither_error (γ x y : ℝ) (hγ : 0 ≤ γ)
44    (hy : -(1 / 2 : ℝ) ≤ y ∧ y < 1 / 2) :
45    |(nearest (γ * (x + y)) : ℝ) - γ * x| ≤ (γ + 1) / 2 := by
46  have hround := nearest_error (γ * (x + y))
47  have habs : |y| ≤ (1 / 2 : ℝ) := abs_le.mpr ⟨hy.1, hy.2.le⟩
48  calc
49    |(nearest (γ * (x + y)) : ℝ) - γ * x| =
50        |((nearest (γ * (x + y)) : ℝ) - γ * (x + y)) + γ * y| := by congr 1; ring
51    _ ≤ |(nearest (γ * (x + y)) : ℝ) - γ * (x + y)| + |γ * y| := abs_add_le _ _
52    _ ≤ 1 / 2 + γ * (1 / 2) := by rw [abs_mul, abs_of_nonneg hγ]; gcongr
53    _ = (γ + 1) / 2 := by ring
54 
55/-- Completing the last coordinate preserves the required integer mass. -/
56def completeLast {ι : Type*} [Fintype ι] (m : ℤ) (head : ι → ℤ) : ℤ :=
57  m - ∑ i, head i
58 
59theorem completed_mass {ι : Type*} [Fintype ι] (m : ℤ) (head : ι → ℤ) :
60    (∑ i, head i) + completeLast m head = m := by
61  simp [completeLast]
62 
63/-- The last error is the negative sum of the head errors. -/
64theorem completeLast_error {ι : Type*} [Fintype ι]
65    (m : ℤ) (head : ι → ℤ) (μ : ι → ℝ) (μlast γ : ℝ)
66    (hm : (m : ℝ) = γ * ((∑ i, μ i) + μlast)) :
67    (completeLast m head : ℝ) - γ * μlast =
68      -(∑ i, ((head i : ℝ) - γ * μ i)) := by
69  simp only [completeLast, Int.cast_sub, Int.cast_sum, Finset.sum_sub_distrib,
70    ← Finset.mul_sum]
71  rw [hm]
72  ring
73 
74theorem completeLast_error_bound {ι : Type*} [Fintype ι]
75    (m : ℤ) (head : ι → ℤ) (μ : ι → ℝ) (μlast γ c : ℝ)
76    (hm : (m : ℝ) = γ * ((∑ i, μ i) + μlast))
77    (hhead : ∀ i, |(head i : ℝ) - γ * μ i| ≤ c) :
78    |(completeLast m head : ℝ) - γ * μlast| ≤ Fintype.card ι * c := by
79  rw [completeLast_error m head μ μlast γ hm, abs_neg]
80  calc
81    |∑ i, ((head i : ℝ) - γ * μ i)| ≤ ∑ i, |(head i : ℝ) - γ * μ i| :=
82      Finset.abs_sum_le_sum_abs _ _
83    _ ≤ ∑ _i : ι, c := Finset.sum_le_sum fun i _ ↦ hhead i
84    _ = Fintype.card ι * c := by simp
85 
86/-- The manuscript's `(d-1)(γ+1)/2` bound for the completed coordinate. -/
87theorem rounded_last_error {ι : Type*} [Fintype ι]
88    (m : ℤ) (μ y : ι → ℝ) (μlast γ : ℝ) (hγ : 0 ≤ γ)
89    (hm : (m : ℝ) = γ * ((∑ i, μ i) + μlast))
90    (hy : ∀ i, -(1 / 2 : ℝ) ≤ y i ∧ y i < 1 / 2) :
91    |(completeLast m (fun i ↦ nearest (γ * (μ i + y i))) : ℝ) - γ * μlast| ≤
92      Fintype.card ι * ((γ + 1) / 2) := by
93  apply completeLast_error_bound m _ μ μlast γ _ hm
94  exact fun i ↦ dither_error γ (μ i) (y i) hγ (hy i)
95 
96/-- A bounded unnormalized rounding error gives the claimed spectral error. -/
97theorem normalized_rounding_error (μ ν n m γ p c : ℝ)
98    (hn : n ≠ 0) (hm : 0 < m) (hscale : m = γ * n)
99    (herr : |ν - γ * μ| ≤ c) :
100    |ν / m - p| ≤ |μ / n - p| + c / m := by
101  have hid : ν / m - p = (μ / n - p) + (ν - γ * μ) / m := by
102    field_simp [hn, hm.ne']
103    rw [hscale]
104    ring
105  rw [hid]
106  calc
107    |(μ / n - p) + (ν - γ * μ) / m| ≤
108        |μ / n - p| + |(ν - γ * μ) / m| := abs_add_le _ _
109    _ ≤ |μ / n - p| + c / m := by
110      rw [abs_div, abs_of_pos hm]
111      exact add_le_add le_rfl (div_le_div_of_nonneg_right herr hm.le)
112 
113section FiniteKernels
114 
115variable {ι κ : Type*} [Fintype ι] [Fintype κ]
116 
117/-- Nonnegative row-stochastic kernels, in real coordinates. -/
118structure StochasticKernel (ι κ : Type*) [Fintype κ] where
119  value : ι → κ → ℝ
120  nonneg : ∀ i j, 0 ≤ value i j
121  row_sum : ∀ i, ∑ j, value i j = 1
122 
123/-- The intersection-volume formula defines a stochastic kernel once the
124target-cell overlaps partition the source-cell volume.  The geometric
125partition-of-volume identity is supplied explicitly as `hpartition`. -/
126noncomputable def kernelOfCellMasses (overlap : ι → κ → ℝ) (sourceVolume : ι → ℝ)
127    (hoverlap : ∀ i j, 0 ≤ overlap i j)
128    (hvolume : ∀ i, 0 < sourceVolume i)
129    (hpartition : ∀ i, ∑ j, overlap i j = sourceVolume i) :
130    StochasticKernel ι κ where
131  value i j := overlap i j / sourceVolume i
132  nonneg i j := div_nonneg (hoverlap i j) (hvolume i).le
133  row_sum i := by
134    simp only [div_eq_mul_inv, ← Finset.sum_mul, hpartition i]
135    exact mul_inv_cancel₀ (hvolume i).ne'
136 
137def transport (K : StochasticKernel ι κ) (p : ι → ℝ) (j : κ) : ℝ :=
138  ∑ i, p i * K.value i j
139 
140def l1Distance (p q : ι → ℝ) : ℝ := ∑ i, |p i - q i|
141 
142theorem transport_nonneg (K : StochasticKernel ι κ) (p : ι → ℝ)
143    (hp : ∀ i, 0 ≤ p i) (j : κ) : 0 ≤ transport K p j :=
144  Finset.sum_nonneg fun i _ ↦ mul_nonneg (hp i) (K.nonneg i j)
145 
146theorem transport_mass (K : StochasticKernel ι κ) (p : ι → ℝ) :
147    ∑ j, transport K p j = ∑ i, p i := by
148  simp only [transport]
149  rw [Finset.sum_comm]
150  simp only [← Finset.mul_sum, K.row_sum, mul_one]
151 
152/-- Averaging by a stochastic kernel contracts the discrete `L¹` distance. -/
153theorem transport_l1_contraction (K : StochasticKernel ι κ) (p q : ι → ℝ) :
154    l1Distance (transport K p) (transport K q) ≤ l1Distance p q := by
155  simp only [l1Distance, transport, ← Finset.sum_sub_distrib, ← sub_mul]
156  calc
157    (∑ j, |∑ i, (p i - q i) * K.value i j|) ≤
158        ∑ j, ∑ i, |(p i - q i) * K.value i j| :=
159      Finset.sum_le_sum fun j _ ↦ Finset.abs_sum_le_sum_abs _ _
160    _ = ∑ i, |p i - q i| := by
161      simp only [abs_mul, abs_of_nonneg (K.nonneg _ _)]
162      rw [Finset.sum_comm]
163      simp only [← Finset.mul_sum, K.row_sum, mul_one]
164 
165/-- A bound for replacing a transition kernel without changing the input law. -/
166theorem transport_kernel_error (K L : StochasticKernel ι κ) (p : ι → ℝ)
167    (hp : ∀ i, 0 ≤ p i) :
168    l1Distance (transport K p) (transport L p) ≤
169      ∑ i, p i * (∑ j, |K.value i j - L.value i j|) := by
170  simp only [l1Distance, transport, ← Finset.sum_sub_distrib, ← mul_sub]
171  calc
172    (∑ j, |∑ i, p i * (K.value i j - L.value i j)|) ≤
173        ∑ j, ∑ i, |p i * (K.value i j - L.value i j)| :=
174      Finset.sum_le_sum fun j _ ↦ Finset.abs_sum_le_sum_abs _ _
175    _ = ∑ i, p i * (∑ j, |K.value i j - L.value i j|) := by
176      simp only [abs_mul, abs_of_nonneg (hp _)]
177      rw [Finset.sum_comm]
178      simp only [Finset.mul_sum]
179 
180omit [Fintype ι] in
181theorem kernel_row_distance_le_two (K L : StochasticKernel ι κ) (i : ι) :
182    (∑ j, |K.value i j - L.value i j|) ≤ 2 := by
183  calc
184    (∑ j, |K.value i j - L.value i j|) ≤
185        ∑ j, (K.value i j + L.value i j) := by
186      apply Finset.sum_le_sum
187      intro j _
188      calc
189        |K.value i j - L.value i j| ≤ |K.value i j| + |L.value i j| := abs_sub _ _
190        _ = K.value i j + L.value i j := by
191          rw [abs_of_nonneg (K.nonneg i j), abs_of_nonneg (L.nonneg i j)]
192    _ = 2 := by rw [Finset.sum_add_distrib, K.row_sum, L.row_sum]; norm_num
193 
194/-- Fallback changes the output law by at most twice the atypical input mass. -/
195theorem fallback_l1_bound (K L : StochasticKernel ι κ) (p : ι → ℝ)
196    (hp : ∀ i, 0 ≤ p i) (good : ι → Prop) [DecidablePred good]
197    (hsame : ∀ i, good i → ∀ j, K.value i j = L.value i j) :
198    l1Distance (transport K p) (transport L p) ≤
199      2 * (∑ i, if good i then 0 else p i) := by
200  calc
201    l1Distance (transport K p) (transport L p) ≤
202        ∑ i, p i * (∑ j, |K.value i j - L.value i j|) :=
203      transport_kernel_error K L p hp
204    _ ≤ ∑ i, 2 * (if good i then 0 else p i) := by
205      apply Finset.sum_le_sum
206      intro i _
207      by_cases hi : good i
208      · simp [hi, hsame i hi]
209      · simp only [hi, ↓reduceIte]
210        calc
211          p i * (∑ j, |K.value i j - L.value i j|) ≤ p i * 2 :=
212            mul_le_mul_of_nonneg_left (kernel_row_distance_le_two K L i) (hp i)
213          _ = 2 * p i := mul_comm _ _
214    _ = 2 * (∑ i, if good i then 0 else p i) := (Finset.mul_sum _ _ _).symm
215 
216/-- Vanishing atypical mass makes the fallback asymptotically invisible in `L¹`. -/
217theorem fallback_l1_tendsto
218    (K L : ℕ → StochasticKernel ι κ) (p : ℕ → ι → ℝ)
219    (hp : ∀ n i, 0 ≤ p n i) (good : ℕ → ι → Prop)
220    [∀ n, DecidablePred (good n)]
221    (hsame : ∀ n i, good n i → ∀ j, (K n).value i j = (L n).value i j)
222    (hbad : Tendsto (fun n ↦ ∑ i, if good n i then 0 else p n i) atTop (nhds 0)) :
223    Tendsto (fun n ↦ l1Distance (transport (K n) (p n)) (transport (L n) (p n)))
224      atTop (nhds 0) := by
225  apply squeeze_zero
226    (fun n ↦ Finset.sum_nonneg fun i _ ↦ abs_nonneg _)
227    (fun n ↦ fallback_l1_bound (K n) (L n) (p n) (hp n) (good n) (hsame n))
228  simpa [two_mul] using hbad.add hbad
229 
230end FiniteKernels
231 
232section AnalyticReduction
233 
234variable {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F]
235 
236/-- The precise three-term inequality in the randomized dilation proof.
237`D` is dilation, `A` is cell averaging, `f` is the input density, `g` the
238input Gaussian, and `h` the limiting output Gaussian. -/
239theorem dilation_averaging_error (D : E → F) (A : F → F)
240    (hD : ∀ x y, ‖D x - D y‖ = ‖x - y‖)
241    (hA : ∀ x y, ‖A x - A y‖ ≤ ‖x - y‖) (f g : E) (h : F) :
242    ‖A (D f) - h‖ ≤ ‖f - g‖ + ‖A (D g) - D g‖ + ‖D g - h‖ := by
243  calc
244    ‖A (D f) - h‖ ≤ ‖A (D f) - A (D g)‖ + ‖A (D g) - h‖ :=
245      norm_sub_le_norm_sub_add_norm_sub _ _ _
246    _ ≤ ‖D f - D g‖ + (‖A (D g) - D g‖ + ‖D g - h‖) :=
247      add_le_add (hA _ _) (norm_sub_le_norm_sub_add_norm_sub _ _ _)
248    _ = ‖f - g‖ + ‖A (D g) - D g‖ + ‖D g - h‖ := by rw [hD]; ring
249 
250/-- The three analytic inputs suffice to establish the rounded density limit.
251This is a conditional reduction; in particular it does not claim to prove
252the manuscript's Young local limit or Gaussian cell approximation. -/
253theorem dilation_averaging_tendsto
254    (D : ℕ → E → F) (A : ℕ → F → F) (f : ℕ → E) (g : E) (h : F)
255    (hD : ∀ n x y, ‖D n x - D n y‖ = ‖x - y‖)
256    (hA : ∀ n x y, ‖A n x - A n y‖ ≤ ‖x - y‖)
257    (hlocal : Tendsto (fun n ↦ ‖f n - g‖) atTop (nhds 0))
258    (hcell : Tendsto (fun n ↦ ‖A n (D n g) - D n g‖) atTop (nhds 0))
259    (hscale : Tendsto (fun n ↦ ‖D n g - h‖) atTop (nhds 0)) :
260    Tendsto (fun n ↦ ‖A n (D n (f n)) - h‖) atTop (nhds 0) := by
261  apply squeeze_zero (fun n ↦ norm_nonneg _)
262    (fun n ↦ dilation_averaging_error (D n) (A n) (hD n) (hA n) (f n) g h)
263  simpa using (hlocal.add hcell).add hscale
264 
265/-- Uniform version of the same reduction.  The parameter set `S` can be
266the compact set of spectra in the manuscript.  Compactness enters through
267the three uniform error bounds, rather than being silently assumed here. -/
268theorem dilation_averaging_uniform {P : Type*} (S : Set P)
269    (D : ℕ → P → E → F) (A : ℕ → P → F → F)
270    (f : ℕ → P → E) (g : P → E) (h : P → F)
271    (u v w : ℕ → ℝ)
272    (hD : ∀ n p x y, ‖D n p x - D n p y‖ = ‖x - y‖)
273    (hA : ∀ n p x y, ‖A n p x - A n p y‖ ≤ ‖x - y‖)
274    (hlocal : ∀ n p, p ∈ S → ‖f n p - g p‖ ≤ u n)
275    (hcell : ∀ n p, p ∈ S → ‖A n p (D n p (g p)) - D n p (g p)‖ ≤ v n)
276    (hscale : ∀ n p, p ∈ S → ‖D n p (g p) - h p‖ ≤ w n)
277    (hu : Tendsto u atTop (nhds 0)) (hv : Tendsto v atTop (nhds 0))
278    (hw : Tendsto w atTop (nhds 0)) :
279    ∀ ε > 0, ∀ᶠ n in atTop,
280      ∀ p ∈ S, ‖A n p (D n p (f n p)) - h p‖ < ε := by
281  have hsum : Tendsto (fun n ↦ u n + v n + w n) atTop (nhds 0) := by
282    simpa using (hu.add hv).add hw
283  intro ε hε
284  refine (hsum.eventually (gt_mem_nhds hε)).mono ?_
285  intro n hn p hp
286  calc
287    ‖A n p (D n p (f n p)) - h p‖ ≤
288        ‖f n p - g p‖ + ‖A n p (D n p (g p)) - D n p (g p)‖ +
289          ‖D n p (g p) - h p‖ :=
290      dilation_averaging_error (D n p) (A n p) (hD n p) (hA n p) _ _ _
291    _ ≤ u n + v n + w n :=
292      add_le_add (add_le_add (hlocal n p hp) (hcell n p hp)) (hscale n p hp)
293    _ < ε := hn
294 
295end AnalyticReduction
296 
297end Cloning.Rounding