Skip to content

Commit

Permalink
refactor(data/set/lattice): add congr lemmas for Prop-indexed `Unio…
Browse files Browse the repository at this point in the history
…n` and `Inter` (#8260)

Thanks to new `@[congr]` lemmas `Union_congr_Prop` and `Inter_congr_Prop`, `simp` can simplify `p y` in `⋃ y (h : p y), f y`. As a result, LHS of many lemmas (e.g., `Union_image`) is no longer in `simp` normal form. E.g.,
```lean
lemma bUnion_range {f : ι → α} {g : α → set β} : (⋃x ∈ range f, g x) = (⋃y, g (f y)) :=
```
can no longer be a `@[simp]` lemma because `simp` simplifies `⋃x ∈ range f, g x` to `⋃ (x : α) (h : ∃ i, f i = x), g x`, then to `⋃ (x : α) (i : α) (h : f i = x), g x`. So, we add
```lean
@[simp] lemma Union_Union_eq' {f : ι → α} {g : α → set β} :
  (⋃ x y (h : f y = x), g x) = ⋃ y, g (f y) :=
```

Also, `Union` and `Inter` are semireducible, so one has to explicitly convert between these operations and `supr`/`infi`.



Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
  • Loading branch information
urkud and sgouezel committed Aug 1, 2021
1 parent f961b28 commit d3c943b
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 220 deletions.
4 changes: 3 additions & 1 deletion src/algebra/lie/subalgebra.lean
Expand Up @@ -315,7 +315,9 @@ end
lemma Inf_glb (S : set (lie_subalgebra R L)) : is_glb S (Inf S) :=
begin
have h : ∀ (K K' : lie_subalgebra R L), (K : set L) ≤ K' ↔ K ≤ K', { intros, exact iff.rfl, },
simp only [is_glb.of_image h, Inf_coe, is_glb_binfi],
apply is_glb.of_image h,
simp only [Inf_coe],
exact is_glb_binfi
end

/-- The set of Lie subalgebras of a Lie algebra form a complete lattice.
Expand Down
6 changes: 4 additions & 2 deletions src/algebra/lie/submodule.lean
Expand Up @@ -271,8 +271,10 @@ end

lemma Inf_glb (S : set (lie_submodule R L M)) : is_glb S (Inf S) :=
begin
have h : ∀ (N N' : lie_submodule R L M), (N : set M) ≤ N' ↔ N ≤ N', { intros, apply iff.rfl, },
simp only [is_glb.of_image h, Inf_coe, is_glb_binfi],
have h : ∀ (N N' : lie_submodule R L M), (N : set M) ≤ N' ↔ N ≤ N', { intros, refl },
apply is_glb.of_image h,
simp only [Inf_coe],
exact is_glb_binfi
end

/-- The set of Lie submodules of a Lie module form a complete lattice.
Expand Down
43 changes: 19 additions & 24 deletions src/data/finset/lattice.lean
Expand Up @@ -921,7 +921,7 @@ by simp

lemma supr_option_to_finset (o : option α) (f : α → β) :
(⨆ x ∈ o.to_finset, f x) = ⨆ x ∈ o, f x :=
by { congr, ext, rw [option.mem_to_finset] }
by simp

lemma infi_option_to_finset (o : option α) (f : α → β) :
(⨅ x ∈ o.to_finset, f x) = ⨅ x ∈ o, f x :=
Expand All @@ -935,15 +935,15 @@ by simp [supr_or, supr_sup_eq]

theorem infi_union {f : α → β} {s t : finset α} :
(⨅ x ∈ s ∪ t, f x) = (⨅ x ∈ s, f x) ⊓ (⨅ x ∈ t, f x) :=
by simp [infi_or, infi_inf_eq]
@supr_union α (order_dual β) _ _ _ _ _

lemma supr_insert (a : α) (s : finset α) (t : α → β) :
(⨆ x ∈ insert a s, t x) = t a ⊔ (⨆ x ∈ s, t x) :=
by { rw insert_eq, simp only [supr_union, finset.supr_singleton] }

lemma infi_insert (a : α) (s : finset α) (t : α → β) :
(⨅ x ∈ insert a s, t x) = t a ⊓ (⨅ x ∈ s, t x) :=
by { rw insert_eq, simp only [infi_union, finset.infi_singleton] }
@supr_insert α (order_dual β) _ _ _ _ _

lemma supr_finset_image {f : γ → α} {g : α → β} {s : finset γ} :
(⨆ x ∈ s.image f, g x) = (⨆ y ∈ s, g (f y)) :=
Expand All @@ -954,10 +954,7 @@ lemma sup_finset_image {β γ : Type*} [semilattice_sup_bot β]
(s.image f).sup g = s.sup (g ∘ f) :=
begin
classical,
apply finset.induction_on s,
{ simp },
{ intros a s' ha ih,
rw [sup_insert, image_insert, sup_insert, ih] }
induction s using finset.induction_on with a s' ha ih; simp *
end

lemma infi_finset_image {f : γ → α} {g : α → β} {s : finset γ} :
Expand All @@ -977,41 +974,39 @@ lemma infi_insert_update {x : α} {t : finset α} (f : α → β) {s : β} (hx :

lemma supr_bUnion (s : finset γ) (t : γ → finset α) (f : α → β) :
(⨆ y ∈ s.bUnion t, f y) = ⨆ (x ∈ s) (y ∈ t x), f y :=
calc (⨆ y ∈ s.bUnion t, f y) = ⨆ y (hy : ∃ x ∈ s, y ∈ t x), f y :
congr_arg _ $ funext $ λ y, by rw [mem_bUnion]
... = _ : by simp only [supr_exists, @supr_comm _ α]
by simp [@supr_comm _ α, supr_and]

lemma infi_bUnion (s : finset γ) (t : γ → finset α) (f : α → β) :
(⨅ y ∈ s.bUnion t, f y) = ⨅ (x ∈ s) (y ∈ t x), f y :=
@supr_bUnion _ (order_dual β) _ _ _ _ _ _

end lattice

@[simp] theorem set_bUnion_coe (s : finset α) (t : α → set β) :
theorem set_bUnion_coe (s : finset α) (t : α → set β) :
(⋃ x ∈ (↑s : set α), t x) = ⋃ x ∈ s, t x :=
rfl

@[simp] theorem set_bInter_coe (s : finset α) (t : α → set β) :
theorem set_bInter_coe (s : finset α) (t : α → set β) :
(⋂ x ∈ (↑s : set α), t x) = ⋂ x ∈ s, t x :=
rfl

@[simp] theorem set_bUnion_singleton (a : α) (s : α → set β) :
theorem set_bUnion_singleton (a : α) (s : α → set β) :
(⋃ x ∈ ({a} : finset α), s x) = s a :=
supr_singleton a s

@[simp] theorem set_bInter_singleton (a : α) (s : α → set β) :
theorem set_bInter_singleton (a : α) (s : α → set β) :
(⋂ x ∈ ({a} : finset α), s x) = s a :=
infi_singleton a s

@[simp] lemma set_bUnion_preimage_singleton (f : α → β) (s : finset β) :
(⋃ y ∈ s, f ⁻¹' {y}) = f ⁻¹' s :=
set.bUnion_preimage_singleton f s
(⋃ y ∈ s, f ⁻¹' {y}) = f ⁻¹' s :=
set.bUnion_preimage_singleton f s

@[simp] lemma set_bUnion_option_to_finset (o : option α) (f : α → set β) :
lemma set_bUnion_option_to_finset (o : option α) (f : α → set β) :
(⋃ x ∈ o.to_finset, f x) = ⋃ x ∈ o, f x :=
supr_option_to_finset o f

@[simp] lemma set_bInter_option_to_finset (o : option α) (f : α → set β) :
lemma set_bInter_option_to_finset (o : option α) (f : α → set β) :
(⋂ x ∈ o.to_finset, f x) = ⋂ x ∈ o, f x :=
infi_option_to_finset o f

Expand All @@ -1025,19 +1020,19 @@ lemma set_bInter_inter (s t : finset α) (u : α → set β) :
(⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) :=
infi_union

@[simp] lemma set_bUnion_insert (a : α) (s : finset α) (t : α → set β) :
lemma set_bUnion_insert (a : α) (s : finset α) (t : α → set β) :
(⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) :=
supr_insert a s t

@[simp] lemma set_bInter_insert (a : α) (s : finset α) (t : α → set β) :
lemma set_bInter_insert (a : α) (s : finset α) (t : α → set β) :
(⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) :=
infi_insert a s t

@[simp] lemma set_bUnion_finset_image {f : γ → α} {g : α → set β} {s : finset γ} :
lemma set_bUnion_finset_image {f : γ → α} {g : α → set β} {s : finset γ} :
(⋃x ∈ s.image f, g x) = (⋃y ∈ s, g (f y)) :=
supr_finset_image

@[simp] lemma set_bInter_finset_image {f : γ → α} {g : α → set β} {s : finset γ} :
lemma set_bInter_finset_image {f : γ → α} {g : α → set β} {s : finset γ} :
(⋂ x ∈ s.image f, g x) = (⋂ y ∈ s, g (f y)) :=
infi_finset_image

Expand All @@ -1049,11 +1044,11 @@ lemma set_bInter_insert_update {x : α} {t : finset α} (f : α → set β) {s :
(⋂ (i ∈ insert x t), @update _ _ _ f x s i) = (s ∩ ⋂ (i ∈ t), f i) :=
infi_insert_update f hx

@[simp] lemma set_bUnion_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) :
lemma set_bUnion_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) :
(⋃ y ∈ s.bUnion t, f y) = ⋃ (x ∈ s) (y ∈ t x), f y :=
supr_bUnion s t f

@[simp] lemma set_bInter_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) :
lemma set_bInter_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) :
(⋂ y ∈ s.bUnion t, f y) = ⋂ (x ∈ s) (y ∈ t x), f y :=
infi_bUnion s t f

Expand Down
7 changes: 3 additions & 4 deletions src/data/set/finite.lean
Expand Up @@ -585,10 +585,9 @@ lemma finite_subset_Union {s : set α} (hs : finite s)
begin
casesI hs,
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i, {simpa [subset_def] using h},
refine ⟨range f, finite_range f, _⟩,
rintro x hx,
simp,
exact ⟨x, ⟨hx, hf _⟩⟩,
refine ⟨range f, finite_range f, λ x hx, _⟩,
rw [bUnion_range, mem_Union],
exact ⟨⟨x, hx⟩, hf _⟩
end

lemma eq_finite_Union_of_finite_subset_Union {ι} {s : ι → set α} {t : set α} (tfin : finite t)
Expand Down

0 comments on commit d3c943b

Please sign in to comment.