|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Miguel Marco. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Miguel Marco |
| 5 | +-/ |
| 6 | +import Mathlib.Data.Set.Function |
| 7 | +import Mathlib.Data.Set.Functor |
| 8 | + |
| 9 | +/-! |
| 10 | +# Sets in subtypes |
| 11 | +
|
| 12 | +This file is about sets in `Set A` when `A` is a set. |
| 13 | +
|
| 14 | +It defines notation `↓∩` for sets in a type pulled down to sets in a subtype, as an inverse |
| 15 | +operation to the coercion that lifts sets in a subtype up to sets in the ambient type. |
| 16 | +
|
| 17 | +This module also provides lemmas for `↓∩` and this coercion. |
| 18 | +
|
| 19 | +## Notation |
| 20 | +
|
| 21 | +Let `α` be a `Type`, `A B : Set α` two sets in `α`, and `C : Set A` a set in the subtype `↑A`. |
| 22 | +
|
| 23 | +- `A ↓∩ B` denotes `(Subtype.val ⁻¹' B : Set A)` (that is, `{x : ↑A | ↑x ∈ B}`). |
| 24 | +- `↑C` denotes `Subtype.val '' C` (that is, `{x : α | ∃ y ∈ C, ↑y = x}`). |
| 25 | +
|
| 26 | +This notation, (together with the `↑` notation for `Set.CoeHead` in `Mathlib.Data.Set.Functor`) |
| 27 | +is scoped to the `Set.Notation` namespace. |
| 28 | +To enable it, use `open Set.Notation`. |
| 29 | +
|
| 30 | +
|
| 31 | +## Naming conventions |
| 32 | +
|
| 33 | +Theorem names refer to `↓∩` as `preimage_val`. |
| 34 | +
|
| 35 | +## Tags |
| 36 | +
|
| 37 | +subsets |
| 38 | +-/ |
| 39 | + |
| 40 | +open Set |
| 41 | + |
| 42 | +variable {ι : Sort*} {α : Type*} {A B C : Set α} {D E : Set A} |
| 43 | +variable {S : Set (Set α)} {T : Set (Set A)} {s : ι → Set α} {t : ι → Set A} |
| 44 | + |
| 45 | +namespace Set.Notation |
| 46 | + |
| 47 | +/-- |
| 48 | +Given two sets `A` and `B`, `A ↓∩ B` denotes the intersection of `A` and `B` as a set in `Set A`. |
| 49 | +
|
| 50 | +The notation is short for `((↑) ⁻¹' B : Set A)`, while giving hints to the elaborator |
| 51 | +that both `A` and `B` are terms of `Set α` for the same `α`. |
| 52 | +This set is the same as `{x : ↑A | ↑x ∈ B}`. |
| 53 | +-/ |
| 54 | +scoped notation3 A:67 " ↓∩ " B:67 => (Subtype.val ⁻¹' (B : type_of% A) : Set (A : Set _)) |
| 55 | + |
| 56 | +end Set.Notation |
| 57 | + |
| 58 | +namespace Set |
| 59 | + |
| 60 | +open Notation |
| 61 | + |
| 62 | +lemma preimage_val_eq_univ_of_subset (h : A ⊆ B) : A ↓∩ B = univ := by |
| 63 | + rw [eq_univ_iff_forall, Subtype.forall] |
| 64 | + exact h |
| 65 | + |
| 66 | +lemma preimage_val_sUnion : A ↓∩ (⋃₀ S) = ⋃₀ { (A ↓∩ B) | B ∈ S } := by |
| 67 | + erw [sUnion_image] |
| 68 | + simp_rw [sUnion_eq_biUnion, preimage_iUnion] |
| 69 | + |
| 70 | +@[simp] |
| 71 | +lemma preimage_val_iInter : A ↓∩ (⋂ i, s i) = ⋂ i, A ↓∩ s i := preimage_iInter |
| 72 | + |
| 73 | +lemma preimage_val_sInter : A ↓∩ (⋂₀ S) = ⋂₀ { (A ↓∩ B) | B ∈ S } := by |
| 74 | + erw [sInter_image] |
| 75 | + simp_rw [sInter_eq_biInter, preimage_iInter] |
| 76 | + |
| 77 | +lemma preimage_val_sInter_eq_sInter : A ↓∩ (⋂₀ S) = ⋂₀ ((A ↓∩ .) '' S) := by |
| 78 | + simp only [preimage_sInter, sInter_image] |
| 79 | + |
| 80 | +lemma eq_of_preimage_val_eq_of_subset (hB : B ⊆ A) (hC : C ⊆ A) (h : A ↓∩ B = A ↓∩ C) : B = C := by |
| 81 | + simp only [← inter_eq_right] at hB hC |
| 82 | + simp only [Subtype.preimage_val_eq_preimage_val_iff, hB, hC] at h |
| 83 | + exact h |
| 84 | + |
| 85 | +/-! |
| 86 | +The following simp lemmas try to transform operations in the subtype into operations in the ambient |
| 87 | +type, if possible. |
| 88 | +-/ |
| 89 | + |
| 90 | +@[simp] |
| 91 | +lemma image_val_union : (↑(D ∪ E) : Set α) = ↑D ∪ ↑E := image_union _ _ _ |
| 92 | + |
| 93 | +@[simp] |
| 94 | +lemma image_val_inter : (↑(D ∩ E) : Set α) = ↑D ∩ ↑E := image_inter Subtype.val_injective |
| 95 | + |
| 96 | +@[simp] |
| 97 | +lemma image_val_diff : (↑(D \ E) : Set α) = ↑D \ ↑E := image_diff Subtype.val_injective _ _ |
| 98 | + |
| 99 | +@[simp] |
| 100 | +lemma image_val_compl : ↑(Dᶜ) = A \ ↑D := by |
| 101 | + rw [compl_eq_univ_diff, image_val_diff, image_univ, Subtype.range_coe_subtype, setOf_mem_eq] |
| 102 | + |
| 103 | +@[simp] |
| 104 | +lemma image_val_sUnion : ↑(⋃₀ T) = ⋃₀ { (B : Set α) | B ∈ T} := by |
| 105 | + -- TODO: missing `image_sUnion` lemma |
| 106 | + erw [sUnion_image] |
| 107 | + simp_rw [sUnion_eq_biUnion, image_iUnion] |
| 108 | + |
| 109 | +@[simp] |
| 110 | +lemma image_val_iUnion : ↑(⋃ i, t i) = ⋃ i, (t i : Set α) := image_iUnion |
| 111 | + |
| 112 | +@[simp] |
| 113 | +lemma image_val_sInter (hT : T.Nonempty) : (↑(⋂₀ T) : Set α) = ⋂₀ { (↑B : Set α) | B ∈ T } := by |
| 114 | + erw [sInter_image] |
| 115 | + rw [sInter_eq_biInter, (Subtype.val_injective.injOn _).image_biInter_eq hT] |
| 116 | + |
| 117 | +@[simp] |
| 118 | +lemma image_val_iInter [Nonempty ι] : (↑(⋂ i, t i) : Set α) = ⋂ i, (↑(t i) : Set α) := |
| 119 | + (Subtype.val_injective.injOn _).image_iInter_eq |
| 120 | + |
| 121 | +@[simp] |
| 122 | +lemma image_val_union_self_right_eq : A ∪ ↑D = A := |
| 123 | + union_eq_left.2 image_val_subset |
| 124 | + |
| 125 | +@[simp] |
| 126 | +lemma image_val_union_self_left_eq : ↑D ∪ A = A := |
| 127 | + union_eq_right.2 image_val_subset |
| 128 | + |
| 129 | +@[simp] |
| 130 | +lemma cou_inter_self_right_eq_coe : A ∩ ↑D = ↑D := |
| 131 | + inter_eq_right.2 image_val_subset |
| 132 | + |
| 133 | +@[simp] |
| 134 | +lemma image_val_inter_self_left_eq_coe : ↑D ∩ A = ↑D := |
| 135 | + inter_eq_left.2 image_val_subset |
| 136 | + |
| 137 | +lemma subset_preimage_val_image_val_iff : D ⊆ A ↓∩ ↑E ↔ D ⊆ E := by |
| 138 | + rw [preimage_image_eq _ Subtype.val_injective] |
| 139 | + |
| 140 | +@[simp] |
| 141 | +lemma image_val_inj : (D : Set α) = ↑E ↔ D = E := Subtype.val_injective.image_injective.eq_iff |
| 142 | + |
| 143 | +lemma image_val_injective : Function.Injective ((↑) : Set A → Set α) := |
| 144 | + Subtype.val_injective.image_injective |
| 145 | + |
| 146 | +lemma subset_of_image_val_subset_image_val (h : (↑D : Set α) ⊆ ↑E) : D ⊆ E := |
| 147 | + (image_subset_image_iff Subtype.val_injective).1 h |
| 148 | + |
| 149 | +@[mono] |
| 150 | +lemma image_val_mono (h : D ⊆ E) : (↑D : Set α) ⊆ ↑E := |
| 151 | + (image_subset_image_iff Subtype.val_injective).2 h |
| 152 | + |
| 153 | +/-! |
| 154 | +Relations between restriction and coercion. |
| 155 | +-/ |
| 156 | + |
| 157 | +lemma image_val_preimage_val_subset_self : ↑(A ↓∩ B) ⊆ B := |
| 158 | + image_preimage_subset _ _ |
| 159 | + |
| 160 | +lemma preimage_val_image_val_eq_self : A ↓∩ ↑D = D := |
| 161 | + Function.Injective.preimage_image Subtype.val_injective _ |
| 162 | + |
| 163 | +end Set |
0 commit comments