Skip to content

Commit 2718043

Browse files
committed
simplification
1 parent 3f652ea commit 2718043

1 file changed

Lines changed: 7 additions & 33 deletions

File tree

Probability/Probability/Prelude.lean

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,47 +79,21 @@ theorem prod_eq_zero_of_nneg_dp_zero (hx : 0 ≤ x) (hy : 0 ≤ y) : x ⬝ᵥ y
7979
simp_all [dotProduct]
8080
exact (Fintype.sum_eq_zero_iff_of_nonneg this).mp h
8181

82+
theorem abs_pos_hom {a b : ℚ} (h : 0 ≤ a) : |a * b| = a * |b| := by
83+
rw [abs_mul, abs_of_nonneg h]
8284

83-
theorem abs_dotProd_le_dotProd_abs(p x : Fin n → ℚ) (hp : ∀ i, 0 ≤ p i) :
84-
|p ⬝ᵥ x| ≤ p ⬝ᵥ fun i => |x i| := by
85-
classical
86-
unfold dotProduct
87-
-- Step 1: triangle inequality
88-
have h1 :
89-
|∑ i : Fin n, p i * x i|
90-
≤ ∑ i : Fin n, |p i * x i| := by
91-
simpa using
92-
Finset.abs_sum_le_sum_abs
93-
(s := Finset.univ)
94-
(f := fun i : Fin n => p i * x i)
95-
96-
-- Step 2: simplify absolute value of product
97-
have h2 :
98-
∑ i : Fin n, |p i * x i|
99-
= ∑ i : Fin n, p i * |x i| := by
100-
refine Finset.sum_congr rfl ?_
101-
intro i _
102-
have hpi := hp i
103-
have hpos : |p i| = p i := abs_of_nonneg hpi
104-
calc
105-
|p i * x i|
106-
= |p i| * |x i| := by simp [abs_mul]
107-
_ = p i * |x i| := by simp [hpos]
108-
109-
-- Step 3: combine
85+
theorem abs_dotProd_le_dotProd_abs(p x : Fin n → ℚ) (hp : ∀ i, 0 ≤ p i) : |p ⬝ᵥ x| ≤ p ⬝ᵥ fun i => |x i| := by
11086
calc
111-
|∑ i : Fin n, p i * x i| ≤ ∑ i, |p i * x i| := h1
112-
_ = ∑ i, p i * |x i| := h2
87+
|∑ i : Fin n, p i * x i| ≤ ∑ i, |p i * x i| := Finset.abs_sum_le_sum_abs (fun i ↦ p i * x i) Finset.univ
88+
_ = ∑ i, p i * |x i| := Finset.sum_congr rfl (fun i _ => abs_pos_hom (hp i))
11389
_ = p ⬝ᵥ fun i => |x i| := rfl
11490

11591
theorem jensen_abs_uniform (x : Fin n → ℚ) (hn : 0 < n) :
116-
|(fun _ : Fin n => (1 : ℚ) / n) ⬝ᵥ x|
117-
≤ (fun _ : Fin n => (1 : ℚ) / n) ⬝ᵥ fun i => |x i| := by
118-
classical
92+
|(fun _ : Fin n => (1 : ℚ) / n) ⬝ᵥ x| ≤ (fun _ : Fin n => (1 : ℚ) / n) ⬝ᵥ fun i => |x i| := by
11993
have hpos : 0 < (n : ℚ) := by exact_mod_cast hn
12094
have hnonneg : 0 ≤ (1 : ℚ) / n := by
12195
have := inv_pos.mpr hpos
122-
simpa [one_div] using (le_of_lt this)
96+
simp
12397
have hp : ∀ i : Fin n, 0 ≤ (1 : ℚ) / n := fun _ => hnonneg
12498
simpa using
12599
abs_dotProd_le_dotProd_abs

0 commit comments

Comments
 (0)