Skip to content

Commit 4c9893d

Browse files
committed
chore(Order/Interval/Set/WithBotTop): use to_dual (leanprover-community#38240)
1 parent 30d2c5f commit 4c9893d

4 files changed

Lines changed: 50 additions & 168 deletions

File tree

Mathlib/Order/Cover.lean

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ instance CovBy.irrefl : @Std.Irrefl α (· ⋖ ·) :=
315315
theorem CovBy.Ioo_eq (h : a ⋖ b) : Ioo a b = ∅ :=
316316
h.wcovBy.Ioo_eq
317317

318+
@[to_dual self]
318319
theorem covBy_iff_Ioo_eq : a ⋖ b ↔ a < b ∧ Ioo a b = ∅ :=
319320
and_congr_right' <| by simp [eq_empty_iff_forall_notMem]
320321

@@ -739,44 +740,26 @@ namespace WithTop
739740

740741
variable [Preorder α] {a b : α}
741742

742-
@[simp, norm_cast] lemma coe_wcovBy_coe : (a : WithTop α) ⩿ b ↔ a ⩿ b :=
743+
@[to_dual (attr := simp, norm_cast)]
744+
lemma coe_wcovBy_coe : (a : WithTop α) ⩿ b ↔ a ⩿ b :=
743745
Set.OrdConnected.apply_wcovBy_apply_iff WithTop.coeOrderHom <| by
744746
simp [WithTop.range_coe, ordConnected_Iio]
745747

746-
@[simp, norm_cast] lemma coe_covBy_coe : (a : WithTop α) ⋖ b ↔ a ⋖ b :=
748+
@[to_dual (attr := simp, norm_cast)]
749+
lemma coe_covBy_coe : (a : WithTop α) ⋖ b ↔ a ⋖ b :=
747750
Set.OrdConnected.apply_covBy_apply_iff WithTop.coeOrderHom <| by
748751
simp [WithTop.range_coe, ordConnected_Iio]
749752

750-
@[simp] lemma coe_covBy_top : (a : WithTop α) ⋖ ⊤ ↔ IsMax a := by
751-
simp only [covBy_iff_Ioo_eq, ← image_coe_Ioi, coe_lt_top, image_eq_empty,
752-
true_and, Ioi_eq_empty_iff]
753+
@[to_dual (attr := simp) bot_covBy_coe]
754+
lemma coe_covBy_top : (a : WithTop α) ⋖ ⊤ ↔ IsMax a := by
755+
simp [covBy_iff_Ioo_eq, ← image_coe_Ioi]
753756

754-
@[simp] lemma coe_wcovBy_top : (a : WithTop α) ⩿ ⊤ ↔ IsMax a := by
757+
@[to_dual (attr := simp) bot_wcovBy_coe]
758+
lemma coe_wcovBy_top : (a : WithTop α) ⩿ ⊤ ↔ IsMax a := by
755759
simp only [wcovBy_iff_Ioo_eq, ← image_coe_Ioi, le_top, image_eq_empty, true_and, Ioi_eq_empty_iff]
756760

757761
end WithTop
758762

759-
namespace WithBot
760-
761-
variable [Preorder α] {a b : α}
762-
763-
@[simp, norm_cast] lemma coe_wcovBy_coe : (a : WithBot α) ⩿ b ↔ a ⩿ b :=
764-
Set.OrdConnected.apply_wcovBy_apply_iff WithBot.coeOrderHom <| by
765-
simp [WithBot.range_coe, ordConnected_Ioi]
766-
767-
@[simp, norm_cast] lemma coe_covBy_coe : (a : WithBot α) ⋖ b ↔ a ⋖ b :=
768-
Set.OrdConnected.apply_covBy_apply_iff WithBot.coeOrderHom <| by
769-
simp [WithBot.range_coe, ordConnected_Ioi]
770-
771-
@[simp] lemma bot_covBy_coe : ⊥ ⋖ (a : WithBot α) ↔ IsMin a := by
772-
simp only [covBy_iff_Ioo_eq, ← image_coe_Iio, bot_lt_coe, image_eq_empty,
773-
true_and, Iio_eq_empty_iff]
774-
775-
@[simp] lemma bot_wcovBy_coe : ⊥ ⩿ (a : WithBot α) ↔ IsMin a := by
776-
simp only [wcovBy_iff_Ioo_eq, ← image_coe_Iio, bot_le, image_eq_empty, true_and, Iio_eq_empty_iff]
777-
778-
end WithBot
779-
780763
section WellFounded
781764

782765
variable [Preorder α]

Mathlib/Order/Interval/Set/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class OrdConnected (s : Set α) : Prop where
8888
/-- `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. -/
8989
out' ⦃x : α⦄ (hx : x ∈ s) ⦃y : α⦄ (hy : y ∈ s) : Icc x y ⊆ s
9090

91+
attribute [to_dual self (reorder := out' (x y, hx hy))] OrdConnected.mk
9192
attribute [to_dual self (reorder := x y, hx hy)] OrdConnected.out'
9293

9394
end Set

Mathlib/Order/Interval/Set/OrdConnected.lean

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,36 +165,24 @@ instance ordConnected_pi' {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α
165165
{t : ∀ i, Set (α i)} [h : ∀ i, OrdConnected (t i)] : OrdConnected (s.pi t) :=
166166
ordConnected_pi fun i _ => h i
167167

168-
@[instance]
169-
theorem ordConnected_Ici {a : α} : OrdConnected (Ici a) :=
168+
@[to_dual]
169+
instance ordConnected_Ici {a : α} : OrdConnected (Ici a) :=
170170
fun _ hx _ _ _ hz => le_trans hx hz.1
171171

172-
@[instance]
173-
theorem ordConnected_Iic {a : α} : OrdConnected (Iic a) :=
174-
fun _ _ _ hy _ hz => le_trans hz.2 hy⟩
175-
176-
@[instance]
177-
theorem ordConnected_Ioi {a : α} : OrdConnected (Ioi a) :=
172+
@[to_dual]
173+
instance ordConnected_Ioi {a : α} : OrdConnected (Ioi a) :=
178174
fun _ hx _ _ _ hz => lt_of_lt_of_le hx hz.1
179175

180-
@[instance]
181-
theorem ordConnected_Iio {a : α} : OrdConnected (Iio a) :=
182-
fun _ _ _ hy _ hz => lt_of_le_of_lt hz.2 hy⟩
183-
184-
@[instance]
185-
theorem ordConnected_Icc {a b : α} : OrdConnected (Icc a b) :=
176+
@[to_dual self]
177+
instance ordConnected_Icc {a b : α} : OrdConnected (Icc a b) :=
186178
ordConnected_Ici.inter ordConnected_Iic
187179

188-
@[instance]
189-
theorem ordConnected_Ico {a b : α} : OrdConnected (Ico a b) :=
180+
@[to_dual]
181+
instance ordConnected_Ico {a b : α} : OrdConnected (Ico a b) :=
190182
ordConnected_Ici.inter ordConnected_Iio
191183

192-
@[instance]
193-
theorem ordConnected_Ioc {a b : α} : OrdConnected (Ioc a b) :=
194-
ordConnected_Ioi.inter ordConnected_Iic
195-
196-
@[instance]
197-
theorem ordConnected_Ioo {a b : α} : OrdConnected (Ioo a b) :=
184+
@[to_dual self]
185+
instance ordConnected_Ioo {a b : α} : OrdConnected (Ioo a b) :=
198186
ordConnected_Ioi.inter ordConnected_Iio
199187

200188
@[instance]

Mathlib/Order/Interval/Set/WithBotTop.lean

Lines changed: 29 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -22,212 +22,122 @@ open Set
2222

2323
variable {α : Type*}
2424

25-
/-! ### `WithTop` -/
26-
2725
namespace WithTop
2826

29-
@[simp]
27+
@[to_dual (attr := simp)]
3028
theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊤} = (∅ : Set α) :=
3129
eq_empty_of_subset_empty fun _ => coe_ne_top
3230

3331
variable [Preorder α] {a b : α}
3432

33+
@[to_dual]
3534
theorem range_coe : range (some : α → WithTop α) = Iio ⊤ := by
3635
ext; simp [mem_range, WithTop.lt_top_iff_ne_top, ne_top_iff_exists]
3736

38-
@[simp]
37+
@[to_dual (attr := simp)]
3938
theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a :=
4039
ext fun _ => coe_lt_coe
4140

42-
@[simp]
41+
@[to_dual (attr := simp)]
4342
theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a :=
4443
ext fun _ => coe_le_coe
4544

46-
@[simp]
45+
@[to_dual (attr := simp)]
4746
theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a :=
4847
ext fun _ => coe_lt_coe
4948

50-
@[simp]
49+
@[to_dual (attr := simp)]
5150
theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a :=
5251
ext fun _ => coe_le_coe
5352

54-
@[simp]
53+
@[to_dual (attr := simp)]
5554
theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic]
5655

57-
@[simp]
56+
@[to_dual (attr := simp)]
5857
theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio]
5958

60-
@[simp]
59+
@[to_dual (attr := simp)]
6160
theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic]
6261

63-
@[simp]
62+
@[to_dual (attr := simp)]
6463
theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio]
6564

66-
@[simp]
65+
@[to_dual (attr := simp)]
6766
theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊤ = univ := by
6867
rw [← range_coe, preimage_range]
6968

70-
@[simp]
69+
@[to_dual (attr := simp)]
7170
theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊤ = Ici a := by
7271
simp [← Ici_inter_Iio]
7372

74-
@[simp]
73+
@[to_dual (attr := simp)]
7574
theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊤ = Ioi a := by
7675
simp [← Ioi_inter_Iio]
7776

77+
@[to_dual]
7878
theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊤ := by
7979
rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio]
8080

81+
@[to_dual]
8182
theorem image_coe_Ici : (some : α → WithTop α) '' Ici a = Ico (a : WithTop α) ⊤ := by
8283
rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, Ici_inter_Iio]
8384

85+
@[to_dual]
8486
theorem image_coe_Iio : (some : α → WithTop α) '' Iio a = Iio (a : WithTop α) := by
8587
rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe,
8688
inter_eq_self_of_subset_left (Iio_subset_Iio le_top)]
8789

90+
@[to_dual]
8891
theorem image_coe_Iic : (some : α → WithTop α) '' Iic a = Iic (a : WithTop α) := by
8992
rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe,
9093
inter_eq_self_of_subset_left (Iic_subset_Iio.2 <| coe_lt_top a)]
9194

95+
@[to_dual]
9296
theorem image_coe_Icc : (some : α → WithTop α) '' Icc a b = Icc (a : WithTop α) b := by
9397
rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe,
9498
inter_eq_self_of_subset_left
9599
(Subset.trans Icc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)]
96100

101+
@[to_dual]
97102
theorem image_coe_Ico : (some : α → WithTop α) '' Ico a b = Ico (a : WithTop α) b := by
98103
rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe,
99104
inter_eq_self_of_subset_left (Subset.trans Ico_subset_Iio_self <| Iio_subset_Iio le_top)]
100105

106+
@[to_dual]
101107
theorem image_coe_Ioc : (some : α → WithTop α) '' Ioc a b = Ioc (a : WithTop α) b := by
102108
rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe,
103109
inter_eq_self_of_subset_left
104110
(Subset.trans Ioc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)]
105111

112+
@[to_dual]
106113
theorem image_coe_Ioo : (some : α → WithTop α) '' Ioo a b = Ioo (a : WithTop α) b := by
107114
rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe,
108115
inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Iio_self <| Iio_subset_Iio le_top)]
109116

117+
@[to_dual]
110118
theorem Ioi_coe : Ioi (a : WithTop α) = (↑) '' (Ioi a) ∪ {⊤} := by
111119
ext x; induction x <;> simp
112120

121+
@[to_dual]
113122
theorem Ici_coe : Ici (a : WithTop α) = (↑) '' (Ici a) ∪ {⊤} := by
114123
ext x; induction x <;> simp
115124

125+
@[to_dual]
116126
theorem Iio_coe : Iio (a : WithTop α) = (↑) '' (Iio a) := image_coe_Iio.symm
117127

128+
@[to_dual]
118129
theorem Iic_coe : Iic (a : WithTop α) = (↑) '' (Iic a) := image_coe_Iic.symm
119130

131+
@[to_dual]
120132
theorem Icc_coe : Icc (a : WithTop α) b = (↑) '' (Icc a b) := image_coe_Icc.symm
121133

134+
@[to_dual]
122135
theorem Ico_coe : Ico (a : WithTop α) b = (↑) '' (Ico a b) := image_coe_Ico.symm
123136

137+
@[to_dual]
124138
theorem Ioc_coe : Ioc (a : WithTop α) b = (↑) '' (Ioc a b) := image_coe_Ioc.symm
125139

140+
@[to_dual]
126141
theorem Ioo_coe : Ioo (a : WithTop α) b = (↑) '' (Ioo a b) := image_coe_Ioo.symm
127142

128143
end WithTop
129-
130-
/-! ### `WithBot` -/
131-
132-
namespace WithBot
133-
134-
@[simp]
135-
theorem preimage_coe_bot : (some : α → WithBot α) ⁻¹' {⊥} = (∅ : Set α) :=
136-
@WithTop.preimage_coe_top αᵒᵈ
137-
138-
variable [Preorder α] {a b : α}
139-
140-
theorem range_coe : range (some : α → WithBot α) = Ioi ⊥ := by
141-
ext; simp [mem_range, WithBot.bot_lt_iff_ne_bot, ne_bot_iff_exists]
142-
143-
@[simp]
144-
theorem preimage_coe_Ioi : (some : α → WithBot α) ⁻¹' Ioi a = Ioi a :=
145-
ext fun _ => coe_lt_coe
146-
147-
@[simp]
148-
theorem preimage_coe_Ici : (some : α → WithBot α) ⁻¹' Ici a = Ici a :=
149-
ext fun _ => coe_le_coe
150-
151-
@[simp]
152-
theorem preimage_coe_Iio : (some : α → WithBot α) ⁻¹' Iio a = Iio a :=
153-
ext fun _ => coe_lt_coe
154-
155-
@[simp]
156-
theorem preimage_coe_Iic : (some : α → WithBot α) ⁻¹' Iic a = Iic a :=
157-
ext fun _ => coe_le_coe
158-
159-
@[simp]
160-
theorem preimage_coe_Icc : (some : α → WithBot α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic]
161-
162-
@[simp]
163-
theorem preimage_coe_Ico : (some : α → WithBot α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio]
164-
165-
@[simp]
166-
theorem preimage_coe_Ioc : (some : α → WithBot α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic]
167-
168-
@[simp]
169-
theorem preimage_coe_Ioo : (some : α → WithBot α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio]
170-
171-
@[simp]
172-
theorem preimage_coe_Ioi_bot : (some : α → WithBot α) ⁻¹' Ioi ⊥ = univ := by
173-
rw [← range_coe, preimage_range]
174-
175-
@[simp]
176-
theorem preimage_coe_Ioc_bot : (some : α → WithBot α) ⁻¹' Ioc ⊥ a = Iic a := by
177-
simp [← Ioi_inter_Iic]
178-
179-
@[simp]
180-
theorem preimage_coe_Ioo_bot : (some : α → WithBot α) ⁻¹' Ioo ⊥ a = Iio a := by
181-
simp [← Ioi_inter_Iio]
182-
183-
theorem image_coe_Iio : (some : α → WithBot α) '' Iio a = Ioo (⊥ : WithBot α) a := by
184-
rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iio]
185-
186-
theorem image_coe_Iic : (some : α → WithBot α) '' Iic a = Ioc (⊥ : WithBot α) a := by
187-
rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iic]
188-
189-
theorem image_coe_Ioi : (some : α → WithBot α) '' Ioi a = Ioi (a : WithBot α) := by
190-
rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe,
191-
inter_eq_self_of_subset_left (Ioi_subset_Ioi bot_le)]
192-
193-
theorem image_coe_Ici : (some : α → WithBot α) '' Ici a = Ici (a : WithBot α) := by
194-
rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe,
195-
inter_eq_self_of_subset_left (Ici_subset_Ioi.2 <| bot_lt_coe a)]
196-
197-
theorem image_coe_Icc : (some : α → WithBot α) '' Icc a b = Icc (a : WithBot α) b := by
198-
rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe,
199-
inter_eq_self_of_subset_left
200-
(Subset.trans Icc_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)]
201-
202-
theorem image_coe_Ioc : (some : α → WithBot α) '' Ioc a b = Ioc (a : WithBot α) b := by
203-
rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe,
204-
inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Ioi_self <| Ioi_subset_Ioi bot_le)]
205-
206-
theorem image_coe_Ico : (some : α → WithBot α) '' Ico a b = Ico (a : WithBot α) b := by
207-
rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe,
208-
inter_eq_self_of_subset_left
209-
(Subset.trans Ico_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)]
210-
211-
theorem image_coe_Ioo : (some : α → WithBot α) '' Ioo a b = Ioo (a : WithBot α) b := by
212-
rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe,
213-
inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Ioi_self <| Ioi_subset_Ioi bot_le)]
214-
215-
theorem Ioi_coe : Ioi (a : WithBot α) = (↑) '' (Ioi a) := image_coe_Ioi.symm
216-
217-
theorem Ici_coe : Ici (a : WithBot α) = (↑) '' (Ici a) := image_coe_Ici.symm
218-
219-
theorem Iio_coe : Iio (a : WithBot α) = (↑) '' (Iio a) ∪ {⊥} := by
220-
ext x; induction x <;> simp
221-
222-
theorem Iic_coe : Iic (a : WithBot α) = (↑) '' (Iic a) ∪ {⊥} := by
223-
ext x; induction x <;> simp
224-
225-
theorem Icc_coe : Icc (a : WithBot α) b = (↑) '' (Icc a b) := image_coe_Icc.symm
226-
227-
theorem Ico_coe : Ico (a : WithBot α) b = (↑) '' (Ico a b) := image_coe_Ico.symm
228-
229-
theorem Ioc_coe : Ioc (a : WithBot α) b = (↑) '' (Ioc a b) := image_coe_Ioc.symm
230-
231-
theorem Ioo_coe : Ioo (a : WithBot α) b = (↑) '' (Ioo a b) := image_coe_Ioo.symm
232-
233-
end WithBot

0 commit comments

Comments
 (0)