Skip to content

Commit 3f2c83a

Browse files
committed
Don't use NumberingOn. Move to under PlainCombi
1 parent 0bc5775 commit 3f2c83a

File tree

3 files changed

+61
-71
lines changed

3 files changed

+61
-71
lines changed

LeanCamCombi.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import LeanCamCombi.GrowthInGroups.Lecture4
1313
import LeanCamCombi.Mathlib.Combinatorics.Additive.ApproximateSubgroup
1414
import LeanCamCombi.Mathlib.Combinatorics.SimpleGraph.Density
1515
import LeanCamCombi.Mathlib.Combinatorics.SimpleGraph.Subgraph
16+
import LeanCamCombi.Mathlib.Data.Fintype.Card
1617
import LeanCamCombi.Mathlib.Probability.ProbabilityMassFunction.Constructions
1718
import LeanCamCombi.PlainCombi.LittlewoodOfford
1819
import LeanCamCombi.PlainCombi.OrderShatter
20+
import LeanCamCombi.PlainCombi.ProbLYM
1921
import LeanCamCombi.PlainCombi.VanDenBergKesten
2022
import LeanCamCombi.StableCombi.AddSet
2123
import LeanCamCombi.StableCombi.Formula
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Mathlib.Data.Fintype.Card
2+
3+
namespace Fintype
4+
variable {α : Type*} {p : α → Prop}
5+
6+
-- TODO: Replace `card_subtype_le`
7+
lemma card_subtype_le' [Fintype α] [Fintype {a // p a}] : card {a // p a} ≤ card α := by
8+
classical convert card_subtype_le _; infer_instance
9+
10+
end Fintype
Lines changed: 49 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2024 Ching-Tsun Chou, Chris Wong. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Ching-Tsun Chou, Chris Wong
55
-/
6-
6+
import LeanCamCombi.Mathlib.Data.Fintype.Card
77
import Mathlib.Data.Fintype.Perm
88
import Mathlib.Probability.UniformOn
99

@@ -42,87 +42,67 @@ in mathlib because we need the special property `set_prefix_subset` below. -/
4242
@[reducible]
4343
def Numbering (α : Type*) [Fintype α] := α ≃ Fin (card α)
4444

