Skip to content

Commit 899a433

Browse files
committed
feat(Order/UpperLower/Basic): use to_dual - part 1 (leanprover-community#33950)
1 parent 25ea657 commit 899a433

1 file changed

Lines changed: 26 additions & 95 deletions

File tree

Mathlib/Order/UpperLower/Basic.lean

Lines changed: 26 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -35,132 +35,83 @@ section LE
3535

3636
variable [LE α] {s t : Set α} {a : α}
3737

38+
@[to_dual]
3839
theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id
3940

40-
theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id
41-
41+
@[to_dual]
4242
theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id
4343

44-
theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id
45-
44+
@[to_dual]
4645
theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
4746

48-
theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
49-
50-
@[simp]
47+
@[to_dual (attr := simp)]
5148
theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s :=
5249
fun h => by
5350
convert h.compl
5451
rw [compl_compl], IsLowerSet.compl⟩
5552

56-
@[simp]
57-
theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s :=
58-
fun h => by
59-
convert h.compl
60-
rw [compl_compl], IsUpperSet.compl⟩
61-
53+
@[to_dual]
6254
theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) :=
6355
fun _ _ h => Or.imp (hs h) (ht h)
6456

65-
theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) :=
66-
fun _ _ h => Or.imp (hs h) (ht h)
67-
57+
@[to_dual]
6858
theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) :=
6959
fun _ _ h => And.imp (hs h) (ht h)
7060

71-
theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) :=
72-
fun _ _ h => And.imp (hs h) (ht h)
73-
61+
@[to_dual]
7462
theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) :=
7563
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2
7664

77-
theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) :=
78-
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2
79-
65+
@[to_dual]
8066
theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) :=
8167
isUpperSet_sUnion <| forall_mem_range.2 hf
8268

83-
theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) :=
84-
isLowerSet_sUnion <| forall_mem_range.2 hf
85-
69+
@[to_dual]
8670
theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
8771
IsUpperSet (⋃ (i) (j), f i j) :=
8872
isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i
8973

90-
theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) :
91-
IsLowerSet (⋃ (i) (j), f i j) :=
92-
isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i
93-
74+
@[to_dual]
9475
theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) :=
9576
fun _ _ h => forall₂_imp fun s hs => hf s hs h
9677

97-
theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) :=
98-
fun _ _ h => forall₂_imp fun s hs => hf s hs h
99-
78+
@[to_dual]
10079
theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) :=
10180
isUpperSet_sInter <| forall_mem_range.2 hf
10281

103-
theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) :=
104-
isLowerSet_sInter <| forall_mem_range.2 hf
105-
82+
@[to_dual]
10683
theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
10784
IsUpperSet (⋂ (i) (j), f i j) :=
10885
isUpperSet_iInter fun i => isUpperSet_iInter <| hf i
10986

110-
theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) :
111-
IsLowerSet (⋂ (i) (j), f i j) :=
112-
isLowerSet_iInter fun i => isLowerSet_iInter <| hf i
113-
114-
@[simp]
115-
theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s :=
116-
Iff.rfl
117-
118-
@[simp]
87+
@[to_dual (attr := simp)]
11988
theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s :=
12089
Iff.rfl
12190

122-
@[simp]
123-
theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s :=
124-
Iff.rfl
125-
126-
@[simp]
91+
@[to_dual (attr := simp)]
12792
theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s :=
12893
Iff.rfl
12994

130-
alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff
131-
132-
alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff
133-
134-
alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff
135-
136-
alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff
95+
@[to_dual] alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff
96+
@[to_dual] alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff
13797

98+
@[to_dual]
13899
lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) :
139100
IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop
140101

141-
lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) :
142-
IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop
143-
102+
@[to_dual]
144103
lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) :
145104
IsUpperSet (s \ t) :=
146105
fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩
147106

148-
lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) :
149-
IsLowerSet (s \ t) :=
150-
fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩
151-
107+
@[to_dual]
152108
lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) :=
153109
hs.sdiff <| by aesop
154110

155-
lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) :=
156-
hs.sdiff <| by aesop
157-
111+
@[to_dual]
158112
lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) :=
159113
hs.sdiff <| by simpa using has
160114

161-
lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) :=
162-
hs.sdiff <| by simpa using has
163-
164115
end LE
165116

166117
section Preorder
@@ -203,16 +154,12 @@ theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f
203154
theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) :
204155
IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h
205156

157+
@[to_dual]
206158
theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by
207159
change IsUpperSet ((f : α ≃ β) '' s)
208160
rw [Equiv.image_eq_preimage_symm]
209161
exact hs.preimage f.symm.monotone
210162

211-
theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by
212-
change IsLowerSet ((f : α ≃ β) '' s)
213-
rw [Equiv.image_eq_preimage_symm]
214-
exact hs.preimage f.symm.monotone
215-
216163
theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) :
217164
e '' Ici a = Ici (e a) := by
218165
rw [← e.preimage_Ici, image_preimage_eq_inter_range,
@@ -257,32 +204,20 @@ section OrderTop
257204

258205
variable [OrderTop α]
259206

207+
@[to_dual]
260208
theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ :=
261209
fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩
262210

211+
@[to_dual]
263212
theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty :=
264213
fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩
265214

215+
@[to_dual]
266216
theorem IsUpperSet.top_notMem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ :=
267217
hs.top_mem.not.trans not_nonempty_iff_eq_empty
268218

269219
end OrderTop
270220

271-
section OrderBot
272-
273-
variable [OrderBot α]
274-
275-
theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ :=
276-
fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩
277-
278-
theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty :=
279-
fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩
280-
281-
theorem IsLowerSet.bot_notMem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ :=
282-
hs.bot_mem.not.trans not_nonempty_iff_eq_empty
283-
284-
end OrderBot
285-
286221
section NoMaxOrder
287222

288223
variable [NoMaxOrder α]
@@ -323,12 +258,10 @@ section PartialOrder
323258

324259
variable [PartialOrder α] {s : Set α}
325260

261+
@[to_dual]
326262
theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s :=
327263
forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and]
328264

329-
theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s :=
330-
forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and]
331-
332265
theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by
333266
simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)]
334267

@@ -341,6 +274,7 @@ section LinearOrder
341274

342275
variable [LinearOrder α] {s t : Set α}
343276

277+
@[to_dual]
344278
theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by
345279
by_contra! h
346280
simp_rw [Set.not_subset] at h
@@ -349,9 +283,6 @@ theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t
349283
· exact hbs (hs hab has)
350284
· exact hat (ht hba hbt)
351285

352-
theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s :=
353-
hs.toDual.total ht.toDual
354-
355286
theorem IsUpperSet.eq_empty_or_Ici [WellFoundedLT α] (h : IsUpperSet s) :
356287
s = ∅ ∨ (∃ a, s = Set.Ici a) := by
357288
refine or_iff_not_imp_left.2 fun ha ↦ ?_

0 commit comments

Comments
 (0)