Skip to content

Commit 4c48eee

Browse files
committed
cleanup Johnson
1 parent 5248930 commit 4c48eee

5 files changed

Lines changed: 397 additions & 828 deletions

File tree

ArkLib/Data/CodingTheory/JohnsonBound.lean

Lines changed: 46 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22
Released under Apache 2.0 license as described in the file LICENSE.
33
Authors: Ilia Vlasov
44
-/
5-
import Mathlib.Algebra.Field.Rat
6-
import Mathlib.Analysis.Convex.Function
7-
import Mathlib.Data.Real.Sqrt
8-
import Mathlib.Data.Set.Pairwise.Basic
9-
import Mathlib.Algebra.BigOperators.Field
10-
import Mathlib.Analysis.Convex.Jensen
11-
import Mathlib.Algebra.Module.LinearMap.Defs
12-
13-
import ArkLib.Data.CodingTheory.Basic
14-
import ArkLib.Data.CodingTheory.JohnsonBound.Choose2
15-
import ArkLib.Data.CodingTheory.JohnsonBound.Expectations
165
import ArkLib.Data.CodingTheory.JohnsonBound.Lemmas
176

187
namespace JohnsonBound
198

209
variable {n : ℕ}
21-
variable {F : Type} [Fintype F] [DecidableEq F]
10+
{F : Type} [Fintype F] [DecidableEq F]
11+
{B : Finset (Fin n → F)} {v : Fin n → F}
2212

2313
def JohnsonDenominator (B : Finset (Fin n → F)) (v : Fin n → F) : ℚ :=
2414
let e := e B v
@@ -27,9 +17,9 @@ def JohnsonDenominator (B : Finset (Fin n → F)) (v : Fin n → F) : ℚ :=
2717
let frac := q / (q - 1)
2818
(1- frac * e/n) ^ 2 - (1 - frac * d/n)
2919

30-
lemma johnson_denominator_def {B : Finset (Fin n → F)} {v : Fin n → F} :
31-
JohnsonDenominator B v = ((1 - ((Fintype.card F : ℚ) / (Fintype.card F - 1)) * (e B v / n)) ^ 2
32-
- (1 - ((Fintype.card F : ℚ) / (Fintype.card F - 1)) * (d B/n))) := by
20+
lemma johnson_denominator_def :
21+
JohnsonDenominator B v = ((1 - ((Fintype.card F) / (Fintype.card F - 1)) * (e B v / n)) ^ 2
22+
- (1 - ((Fintype.card F) / (Fintype.card F - 1)) * (d B/n))) := by
3323
simp [JohnsonDenominator]
3424
field_simp
3525

@@ -40,81 +30,42 @@ def JohnsonConditionStrong (B : Finset (Fin n → F)) (v : Fin n → F) : Prop :
4030
let frac := q / (q - 1)
4131
(1 - frac * d/n) < (1- frac * e/n) ^ 2
4232

43-
private lemma johnson_condition_strong_implies_n_pos {B : Finset (Fin n → F)} {v : Fin n → F}
33+
private lemma johnson_condition_strong_implies_n_pos
4434
(h_johnson : JohnsonConditionStrong B v)
4535
:
4636
0 < n := by
4737
cases n <;> try simp [JohnsonConditionStrong] at *
4838

49-
private lemma johnson_condition_strong_implies_2_le_F_card {B : Finset (Fin n → F)} {v : Fin n → F}
39+
private lemma johnson_condition_strong_implies_2_le_F_card
5040
(h_johnson : JohnsonConditionStrong B v)
5141
:
5242
2 ≤ Fintype.card F := by
53-
generalize h : Fintype.card F = card
54-
rcases card with _ | card
55-
· simp [JohnsonConditionStrong] at h_johnson
56-
rw [h] at h_johnson
57-
simp at h_johnson
58-
· rcases card with _ | card
59-
· simp [JohnsonConditionStrong] at h_johnson
60-
rw [h] at h_johnson
61-
simp at h_johnson
62-
· omega
63-
43+
revert h_johnson
44+
dsimp [JohnsonConditionStrong]
45+
rcases Fintype.card F with _ | _ | _ <;> aesop
6446