45-
@[reducible]
46-
def NumberingOn {α : Type*} (s : Finset α) := {x // x ∈ s} ≃ Fin s.card
47-
4845
variable {α : Type*} [Fintype α] [DecidableEq α]
4946

5047
theorem card_Numbering : card (Numbering α) = (card α).factorial := by
5148
exact Fintype.card_equiv (Fintype.equivFinOfCardEq rfl)
5249

53-
omit [Fintype α] in
54-
theorem card_NumberingOn (s : Finset α) : card (NumberingOn s) = s.card.factorial := by
55-
simp only [NumberingOn]
56-
have h1 : card {x // x ∈ s} = card (Fin s.card) := by simp
57-
have h2 : {x // x ∈ s} ≃ Fin s.card := by exact Fintype.equivOfCardEq h1
58-
simp [Fintype.card_equiv h2]
59-
6050
/-- `IsPrefix s f` means that the elements of `s` precede the elements of `sᶜ`
6151
in the numbering `f`. -/
6252
def IsPrefix (s : Finset α) (f : Numbering α) :=
63-
∀ x, x ∈ s ↔ f x < s.card
53+
∀ x, x ∈ s ↔ f x < #s
6454

6555
omit [DecidableEq α] in
6656
theorem subset_IsPrefix_IsPrefix {s1 s2 : Finset α} {f : Numbering α}
6757
(h_s1 : IsPrefix s1 f) (h_s2 : IsPrefix s2 f) (h_card : s1.card ≤ s2.card) : s1 ⊆ s2 := by
6858
intro a h_as1
6959
exact (h_s2 a).mpr (lt_of_lt_of_le ((h_s1 a).mp h_as1) h_card)
7060

71-
def equiv_IsPrefix_NumberingOn2 (s : Finset α) : {f // IsPrefix s f} ≃ NumberingOn s × NumberingOn sᶜ where
61+
def equiv_IsPrefix_Numbering2 (s : Finset α) :
62+
{f // IsPrefix s f} ≃ Numbering s × Numbering ↑(sᶜ) where
7263
toFun := fun ⟨f, hf⟩ ↦
73-
({
74-
toFun := fun ⟨x, hx⟩ ↦ ⟨f x, by rwa [← hf x]⟩
75-
invFun := fun ⟨n, hn⟩ ↦ ⟨f.symm ⟨n, by have := s.card_le_univ; omega⟩, by rw [hf]; simpa⟩
76-
left_inv := by rintro ⟨x, hx⟩; simp
77-
right_inv := by rintro ⟨n, hn⟩; simp
78-
},
79-
{
80-
toFun := fun ⟨x, hx⟩ ↦ ⟨f x - s.card, by
81-
rw [s.mem_compl, hf] at hx
82-
rw [s.card_compl]
83-
exact Nat.sub_lt_sub_right (by omega) (by omega)
84-
85-
invFun := fun ⟨n, hn⟩ ↦ ⟨f.symm ⟨n + s.card, by rw [s.card_compl] at hn; omega⟩,
86-
by rw [s.mem_compl, hf]; simp⟩
87-
left_inv := by
64+
{ fst.toFun x := ⟨f x, by simp [← hf x]⟩
65+
fst.invFun n :=
66+
⟨f.symm ⟨n, n.2.trans_le <| by simpa using s.card_le_univ⟩, by rw [hf]; simpa using n.2
67+
fst.left_inv x := by simp
68+
fst.right_inv n := by simp
69+
snd.toFun x := ⟨f x - #s, by
70+
have := (hf x).not.1 (Finset.mem_compl.1 x.2)
71+
simp at this ⊢
72+
omega⟩
73+
snd.invFun n :=
74+
⟨f.symm ⟨n + #s, Nat.add_lt_of_lt_sub <| by simpa using n.2⟩, by rw [s.mem_compl, hf]; simp⟩
75+
snd.left_inv := by
8876
rintro ⟨x, hx⟩
8977
rw [s.mem_compl, hf, not_lt] at hx
9078
simp [Nat.sub_add_cancel hx]
91-
right_inv := by rintro ⟨n, hn⟩; simp
92-
})
93-
invFun := fun (g, g') ↦ ⟨
94-
{
95-
toFun := fun x ↦
79+
snd.right_inv := by rintro ⟨n, hn⟩; simp }
80+
invFun := fun (g, g') ↦
81+
{ val.toFun x :=
9682
if hx : x ∈ s then
97-
g ⟨x, hx⟩ |>.castLE s.card_le_univ
83+
g ⟨x, hx⟩ |>.castLE Fintype.card_subtype_le'
9884
else
99-
g' ⟨x, by simpa⟩ |>.addNat s.card |>.cast (by simp)
100-
invFun := fun ⟨n, hn⟩ ↦
101-
if hn' : n < s.card then
102-
g.symm ⟨n, hn'
85+
g' ⟨x, by simpa⟩ |>.addNat #s |>.cast (by simp [card_le_univ])
86+
val.invFun n :=
87+
if hn : n < #s then
88+
g.symm ⟨n, by simpa using hn
10389
else
104-
g'.symm ⟨n - s.card, by rw [s.card_compl]; omega⟩
105-
left_inv := by intro x; by_cases hx : x ∈ s <;> simp [hx]
106-
right_inv := by
107-
rintro ⟨n, hn⟩
108-
by_cases hn' : n < s.card
109-
· simp [hn']
110-
· simp [hn']
111-
split_ifs
112-
· rename_i h
113-
have : ∀ x, ↑(g'.symm x) ∉ s := by
114-
intro x
115-
simp only [← Finset.mem_compl, Finset.coe_mem]
116-
exact this _ h |>.elim
117-
· simp [Nat.sub_add_cancel (not_lt.mp hn')]
118-
},
119-
by
120-
intro x
121-
constructor
122-
· intro hx
123-
simp [hx]
124-
· by_cases hx : x ∈ s <;> simp [hx]
125-
90+
g'.symm ⟨n - #s, by simp; omega⟩
91+
val.left_inv x := by
92+
by_cases hx : x ∈ s
93+
· have : g ⟨x, hx⟩ < #s := by simpa using (g ⟨x, hx⟩).2
94+
simp [hx, this]
95+
· simp [hx, Equiv.symm_apply_eq]
96+
val.right_inv n := by
97+
obtain hns | hsn := lt_or_le n.1 #s
98+
· simp [hns]
99+
· simp [hsn.not_lt, hsn, dif_neg (mem_compl.1 <| Subtype.prop _), Fin.ext_iff,
100+
Fintype.card_subtype_le']
101+
property x := by
102+
constructor
103+
· intro hx
104+
simpa [hx, -Fin.is_lt] using (g _).is_lt
105+
· by_cases hx : x ∈ s <;> simp [hx] }
126106
left_inv := by
127107
rintro ⟨f, hf⟩
128108
ext x
@@ -149,11 +129,10 @@ def PrefixedNumbering (s : Finset α) : Finset (Numbering α) :=
149129
{f | IsPrefix s f}
150130

151131
theorem card_PrefixedNumbering (s : Finset α) :
152-
(PrefixedNumbering s).card = s.card.factorial * (card α - s.card).factorial := by
153-
have h_eq:= Fintype.card_congr (equiv_IsPrefix_NumberingOn2 s)
132+
(PrefixedNumbering s).card = (#s).factorial * (card α - #s).factorial := by
133+
have h_eq:= Fintype.card_congr (equiv_IsPrefix_Numbering2 s)
154134
rw [Fintype.card_subtype] at h_eq
155-
rw [PrefixedNumbering, h_eq, Fintype.card_prod,
156-
card_NumberingOn s, card_NumberingOn sᶜ, card_compl]
135+
simp [PrefixedNumbering, h_eq, card_Numbering]
157136

158137
private lemma auxLemma {k m n : ℕ} (hn : 0 < n) (heq : k * m = n) :
159138
(↑ m : ENNReal) / (↑ n : ENNReal) = 1 / (↑ k : ENNReal) := by
@@ -174,11 +153,11 @@ private lemma auxLemma {k m n : ℕ} (hn : 0 < n) (heq : k * m = n) :
174153
instance : MeasurableSpace (Numbering α) := ⊤
175154

176155
theorem count_PrefixedNumbering (s : Finset α) :
177-
count (PrefixedNumbering s).toSet = ↑(s.card.factorial * (card α - s.card).factorial) := by
156+
count (PrefixedNumbering s).toSet = ↑((#s).factorial * (card α - #s).factorial) := by
178157
rw [← card_PrefixedNumbering s, count_apply_finset]
179158

180159
theorem prob_PrefixedNumbering (s : Finset α) :
181-
uniformOn Set.univ (PrefixedNumbering s).toSet = 1 / (card α).choose s.card := by
160+
uniformOn Set.univ (PrefixedNumbering s).toSet = 1 / (card α).choose #s := by
182161
rw [uniformOn_univ, count_PrefixedNumbering s, card_Numbering]
183162
apply auxLemma (Nat.factorial_pos (card α))
184163
rw [← mul_assoc]
@@ -191,7 +170,7 @@ theorem disj_PrefixedNumbering {s t : Finset α} (h_st : ¬ s ⊆ t) (h_ts : ¬
191170
simp only [mem_inter_iff, Finset.mem_coe, mem_empty_iff_false, imp_false, not_and]
192171
simp [PrefixedNumbering]
193172
intro h_s h_t
194-
rcases Nat.le_total s.card t.card with h_st' | h_ts'
173+
rcases Nat.le_total #s t.card with h_st' | h_ts'
195174
· exact h_st (subset_IsPrefix_IsPrefix h_s h_t h_st')
196175
· exact h_ts (subset_IsPrefix_IsPrefix h_t h_s h_ts')
197176

@@ -211,10 +190,9 @@ theorem prob_biUnion_antichain (h𝓐 : IsAntichain (· ⊆ ·) 𝓐.toSet) :
211190
rw [measure_biUnion_finset hd hm (μ := uniformOn Set.univ)]
212191

213192
theorem LYM_inequality (h𝓐 : IsAntichain (· ⊆ ·) 𝓐.toSet) :
214-
∑ s ∈ 𝓐, ((1 : ENNReal) / (card α).choose s.card) ≤ 1 := by
215-
have h1 : ∀ s ∈ 𝓐,
216-
(1 : ENNReal) / (card α).choose s.card = uniformOn Set.univ (PrefixedNumbering s).toSet := by
217-
intro s h_s
193+
∑ s ∈ 𝓐, ((1 : ENNReal) / (card α).choose #s) ≤ 1 := by
194+
have h1 s (hs : s ∈ 𝓐) :
195+
(1 : ENNReal) / (card α).choose #s = uniformOn Set.univ (PrefixedNumbering s).toSet := by
218196
rw [prob_PrefixedNumbering]
219197
rw [Finset.sum_congr (rfl : 𝓐 = 𝓐) h1, ← prob_biUnion_antichain h𝓐]
220198
exact prob_le_one

0 commit comments

Comments
 (0)