Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 7c38416

Browse files
committed
feat(data/sigma,data/finset,algebra): add support for the sigma type to finset and big operators
1 parent 7d8e3f3 commit 7c38416

File tree

5 files changed

+119
-63
lines changed

5 files changed

+119
-63
lines changed

algebra/big_operators.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ calc (s.product t).prod f = (s.prod $ λx, (t.image $ λy, (x, y)).prod f) :
113113
prod_bind $ assume x hx y hy h, ext $ by simp [mem_image_iff]; cc
114114
... = _ : begin congr, apply funext, intro x, apply prod_image, simp {contextual := tt} end
115115

116+
lemma prod_sigma {σ : α → Type*} [∀a, decidable_eq (σ a)]
117+
{s : finset α} {t : Πa, finset (σ a)} {f : sigma σ → β} :
118+
(s.sigma t).prod f = (s.prod $ λa, (t a).prod $ λs, f ⟨a, s⟩) :=
119+
have ∀a₁ a₂:α, ∀s₁ : finset (σ a₁), ∀s₂ : finset (σ a₂), a₁ ≠ a₂ →
120+
s₁.image (sigma.mk a₁) ∩ s₂.image (sigma.mk a₂) = ∅,
121+
from assume b₁ b₂ s₁ s₂ h, ext $ assume ⟨b₃, c₃⟩,
122+
by simp [mem_image_iff, sigma.mk_eq_mk_iff, heq_iff_eq] {contextual := tt}; cc,
123+
calc (s.bind (λa, (t a).image (λs, sigma.mk a s))).prod f =
124+
s.prod (λa, ((t a).image (λs, sigma.mk a s)).prod f) :
125+
prod_bind $ assume a₁ ha a₂ ha₂ h, this a₁ a₂ (t a₁) (t a₂) h
126+
... = (s.prod $ λa, (t a).prod $ λs, f ⟨a, s⟩) :
127+
by simp [prod_image, sigma.mk_eq_mk_iff, heq_iff_eq]
128+
116129
lemma prod_mul_distrib : s.prod (λx, f x * g x) = s.prod f * s.prod g :=
117130
eq.trans (by simp; refl) fold_op_distrib
118131

@@ -263,6 +276,7 @@ run_cmd transport_multiplicative_to_additive [
263276
(`finset.prod_inv_distrib, `finset.sum_neg_distrib),
264277
(`finset.prod_const_one, `finset.sum_const_zero),
265278
(`finset.prod_comm, `finset.sum_comm),
279+
(`finset.prod_sigma, `finset.sum_sigma),
266280
(`finset.prod_subset, `finset.sum_subset)]
267281

268282
namespace finset

data/finset/fold.lean

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ Author: Johannes Hölzl
55
66
Fold on finite sets
77
-/
8-
import data.list.set data.list.perm tactic.finish data.finset.basic
8+
import data.list.set data.list.perm data.finset.basic data.sigma tactic.finish
99
open list subtype nat finset
1010

1111
universes u v w
1212
variables {α : Type u} {β : Type v} {γ : Type w}
1313

14+
section logic
15+
16+
lemma heq_iff_eq {a₁ a₂ : α} : a₁ == a₂ ↔ a₁ = a₂ :=
17+
iff.intro eq_of_heq heq_of_eq
18+
19+
end logic
20+
1421
namespace list
1522

1623
@[congr] lemma map_congr {f g : α → β} : ∀ {l : list α}, (∀ x ∈ l, f x = g x) → map f l = map g l
@@ -149,4 +156,22 @@ by simp [finset.product, mem_bind_iff, mem_image_iff]
149156

150157
end prod
151158