65-
private lemma johnson_condition_strong_implies_2_le_B_card {B : Finset (Fin n → F)} {v : Fin n → F}
47+
private lemma johnson_condition_strong_implies_2_le_B_card
6648
(h_johnson : JohnsonConditionStrong B v)
6749
:
6850
2 ≤ B.card := by
69-
generalize h : B.card = card
70-
rcases card with _ | card
71-
· simp [JohnsonConditionStrong] at *
72-
simp [e, d] at *
73-
subst h
74-
simp at h_johnson
75-
· rcases card with _ | card
76-
· simp [JohnsonConditionStrong] at *
77-
simp [e, d] at *
78-
rw [h] at h_johnson
79-
simp [choose_2] at h_johnson
80-
have h_set := Finset.card_eq_one.1 h
81-
rcases h_set with ⟨a, h_set⟩
82-
rw [h_set] at h_johnson
83-
simp at h_johnson
84-
generalize hq : Fintype.card F = q
85-
rcases q with _ | q
86-
· simp [hq] at h_johnson
87-
· rcases q with _ | q
88-
· simp [hq] at h_johnson
89-
· have h : (Fintype.card F : ℚ) /((Fintype.card F : ℚ) - 1) =
90-
(1 : ℚ) + (1:ℚ)/((Fintype.card F : ℚ) - 1) := by
91-
have h : (Fintype.card F : ℚ) = ((Fintype.card F : ℚ) - 1) + 1 := by ring
92-
conv =>
93-
lhs
94-
congr
95-
rw [h]
96-
rfl
97-
rfl
98-
rw [Field.div_eq_mul_inv, Field.div_eq_mul_inv]
99-
rw [add_mul]
100-
rw [Field.mul_inv_cancel _ (by {
101-
rw [hq]
102-
simp
103-
aesop
104-
})]
105-
rw [h] at h_johnson
106-
have h' := JohnsonBound.a_lemma_im_not_proud_of (v := v) (a := a) (by omega)
107-
have h : (1 :ℚ) < (1 : ℚ) := by
108-
apply lt_of_lt_of_le h_johnson
109-
assumption
110-
simp at h
111-
· omega
51+
dsimp [JohnsonConditionStrong] at h_johnson
52+
rcases eq : B.card with _ | card | _ <;> [simp_all [e, d]; skip; omega]
53+
obtain ⟨a, ha⟩ := Finset.card_eq_one.1 eq
54+
replace h_johnson : 1 < |1 - (Fintype.card F) / ((Fintype.card F) - 1) * Δ₀(v, a) / (n : ℚ)| := by
55+
simp_all [e, d, choose_2]
56+
generalize eq₁ : Fintype.card F = q
57+
rcases q with _ | _ | q <;> [simp_all; simp_all; skip]
58+
have h : (Fintype.card F : ℚ) / (Fintype.card F - 1) = 1 + 1 / (Fintype.card F - 1) := by
59+
have : (Fintype.card F : ℚ) - 10 := by simp [sub_eq_zero]; omega
60+
field_simp
61+
have h' := JohnsonBound.abs_one_sub_div_le_one (v := v) (a := a) (by omega)
62+
exact absurd (lt_of_lt_of_le (h ▸ h_johnson) h') (lt_irrefl _)
11263

113-
lemma johnson_condition_strong_iff_johnson_denom_pos {B : Finset (Fin n → F)} {v : Fin n → F} :
64+
lemma johnson_condition_strong_iff_johnson_denom_pos :
11465
JohnsonConditionStrong B v ↔ 0 < JohnsonDenominator B v := by
11566
simp [JohnsonDenominator, JohnsonConditionStrong]
11667

117-
theorem johnson_bound [Field F] {B : Finset (Fin n → F)} {v : Fin n → F}
68+
theorem johnson_bound_OLD [Field F]
11869
(h_condition : JohnsonConditionStrong B v)
11970
:
12071
let d := d B
@@ -130,10 +81,29 @@ theorem johnson_bound [Field F] {B : Finset (Fin n → F)} {v : Fin n → F}
13081
rw [mul_assoc, mul_comm ((_)⁻¹) _, Field.mul_inv_cancel _ (by linarith)]
13182
simp
13283
rw [johnson_denominator_def]
133-
apply JohnsonBound.johnson_bound_lemma
84+
exact JohnsonBound.johnson_bound_lemma
13485
(johnson_condition_strong_implies_n_pos h_condition')
13586
(johnson_condition_strong_implies_2_le_B_card h_condition')
13687
(johnson_condition_strong_implies_2_le_F_card h_condition')
137-
88+
89+
theorem johnson_bound [Field F]
90+
(h_condition : JohnsonConditionStrong B v)
91+
:
92+
let d := d B
93+
let q : ℚ := Fintype.card F
94+
let frac := q / (q - 1)
95+
B.card ≤ (frac * d/n) / JohnsonDenominator B v
96+
:= by
97+
suffices B.card * JohnsonDenominator B v ≤
98+
Fintype.card F / (Fintype.card F - 1) * d B / n by
99+
rw [johnson_condition_strong_iff_johnson_denom_pos] at h_condition
100+
rw [←mul_le_mul_right h_condition]
101+
convert this using 1
102+
field_simp; rw [mul_div_mul_right]; linarith
103+
rw [johnson_denominator_def]
104+
exact JohnsonBound.johnson_bound_lemma
105+
(johnson_condition_strong_implies_n_pos h_condition)
106+
(johnson_condition_strong_implies_2_le_B_card h_condition)
107+
(johnson_condition_strong_implies_2_le_F_card h_condition)
138108

139109
end JohnsonBound

ArkLib/Data/CodingTheory/JohnsonBound/Choose2.lean

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,31 @@ namespace JohnsonBound
1616

1717
private def f (x : ℚ) : ℚ := x^2 - x
1818

19-
private lemma x_sqr_minus_x_is_conv' {x₁ x₂ : ℚ} {α₁ α₂ : ℚ}
19+
private lemma f_convex {x₁ x₂ : ℚ} {α₁ α₂ : ℚ}
2020
(h_noneg_1 : 0 ≤ α₁)
2121
(h_noneg_2 : 0 ≤ α₂)
2222
(h_conv : α₁ + α₂ = 1)
2323
:
2424
f (α₁ * x₁ + α₂ * x₂) ≤ α₁ * f x₁ + α₂ * f x₂ := by
2525
unfold f
26-
have h_conv : α₂ = 1 - α₁ := by
27-
rw [←h_conv]
28-
field_simp
29-
rw [add_sq, mul_sub, mul_sub]
30-
have h : α₁ * x₁ ^ 2 - α₁ * x₁ + (α₂ * x₂ ^ 2 - α₂ * x₂)
31-
= α₁ * x₁ ^ 2 + α₂ * x₂ ^ 2 - (α₁ * x₁ + α₂ * x₂) := by ring
32-
rw [h]
33-
field_simp
34-
rw [h_conv]
35-
have h : (α₁ * x₁) ^ 2 + 2 * (α₁ * x₁) * ((1 - α₁) * x₂) + ((1 - α₁) * x₂) ^ 2
36-
= α₁^2 * x₁ ^ 2 + 2 * (α₁ * (1 - α₁) * x₁ * x₂) + (1 - α₁)^2 * x₂ ^ 2 := by ring
37-
rw [h]
38-
apply add_le_of_le_sub_left
39-
conv =>
40-
lhs
41-
rw [←add_zero ((1 - α₁) ^ 2 * x₂ ^ 2)]
42-
rfl
43-
apply add_le_of_le_sub_left
44-
have h : α₁ * x₁ ^ 2
45-
+ (1 - α₁) * x₂ ^ 2 - (α₁ ^ 2 * x₁ ^ 2 + 2 * (α₁ * (1 - α₁) * x₁ * x₂)) - (1 - α₁) ^ 2 * x₂ ^ 2
46-
= α₁ * (1 - α₁) * x₁^2 - 2 * α₁ * (1 - α₁) * x₁ * x₂ + (1 - α₁) * α₁ * x₂^2 := by ring_nf
47-
rw [h]
48-
have h : α₁ * (1 - α₁) * x₁ ^ 2 - 2 * α₁ * (1 - α₁) * x₁ * x₂ + (1 - α₁) * α₁ * x₂ ^ 2
49-
= α₁ * (1 - α₁) * (x₁ - x₂ ) ^ 2 := by ring
50-
rw [h, ←h_conv]
51-
apply mul_nonneg
52-
apply mul_nonneg h_noneg_1 h_noneg_2
53-
exact sq_nonneg _
26+
obtain ⟨rfl⟩ := show α₂ = 1 - α₁ by rw [←h_conv]; simp
27+
suffices 0 ≤ α₁ * (1 - α₁) * (x₁ - x₂) ^ 2 by linarith
28+
exact mul_nonneg (mul_nonneg h_noneg_1 h_noneg_2) (sq_nonneg _)
5429

5530
def choose_2 (x : ℚ) : ℚ := x * (x-1)/2
5631

5732
private lemma choose_2_eq_half_f :
58-
choose_2 = (1/2) * f := by
33+
choose_2 = (1/2) * f := by
5934
ext x
6035
simp [choose_2, f]
6136
ring
6237

63-
theorem choose_2_convex :
64-
ConvexOn ℚ Set.univ choose_2 := by
65-
simp [ConvexOn, Convex, StarConvex]
38+
@[simp]
39+
theorem choose_2_convex : ConvexOn ℚ Set.univ choose_2 := by
6640
rw [choose_2_eq_half_f]
41+
refine ⟨convex_univ, fun x₁ _ x₂ _ α₁ α₂ hα₁ hα₂ h ↦ ?p₁⟩
42+
have := f_convex (x₁ := x₁) (x₂ := x₂) hα₁ hα₂ h
6743
field_simp
68-
intro x₁ x₂ α₁ α₂ hα₁ hα₂ h_conv
69-
rw [Field.div_eq_mul_inv, Field.div_eq_mul_inv]
70-
rw [mul_le_mul_right (by simp)]
71-
apply x_sqr_minus_x_is_conv' <;> aesop
44+
linarith
7245

7346
end JohnsonBound

ArkLib/Data/CodingTheory/JohnsonBound/Expectations.lean

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,42 @@ import ArkLib.Data.CodingTheory.JohnsonBound.Choose2
1717
namespace JohnsonBound
1818

1919
variable {n : ℕ}
20-
variable {F : Type*} [Fintype F] [DecidableEq F]
20+
variable {F : Type*} [DecidableEq F]
21+
{B : Finset (Fin n → F)} {v : Fin n → F}
2122

2223
def e (B : Finset (Fin n → F)) (v : Fin n → F) : ℚ :=
23-
(1 : ℚ)/B.card * ∑ x ∈ B, Δ₀(v, x)
24+
(1 : ℚ)/B.card * ∑ x ∈ B, Δ₀(v, x)
2425

2526
def d (B : Finset (Fin n → F)) : ℚ :=
2627
(1 : ℚ)/(2 * choose_2 B.card) * ∑ x ∈ (Finset.product B B) with x.1 ≠ x.2, Δ₀(x.1, x.2)
2728

28-
lemma lin_shift_card [Field F] {B : Finset (Fin n → F)} {v : Fin n → F}
29+
lemma lin_shift_card [Field F] [Fintype F]
2930
:
3031
B.card = ({ x - v | x ∈ B} : Finset _).card := by
31-
apply Finset.card_bij
32-
(i := fun x _ => x - v)
33-
(by aesop)
34-
(by simp)
35-
(by simp)
32+
apply Finset.card_bij (i := fun x _ => x - v) <;> aesop
3633

3734
@[simp]
3835
lemma lin_shift_hamming_distance [Field F] {x₁ x₂ v : Fin n → F}
3936
:
40-
Δ₀(x₁ - v, x₂ - v) = Δ₀(x₁, x₂) := by
41-
simp [hammingDist]
42-
lemma lin_shift_e [Field F] {B : Finset (Fin n → F)} {v : Fin n → F}
37+
Δ₀(x₁ - v, x₂ - v) = Δ₀(x₁, x₂) := by simp [hammingDist]
38+
39+
lemma lin_shift_e [Field F] [Fintype F]
4340
(h_B : B.card ≠ 0)
4441
:
4542
e B v = e ({ x - v | x ∈ B} : Finset _) 0 := by
4643
simp [e]
4744
rw [←lin_shift_card]
4845
field_simp
49-
apply Finset.sum_bij (i := fun x _ => x - v) <;> try simp [hammingDist, hammingNorm]
50-
intro a ha
51-
apply Finset.card_bij (i := fun x _ => x) <;> try tauto
52-
simp at *
53-
intro α₁ h contr
54-
rw [←zero_add (v α₁)] at h
55-
rw [←contr] at h
56-
simp at h
57-
simp
58-
intro b h contr
59-
rw [contr] at h
60-
simp at h
46+
apply Finset.sum_bij (i := fun x _ => x - v) <;>
47+
simp [hammingDist, hammingNorm, sub_eq_zero, eq_comm]
6148

62-
lemma lin_shift_d [Field F] {B : Finset (Fin n → F)} (v : Fin n → F)
49+
lemma lin_shift_d [Field F] [Fintype F]
6350
(h_B : 2 ≤ B.card)
6451
:
65-
d B = d ({ x - v | x ∈ B} : Finset _) := by
52+
d B = d ({x - v | x ∈ B} : Finset _) := by
6653
simp [d]
6754
rw [←lin_shift_card]
68-
have h : choose_2 B.card ≠ 0 := by
69-
simp [choose_2]
70-
apply And.intro (by aesop)
71-
intro contr
72-
have h : (B.card : ℚ) = 1 := by
73-
rw [←zero_add (1 : ℚ), ←contr]
74-
simp
75-
simp at h
76-
omega
55+
have h : choose_2 B.card ≠ 0 := by aesop (add simp [choose_2, sub_eq_zero])
7756
field_simp
7857
apply Finset.sum_bij (fun x _ => (x.1 - v, x.2 -v)) <;> try aesop
7958

0 commit comments

Comments
 (0)