Skip to content

Commit 002afcf

Browse files
timotree3YaelDilliesmattrobball
committed
feat: Small.{u} sets are closed under various operations (leanprover-community#11126)
This PR adds lemmas showing that sets constructed by applying basic set operations to small sets are themselves small. We now have corresponding `Small ↥s` versions of almost all of the `Finite ↥s` instances in the `Finite.Set` namespace. Co-authored-by: Yaël Dillies <yael.dillies@gmail.com> Co-authored-by: Matthew Ballard <matt@mrb.email>
1 parent 7eb3f52 commit 002afcf

File tree

2 files changed

+91
-11
lines changed

2 files changed

+91
-11
lines changed

Mathlib/Logic/Small/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ universe u w v v'
1616

1717
section
1818

19+
20+
-- TODO(timotree3): lower the priority on this instance?
21+
-- This instance applies to every synthesis problem of the form `Small ↥s` for some set `s`,
22+
-- but we have lots of instances of `Small` for specific set constructions.
1923
instance small_subtype (α : Type v) [Small.{w} α] (P : α → Prop) : Small.{w} { x // P x } :=
2024
small_map (equivShrink α).subtypeEquivOfSubtype'
2125

Mathlib/Logic/Small/Set.lean

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/-
22
Copyright (c) 2024 Markus Himmel. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Markus Himmel
4+
Authors: Markus Himmel, Timothy Carlin-Burns
55
-/
66
import Mathlib.Data.Set.Lattice
77
import Mathlib.Logic.Small.Basic
@@ -10,29 +10,105 @@ import Mathlib.Logic.Small.Basic
1010
# Results about `Small` on coerced sets
1111
-/
1212

13-
universe u v w
13+
universe u u1 u2 u3 u4
1414

15-
theorem small_subset {α : Type v} {s t : Set α} (hts : t ⊆ s) [Small.{u} s] : Small.{u} t :=
16-
let f : t → s := fun x => ⟨x, hts x.prop⟩
17-
@small_of_injective _ _ _ f fun _ _ hxy => Subtype.ext (Subtype.mk.inj hxy)
15+
variable {α : Type u1} {β : Type u2} {γ : Type u3} {ι : Type u4}
1816

19-
instance small_range {α : Type v} {β : Type w} (f : α → β) [Small.{u} α] :
17+
theorem small_subset {s t : Set α} (hts : t ⊆ s) [Small.{u} s] : Small.{u} t :=
18+
small_of_injective (Set.inclusion_injective hts)
19+
20+
instance small_powerset (s : Set α) [Small.{u} s] : Small.{u} (𝒫 s) :=
21+
small_map (Equiv.Set.powerset s)
22+
23+
instance small_setProd (s : Set α) (t : Set β) [Small.{u} s] [Small.{u} t] :
24+
Small.{u} (s ×ˢ t : Set (α × β)) :=
25+
small_of_injective (Equiv.Set.prod s t).injective
26+
27+
instance small_setPi {β : α → Type u2} (s : (a : α) → Set (β a))
28+
[Small.{u} α] [∀ a, Small.{u} (s a)] : Small.{u} (Set.pi Set.univ s) :=
29+
small_of_injective (Equiv.Set.univPi s).injective
30+
31+
instance small_range (f : α → β) [Small.{u} α] :
2032
Small.{u} (Set.range f) :=
2133
small_of_surjective Set.surjective_onto_range
2234

23-
instance small_image {α : Type v} {β : Type w} (f : α → β) (S : Set α) [Small.{u} S] :
24-
Small.{u} (f '' S) :=
35+
instance small_image (f : α → β) (s : Set α) [Small.{u} s] :
36+
Small.{u} (f '' s) :=
2537
small_of_surjective Set.surjective_onto_image
2638

27-
instance small_union {α : Type v} (s t : Set α) [Small.{u} s] [Small.{u} t] :
39+
instance small_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Small.{u} s] [Small.{u} t] :
40+
Small.{u} (Set.image2 f s t) := by
41+
rw [← Set.image_uncurry_prod]
42+
infer_instance
43+
44+
instance small_union (s t : Set α) [Small.{u} s] [Small.{u} t] :
2845
Small.{u} (s ∪ t : Set α) := by
2946
rw [← Subtype.range_val (s := s), ← Subtype.range_val (s := t), ← Set.Sum.elim_range]
3047
infer_instance
3148

32-
instance small_iUnion {α : Type v} {ι : Type w} [Small.{u} ι] (s : ι → Set α)
49+
instance small_iUnion [Small.{u} ι] (s : ι → Set α)
3350
[∀ i, Small.{u} (s i)] : Small.{u} (⋃ i, s i) :=
3451
small_of_surjective <| Set.sigmaToiUnion_surjective _
3552

36-
instance small_sUnion {α : Type v} (s : Set (Set α)) [Small.{u} s] [∀ t : s, Small.{u} t] :
53+
instance small_sUnion (s : Set (Set α)) [Small.{u} s] [∀ t : s, Small.{u} t] :
3754
Small.{u} (⋃₀ s) :=
3855
Set.sUnion_eq_iUnion ▸ small_iUnion _
56+
57+
instance small_biUnion (s : Set ι) [Small.{u} s]
58+
(f : (i : ι) → i ∈ s → Set α) [∀ i hi, Small.{u} (f i hi)] : Small.{u} (⋃ i, ⋃ hi, f i hi) :=
59+
Set.biUnion_eq_iUnion s f ▸ small_iUnion _
60+
61+
instance small_insert (x : α) (s : Set α) [Small.{u} s] :
62+
Small.{u} (insert x s : Set α) :=
63+
Set.insert_eq x s ▸ small_union.{u} {x} s
64+
65+
instance small_diff (s t : Set α) [Small.{u} s] : Small.{u} (s \ t : Set α) :=
66+
small_subset (Set.diff_subset)
67+
68+
instance small_sep (s : Set α) (P : α → Prop) [Small.{u} s] :
69+
Small.{u} { x | x ∈ s ∧ P x} :=
70+
small_subset (Set.sep_subset s P)
71+
72+
instance small_inter_of_left (s t : Set α) [Small.{u} s] :
73+
Small.{u} (s ∩ t : Set α) :=
74+
small_subset Set.inter_subset_left
75+
76+
instance small_inter_of_right (s t : Set α) [Small.{u} t] :
77+
Small.{u} (s ∩ t : Set α) :=
78+
small_subset Set.inter_subset_right
79+
80+
theorem small_iInter (s : ι → Set α) (i : ι)
81+
[Small.{u} (s i)] : Small.{u} (⋂ i, s i) :=
82+
small_subset (Set.iInter_subset s i)
83+
84+
instance small_iInter' [Nonempty ι] (s : ι → Set α)
85+
[∀ i, Small.{u} (s i)] : Small.{u} (⋂ i, s i) :=
86+
let ⟨i⟩ : Nonempty ι := inferInstance
87+
small_iInter s i
88+
89+
theorem small_sInter {s : Set (Set α)} {t : Set α} (ht : t ∈ s)
90+
[Small.{u} t] : Small.{u} (⋂₀ s) :=
91+
Set.sInter_eq_iInter ▸ small_iInter _ ⟨t, ht⟩
92+
93+
instance small_sInter' {s : Set (Set α)} [Nonempty s]
94+
[∀ t : s, Small.{u} t] : Small.{u} (⋂₀ s) :=
95+
let ⟨t⟩ : Nonempty s := inferInstance
96+
small_sInter t.prop
97+
98+
theorem small_biInter {s : Set ι} {i : ι} (hi : i ∈ s)
99+
(f : (i : ι) → i ∈ s → Set α) [Small.{u} (f i hi)] : Small.{u} (⋂ i, ⋂ hi, f i hi) :=
100+
Set.biInter_eq_iInter s f ▸ small_iInter _ ⟨i, hi⟩
101+
102+
instance small_biInter' (s : Set ι) [Nonempty s]
103+
(f : (i : ι) → i ∈ s → Set α) [∀ i hi, Small.{u} (f i hi)] : Small.{u} (⋂ i, ⋂ hi, f i hi) :=
104+
let ⟨t⟩ : Nonempty s := inferInstance
105+
small_biInter t.prop f
106+
107+
theorem small_empty : Small.{u} (∅ : Set α) :=
108+
inferInstance
109+
110+
theorem small_single (x : α) : Small.{u} ({x} : Set α) :=
111+
inferInstance
112+
113+
theorem small_pair (x y : α) : Small.{u} ({x, y} : Set α) :=
114+
inferInstance

0 commit comments

Comments
 (0)