152-
end finset
159+
section sigma
160+
variables {σ : α → Type*} [decidable_eq α] [∀a, decidable_eq (σ a)]
161+
{s : finset α} {t : Πa, finset (σ a)}
162+
163+
protected def sigma (s : finset α) (t : Πa, finset (σ a)) : finset (Σa, σ a) :=
164+
s.bind $ λa, (t a).image $ λb, ⟨a, b⟩
165+
166+
lemma mem_sigma_iff {p : sigma σ} : p ∈ s.sigma t ↔ p.1 ∈ s ∧ p.2 ∈ t (p.1) :=
167+
by cases p with a b;
168+
simp [finset.sigma, mem_bind_iff, mem_image_iff, iff_def, sigma.mk_eq_mk_iff, heq_iff_eq]
169+
{contextual := tt}
170+
171+
lemma sigma_mono {s₁ s₂ : finset α} {t₁ t₂ : Πa, finset (σ a)} :
172+
s₁ ⊆ s₂ → (∀a, t₁ a ⊆ t₂ a) → s₁.sigma t₁ ⊆ s₂.sigma t₂ :=
173+
by simp [subset_iff, mem_sigma_iff] {contextual := tt}
174+
175+
end sigma
176+
177+
end finset

data/sigma/basic.lean

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Author: Johannes Hölzl
5+
-/
6+
7+
variables {α : Type*} {β : α → Type*}
8+
9+
instance [inhabited α] [inhabited (β (default α))] : inhabited (sigma β) :=
10+
⟨⟨default α, default (β (default α))⟩⟩
11+
12+
instance [h₁ : decidable_eq α] [h₂ : ∀a, decidable_eq (β a)] : decidable_eq (sigma β)
13+
| ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ := match a₁, b₁, a₂, b₂, h₁ a₁ a₂ with
14+
| _, b₁, _, b₂, is_true (eq.refl a) :=
15+
match b₁, b₂, h₂ a b₁ b₂ with
16+
| _, _, is_true (eq.refl b) := is_true rfl
17+
| b₁, b₂, is_false n := is_false (assume h, sigma.no_confusion h (λe₁ e₂, n $ eq_of_heq e₂))
18+
end
19+
| a₁, _, a₂, _, is_false n := is_false (assume h, sigma.no_confusion h (λe₁ e₂, n e₁))
20+
end
21+
22+
namespace sigma
23+
24+
lemma mk_eq_mk_iff {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂} :
25+
@sigma.mk α β a₁ b₁ = @sigma.mk α β a₂ b₂ ↔ (a₁ = a₂ ∧ b₁ == b₂) :=
26+
iff.intro sigma.mk.inj $
27+
assume ⟨h₁, h₂⟩, match a₁, a₂, b₁, b₂, h₁, h₂ with _, _, _, _, eq.refl a, heq.refl b := rfl end
28+
29+
variables {α₁ : Type*} {α₂ : Type*} {β₁ : α₁ → Type*} {β₂ : α₂ → Type*}
30+
31+
def map (f₁ : α₁ → α₂) (f₂ : Πa, β₁ a → β₂ (f₁ a)) : sigma β₁ → sigma β₂
32+
| ⟨a, b⟩ := ⟨f₁ a, f₂ a b⟩
33+
34+
end sigma

data/sigma/default.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import data.sigma.basic

topology/infinite_sum.lean

Lines changed: 43 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,49 @@ have (λs:finset β, s.sum (g ∘ f)) = g ∘ (λs:finset β, s.sum f),
143143
show tendsto (λs:finset β, s.sum (g ∘ f)) at_top (nhds (g a)),
144144
by rw [this]; exact tendsto_compose hf (continuous_iff_tendsto.mp h₃ a)
145145

