Repository navigation
Expand file tree
/
Copy pathLift.lean
More file actions
274 lines (227 loc) · 11.5 KB
/
Copy pathLift.lean
File metadata and controls
274 lines (227 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
module
public import Probability.StatisticalDistance
public import Mathlib.Data.Finsupp.Order
public import Mathlib.Algebra.Order.Group.PosPart
/-!
# Positive parts, normalization and overlaps
Relates signed, nonnegative and probability distributions.
## Main definitions
* `X⁺`, `X⁻`: the positive and negative parts of a distribution (the lattice
parts of `A →₀ ℝ`)
* `normalize X`: `|X|⁻¹ • X`, of weight `1` when `|X| ≠ 0`
* `normalizeOr X hX fallback`: for `X ≥ 0`, `normalize X` at nonzero weight and the explicit
probability law `fallback` at weight zero
* `X ⊓ Y`: the pointwise minimum of two distributions
## Main results
* `nonNeg_iff_zero_le`, `posPart_apply`, `negPart_apply`, `nonNeg_posPart`
* `statDist_eq_weight_posPart`: `δ(X, Y) = |(X − Y)⁺|`
* `statDist_eq_weight_sub_weight_inf`: `δ(X, Y) = |X| − |X ⊓ Y|`, the overlap formula of
[1, Definition 3, p. 10]
* `isProbDist_normalize`: `normalize X` is a probability law for `X ≥ 0` with `|X| ≠ 0`
* `normalizeOr_val_of_weight_ne_zero`, `mem_support_normalizeOr_iff`: at positive weight,
normalization rescales the masses and preserves exactly their support
* `weight_smul_normalizeOr`: `|X| • normalizeOr X hX fallback = X`, including at weight zero,
where nonnegativity forces `X = 0`
* `mass_finset_sum`: `(∑ i ∈ s, Xᵢ)(E) = ∑ i ∈ s, Xᵢ(E)` for signed laws; with `mass_smul`,
this computes event probabilities in mixtures from their component masses.
## References
1. D. Lanzenberger and U. Maurer. Coupling of Random Systems. In *Theory of Cryptography
(TCC 2020)*, Springer, 2020. Cryptology ePrint Archive, Paper 2020/1187.
-/
@[expose] public section
noncomputable section
open scoped BigOperators
namespace Probability
/-! ## Generic lattice-ordered-group facts -/
/-- `a⁺ * a⁻ = 0`: at most one of the two parts of a real number is nonzero.
This is the multiplicative face of `posPart_inf_negPart_eq_zero`. -/
lemma posPart_mul_negPart (a : ℝ) : a⁺ * a⁻ = 0 := by
rcases le_total a 0 with h | h
· rw [posPart_eq_zero.mpr h, zero_mul]
· rw [negPart_eq_zero.mpr h, mul_zero]
/-- `a - a ⊓ b = (a - b)⁺` in a lattice-ordered additive group: the amount by
which `a` exceeds `b` is exactly what the meet discards. -/
lemma sub_inf_eq_posPart_sub {α : Type*} [Lattice α] [AddCommGroup α]
[AddLeftMono α] (a b : α) : a - a ⊓ b = (a - b)⁺ := by
rw [posPart_def, sub_eq_add_neg, neg_inf, add_sup, add_neg_cancel,
← sub_eq_add_neg, sup_comm]
/-- `a ⊓ b + (a - b)⁺ = a`: the meet plus the one-sided excess rebuilds `a`.
This is the identity behind the diagonal of an optimal coupling, where the
meet is the shared mass and the excess is what must be transported. -/
lemma inf_add_posPart_sub {α : Type*} [Lattice α] [AddCommGroup α]
[AddLeftMono α] (a b : α) : a ⊓ b + (a - b)⁺ = a := by
rw [← sub_inf_eq_posPart_sub, add_sub_cancel]
namespace Distribution
variable {A : Type*}
/-! ## The `NonNeg` predicate is the `Finsupp` order -/
/-- `Distribution.NonNeg` is the `Finsupp` order relation `0 ≤ X`. Every mathlib fact
about the ordered group `A →₀ ℝ` reaches a `NonNeg` hypothesis through this. -/
lemma nonNeg_iff_zero_le {X : Distribution A} : X.NonNeg ↔ 0 ≤ X := by
simp [NonNeg, Finsupp.le_def]
/-! ## Positive and negative parts -/
/-- Pointwise formula for the positive part: `X⁺(a) = max(X(a), 0)`. -/
@[simp]
lemma posPart_apply (X : Distribution A) (a : A) : X⁺ a = max (X a) 0 := by
simp [posPart_def, Finsupp.sup_apply]
/-- Pointwise formula for the negative part: `X⁻(a) = max(-X(a), 0)`. -/
@[simp]
lemma negPart_apply (X : Distribution A) (a : A) : X⁻ a = max (-X a) 0 := by
simp [negPart_def, Finsupp.sup_apply]
/-- The positive part is an honest (nonnegative) distribution: this is the
lift itself — a signed `Distribution` produces a `NonNeg` one. -/
lemma nonNeg_posPart (X : Distribution A) : (X⁺).NonNeg := fun a => by
rw [posPart_apply]; exact le_max_right _ _
/-- The two parts never charge the same point: `X⁺(a)·X⁻(a) = 0`. -/
lemma posPart_mul_negPart_apply (X : Distribution A) (a : A) : X⁺ a * X⁻ a = 0 := by
simpa using posPart_mul_negPart (X a)
/-! ### The split and `statDist` -/
/-- **`statDist` is the weight of a positive part**: `δ(X, Y) = |(X - Y)⁺|`.
No layer hypothesis and no `Fintype` assumption are required. -/
lemma statDist_eq_weight_posPart (X Y : Distribution A) :
statDist X Y = ((X - Y)⁺).weight := by
classical
have hfun : ∀ a : A, ((X - Y)⁺) a = max (X a - Y a) 0 := fun a => by
rw [posPart_apply, Finsupp.sub_apply]
unfold statDist weight Finsupp.sum
rw [Finset.sum_congr rfl fun a _ => hfun a]
refine (Finset.sum_subset (fun a ha => ?_) (fun a _ ha => ?_)).symm
· rw [Finsupp.mem_support_iff] at ha ⊢
intro h
rw [Finsupp.sub_apply] at h
rw [hfun a, h, max_self] at ha
exact ha rfl
· rw [Finsupp.notMem_support_iff, hfun a] at ha
exact ha
/-- A nonnegative distribution of zero total weight is the zero distribution. -/
lemma eq_zero_of_nonNeg_of_weight_eq_zero {X : Distribution A} (hX : X.NonNeg)
(hw : X.weight = 0) : X = 0 := by
refine Finsupp.ext fun a => ?_
rw [Finsupp.coe_zero, Pi.zero_apply]
by_contra ha
have hle : X a ≤ X.weight := by
unfold weight Finsupp.sum
exact Finset.single_le_sum (fun a' _ => hX a')
(Finsupp.mem_support_iff.mpr ha)
rw [hw] at hle
exact ha (le_antisymm hle (hX a))
/-! ## Normalization -/
/-- Event mass is homogeneous: `(c · X)(P) = c · X(P)`. Signed layer. -/
lemma mass_smul (c : ℝ) (X : Distribution A) (P : A → Prop) :
(c • X).mass P = c * X.mass P := by
classical
unfold mass
rw [Finsupp.sum_smul_index fun _ => by simp]
unfold Finsupp.sum
rw [Finset.mul_sum]
exact Finset.sum_congr rfl fun a _ => by
by_cases h : P a <;> simp [h]
/-- **Event mass of a finite sum**: for signed laws `Xᵢ` and an event `E`,
`(∑ i ∈ s, Xᵢ)(E) = ∑ i ∈ s, Xᵢ(E)`. Neither nonnegativity nor normalization is needed.
With `mass_smul`, it gives mixture event masses `(∑ₖ P(k) • Xₖ)(E) = ∑ₖ P(k) · Xₖ(E)`. -/
lemma mass_finset_sum {I X : Type*} (s : Finset I) (laws : I → Distribution X)
(event : X → Prop) :
(∑ i ∈ s, laws i).mass event = ∑ i ∈ s, (laws i).mass event := by
classical
induction s using Finset.induction with
-- The empty family assigns zero mass to the event.
| empty => simp only [Finset.sum_empty, mass, Finsupp.sum_zero_index]
-- Adding one law adds its event mass; the remaining family satisfies the identity by induction.
| insert i s hi ih => rw [Finset.sum_insert hi, mass_add, ih, Finset.sum_insert hi]
/-- Normalization of a distribution: `X̂ = |X|⁻¹ · X`. A probability
distribution as soon as `X` is nonnegative of nonzero weight
(`isProbDist_normalize`); the second of the two lifts. -/
def normalize (X : Distribution A) : Distribution A := X.weight⁻¹ • X
/-- Pointwise value of the normalization. -/
@[simp]
lemma normalize_apply (X : Distribution A) (a : A) :
X.normalize a = X.weight⁻¹ * X a := by
simp [normalize]
/-- Dividing a nonnegative law of nonzero weight by its weight gives a probability law:
`|X|⁻¹ · X(a) ≥ 0` and `|X|⁻¹ • X` has weight `|X|⁻¹ · |X| = 1`. -/
lemma isProbDist_normalize
-- `hX`: `X ≥ 0` pointwise; `hw`: `|X| ≠ 0`, so `|X|⁻¹ · |X| = 1`.
{X : Distribution A} (hX : X.NonNeg) (hw : X.weight ≠ 0) :
X.normalize.isProbDist := by
refine ⟨fun a => ?_, ?_⟩
· rw [normalize_apply]
exact mul_nonneg (inv_nonneg.mpr hX.weight_nonneg) (hX a)
· rw [normalize, weight_smul, inv_mul_cancel₀ hw]
open Classical in
/-- `normalizeOr X hX fallback = normalize X` when `|X| ≠ 0`, and exactly `fallback` when
`|X| = 0`. It is a probability law for every nonnegative `X`. `weight_smul_normalizeOr`
rescales by `|X|`, so at weight zero `fallback` is multiplied by `0`. -/
def normalizeOr
-- `X` is a finitely supported mass function on `A`; `hX` makes its masses nonnegative.
(X : Distribution A) (hX : X.NonNeg)
-- `fallback`: the caller's probability law, returned when `|X| = 0`.
(fallback : ProbDist A) : ProbDist A :=
if hw : X.weight = 0 then fallback else ⟨X.normalize, isProbDist_normalize hX hw⟩
/-- Scaling the normalized law by the original weight recovers every mass:
`|X| • normalizeOr X hX fallback = X`, for every `fallback`. At `|X| = 0` both sides vanish:
the left is `0 • fallback`, and a nonnegative `X` of weight zero is `0`. -/
lemma weight_smul_normalizeOr
-- `X ≥ 0` by `hX`; `fallback` is any probability law on `A`.
(X : Distribution A) (hX : X.NonNeg) (fallback : ProbDist A) :
X.weight • (X.normalizeOr hX fallback).1 = X := by
classical
unfold normalizeOr
split_ifs with hw
· -- A nonnegative law of weight zero vanishes at every point.
rw [hw, zero_smul, eq_zero_of_nonNeg_of_weight_eq_zero hX hw]
· -- At positive weight, `|X| · |X|⁻¹ · X = X`.
change X.weight • (X.weight⁻¹ • X) = X
rw [smul_smul, mul_inv_cancel₀ hw, one_smul]
/-- At nonzero weight, `normalizeOr` is scalar normalization. -/
lemma normalizeOr_val_of_weight_ne_zero
-- `hμ` makes the masses of `μ` nonnegative; `hw` excludes the fallback branch.
(μ : Distribution A) (hμ : μ.NonNeg) (fallback : ProbDist A) (hw : μ.weight ≠ 0) :
(μ.normalizeOr hμ fallback).1 = μ.weight⁻¹ • μ := by
classical
simp only [normalizeOr, dite_eq_right hw, normalize]
/-- Positive rescaling preserves exactly the atoms in the support. -/
lemma mem_support_normalizeOr_iff
-- `μ` is nonnegative by `hμ`; `hw` excludes zero weight, independently of `fallback`.
(μ : Distribution A) (hμ : μ.NonNeg) (fallback : ProbDist A) (hw : μ.weight ≠ 0)
-- `a` is an atom whose mass normalization preserves or excludes.
(a : A) : a ∈ (μ.normalizeOr hμ fallback).1.support ↔ a ∈ μ.support := by
rw [normalizeOr_val_of_weight_ne_zero μ hμ fallback hw]
simp only [Finsupp.mem_support_iff, Finsupp.smul_apply, smul_eq_mul,
mul_ne_zero_iff]
exact and_iff_right (inv_ne_zero hw)
/-- A nonnegative law with a nonzero atom has nonzero total weight. -/
lemma weight_ne_zero_of_apply_ne_zero
-- `ha` witnesses a nonzero mass of the nonnegative law `μ`.
(μ : Distribution A) (hμ : μ.NonNeg) {a : A} (ha : μ a ≠ 0) : μ.weight ≠ 0 := by
intro hw
have hz := eq_zero_of_nonNeg_of_weight_eq_zero hμ hw
exact ha (congrArg (fun ν : Distribution A => ν a) hz)
/-! ## Overlaps -/
/-- Pointwise formula for the meet: `(X ⊓ Y)(a) = min(X(a), Y(a))`. -/
@[simp]
lemma inf_apply (X Y : Distribution A) (a : A) : (X ⊓ Y) a = min (X a) (Y a) := by
rw [Finsupp.inf_apply]
/-- A point mass with nonnegative weight is honest. -/
lemma single_nonNeg {c : ℝ} (hc : 0 ≤ c) (a : A) :
NonNeg (Finsupp.single a c : Distribution A) := by
classical
intro a'
rw [Finsupp.single_apply]
split
· exact hc
· exact le_rfl
/-- Weight is subtractive. -/
lemma weight_sub (X Y : Distribution A) :
(X - Y).weight = X.weight - Y.weight := by
have h := weight_add (X - Y) Y
rw [sub_add_cancel] at h
linarith
/-- The overlap formula [1, Definition 3, p. 10]: “δ(X, Y) = |X| − ∑ₐ min(X(a), Y(a))”.
Here `X ⊓ Y` is the pointwise shared mass. The identity also holds for signed laws. -/
theorem statDist_eq_weight_sub_weight_inf (X Y : Distribution A) :
statDist X Y = X.weight - (X ⊓ Y).weight := by
have hsplit : (X ⊓ Y) + (X - Y)⁺ = X := inf_add_posPart_sub X Y
have hw := congrArg weight hsplit
rw [weight_add, ← statDist_eq_weight_posPart] at hw
linarith
end Distribution
end Probability