146+
lemma is_sum_sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
147+
(hf : ∀b, is_sum (λc, f ⟨b, c⟩) (g b)) (ha : is_sum f a) : is_sum g a :=
148+
assume s' hs',
149+
let
150+
⟨s, hs, hss', hsc⟩ := nhds_is_closed hs',
151+
⟨u, hu⟩ := mem_at_top_iff.mp $ ha $ hs,
152+
fsts := u.image sigma.fst,
153+
snds := λb, u.bind (λp, (if h : p.1 = b then {cast (congr_arg γ h) p.2} else ∅ : finset (γ b)))
154+
in
155+
have u_subset : u ⊆ fsts.sigma snds,
156+
from subset_iff.mpr $ assume ⟨b, c⟩ hu,
157+
have hb : b ∈ fsts, from mem_image_iff.mpr ⟨_, hu, rfl⟩,
158+
have hc : c ∈ snds b, from mem_bind_iff.mpr ⟨_, hu, by simp; refl⟩,
159+
by simp [mem_sigma_iff, hb, hc] ,
160+
mem_at_top_iff.mpr $ exists.intro fsts $ assume bs (hbs : fsts ⊆ bs),
161+
have h : ∀cs:(Πb, b ∈ bs → finset (γ b)),
162+
(⋂b (hb : b ∈ bs), (λp:Πb, finset (γ b), p b) ⁻¹' {cs' | cs b hb ⊆ cs' }) ∩
163+
(λp, bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩))) ⁻¹' s ≠ ∅,
164+
from assume cs,
165+
let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in
166+
have sum_eq : bs.sum (λb, (cs' b).sum (λc, f ⟨b, c⟩)) = (bs.sigma cs').sum f,
167+
from sum_sigma.symm,
168+
have (bs.sigma cs').sum f ∈ s,
169+
from hu _ $ subset.trans u_subset $ sigma_mono hbs $
170+
assume b, @finset.subset_union_right (γ b) _ _ _,
171+
ne_empty_iff_exists_mem.mpr $ exists.intro cs' $
172+
by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_right] },
173+
have tendsto (λp:(Πb:β, finset (γ b)), bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩)))
174+
(⨅b (h : b ∈ bs), at_top.vmap (λp, p b)) (nhds (bs.sum g)),
175+
from tendsto_sum $
176+
assume c hc, tendsto_infi' c $ tendsto_infi' hc $ tendsto_compose tendsto_vmap (hf c),
177+
have bs.sum g ∈ s,
178+
from mem_closure_of_tendsto this hsc $ forall_sets_neq_empty_iff_neq_bot.mp $
179+
by simp [mem_inf_sets, exists_imp_distrib, and_imp, forall_and_distrib',
180+
filter.mem_infi_sets_finset, mem_vmap, skolem, mem_at_top_iff];
181+
from
182+
assume s₁ s₂ s₃ hs₁ hs₃ p hs₂ p' hp cs hp',
183+
have (⋂b (h : b ∈ bs), (λp:(Πb, finset (γ b)), p b) ⁻¹' {cs' | cs b h ⊆ cs' }) ≤ (⨅b∈bs, p b),
184+
from infi_le_infi $ assume b, infi_le_infi $ assume hb,
185+
le_trans (preimage_mono $ hp' b hb) (hp b hb),
186+
neq_bot_of_le_neq_bot (h _) (le_trans (inter_subset_inter (le_trans this hs₂) hs₃) hs₁),
187+
hss' this
188+
146189
end is_sum
147190

148191
section is_sum_iff_is_sum_of_iso_ne_zero
@@ -203,67 +246,6 @@ iff.intro (is_sum_of_is_sum_ne_zero h₂ h₁ h₄ h₃) (is_sum_of_is_sum_ne_ze
203246

204247
end is_sum_iff_is_sum_of_iso_ne_zero
205248

206-
lemma is_sum_sigma
207-
[add_comm_monoid α] [topological_space α] [topological_add_monoid α] [regular_space α]
208-
{γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
209-
(hf : ∀b, is_sum (λc, f ⟨b, c⟩) (g b)) (ha : is_sum f a) : is_sum g a :=
210-
assume s' hs',
211-
let
212-
⟨s, hs, hss', hsc⟩ := nhds_is_closed hs',
213-
⟨u, hu⟩ := mem_at_top_iff.mp $ ha $ hs,
214-
fsts := u.image sigma.fst,
215-
snds := λb, u.bind (λp, (if h : p.1 = b then {cast (congr_arg γ h) p.2} else ∅ : finset (γ b)))
216-
in
217-
have sig_inj : ∀b, ∀c₁ c₂ : γ b, sigma.mk b c₁ = sigma.mk b c₂ ↔ c₁ = c₂,
218-
from assume b c₁ c₂, ⟨assume h, by cases h; refl, assume h, by simp *⟩,
219-
have sig_image_inj : ∀b₁ b₂, ∀s₁ : finset (γ b₁), ∀s₂ : finset (γ b₂), b₁ ≠ b₂ →
220-
s₁.image (sigma.mk b₁) ∩ s₂.image (sigma.mk b₂) = ∅,
221-
from assume b₁ b₂ s₁ s₂ h, ext $ assume ⟨b₃, c₃⟩,
222-
by simp [mem_image_iff];
223-
from assume c₁ h₁ eq₁ c₂ h₂ eq₂,
224-
have h₁ : b₁ = b₃, from congr_arg sigma.fst eq₁,
225-
have h₂ : b₂ = b₃, from congr_arg sigma.fst eq₂,
226-
h $ by simp [h₁, h₂],
227-
mem_at_top_iff.mpr $ exists.intro fsts $ assume bs (hbs : fsts ⊆ bs),
228-
have h : ∀cs:(Πb, b ∈ bs → finset (γ b)),
229-
(⋂b (hb : b ∈ bs), (λp:Πb, finset (γ b), p b) ⁻¹' {cs' | cs b hb ⊆ cs' }) ∩
230-
(λp, bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩))) ⁻¹' s ≠ ∅,
231-
from assume cs,
232-
let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in
233-
let sig : finset (sigma γ) := bs.bind (λb, (cs' b).image (λc, ⟨b, c⟩)) in
234-
have sum_eq : bs.sum (λb, (cs' b).sum (λc, f ⟨b, c⟩)) = sig.sum f,
235-
from calc bs.sum (λb, (cs' b).sum (λc, f ⟨b, c⟩)) =
236-
bs.sum (λb, ((cs' b).image (@sigma.mk β γ b)).sum f) :
237-
by simp [sum_image, sig_inj]
238-
... = sig.sum f :
239-
(sum_bind $ assume b₁ hb b₂ hb₂ h, sig_image_inj b₁ b₂ (cs' b₁) (cs' b₂) h).symm,
240-
have sig.sum f ∈ s,
241-
from hu _ $ subset_iff.mpr $ show ∀x:sigma γ, x ∈ u → x ∈ sig,
242-
from assume ⟨b, c⟩ hbc,
243-
have hb : b ∈ fsts, from mem_image_iff.mpr ⟨_, hbc, rfl⟩,
244-
have hb' : b ∈ bs, from mem_of_subset_of_mem hbs hb,
245-
have hc : c ∈ snds b, from mem_bind_iff.mpr ⟨_, hbc, by simp; refl⟩,
246-
have hc' : c ∈ cs' b, by simp [hb', hc],
247-
by simp [sig, mem_bind_iff];
248-
from ⟨b, hb', mem_image_iff.mpr ⟨c, hc', rfl⟩⟩,
249-
ne_empty_iff_exists_mem.mpr $ exists.intro cs' $
250-
by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_right] },
251-
have tendsto (λp:(Πb:β, finset (γ b)), bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩)))
252-
(⨅b (h : b ∈ bs), at_top.vmap (λp, p b)) (nhds (bs.sum g)),
253-
from tendsto_sum $
254-
assume c hc, tendsto_infi' c $ tendsto_infi' hc $ tendsto_compose tendsto_vmap (hf c),
255-
have bs.sum g ∈ s,
256-
from mem_closure_of_tendsto this hsc $ forall_sets_neq_empty_iff_neq_bot.mp $
257-
by simp [mem_inf_sets, exists_imp_distrib, and_imp, forall_and_distrib',
258-
filter.mem_infi_sets_finset, mem_vmap, skolem, mem_at_top_iff];
259-
from
260-
assume s₁ s₂ s₃ hs₁ hs₃ p hs₂ p' hp cs hp',
261-
have (⋂b (h : b ∈ bs), (λp:(Πb, finset (γ b)), p b) ⁻¹' {cs' | cs b h ⊆ cs' }) ≤ (⨅b∈bs, p b),
262-
from infi_le_infi $ assume b, infi_le_infi $ assume hb,
263-
le_trans (preimage_mono $ hp' b hb) (hp b hb),
264-
neq_bot_of_le_neq_bot (h _) (le_trans (inter_subset_inter (le_trans this hs₂) hs₃) hs₁),
265-
hss' this
266-
267249
section topological_group
268250
variables [add_comm_group α] [uniform_space α] [complete_space α] [uniform_add_group α]
269251
variables {f g : β → α} {a a₁ a₂ : α}

0 commit comments

Comments
 (0)