-
Notifications
You must be signed in to change notification settings - Fork 383
/
Copy pathWithBot.lean
1220 lines (909 loc) · 42.6 KB
/
WithBot.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Init.Algebra.Classes
import Mathlib.Logic.Nontrivial.Basic
import Mathlib.Order.BoundedOrder
import Mathlib.Data.Option.NAry
import Mathlib.Tactic.Lift
import Mathlib.Data.Option.Basic
/-!
# `WithBot`, `WithTop`
Adding a `bot` or a `top` to an order.
## Main declarations
* `With<Top/Bot> α`: Equips `Option α` with the order on `α` plus `none` as the top/bottom element.
-/
variable {α β γ δ : Type*}
/-- Attach `⊥` to a type. -/
def WithBot (α : Type*) :=
Option α
namespace WithBot
variable {a b : α}
instance [Repr α] : Repr (WithBot α) :=
⟨fun o _ =>
match o with
| none => "⊥"
| some a => "↑" ++ repr a⟩
/-- The canonical map from `α` into `WithBot α` -/
@[coe, match_pattern] def some : α → WithBot α :=
Option.some
-- Porting note: changed this from `CoeTC` to `Coe` but I am not 100% confident that's correct.
instance coe : Coe α (WithBot α) :=
⟨some⟩
instance bot : Bot (WithBot α) :=
⟨none⟩
instance inhabited : Inhabited (WithBot α) :=
⟨⊥⟩
instance nontrivial [Nonempty α] : Nontrivial (WithBot α) :=
Option.nontrivial
open Function
theorem coe_injective : Injective ((↑) : α → WithBot α) :=
Option.some_injective _
@[simp, norm_cast]
theorem coe_inj : (a : WithBot α) = b ↔ a = b :=
Option.some_inj
protected theorem «forall» {p : WithBot α → Prop} : (∀ x, p x) ↔ p ⊥ ∧ ∀ x : α, p x :=
Option.forall
protected theorem «exists» {p : WithBot α → Prop} : (∃ x, p x) ↔ p ⊥ ∨ ∃ x : α, p x :=
Option.exists
theorem none_eq_bot : (none : WithBot α) = (⊥ : WithBot α) :=
rfl
theorem some_eq_coe (a : α) : (Option.some a : WithBot α) = (↑a : WithBot α) :=
rfl
@[simp]
theorem bot_ne_coe : ⊥ ≠ (a : WithBot α) :=
nofun
@[simp]
theorem coe_ne_bot : (a : WithBot α) ≠ ⊥ :=
nofun
/-- Recursor for `WithBot` using the preferred forms `⊥` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recBotCoe {C : WithBot α → Sort*} (bot : C ⊥) (coe : ∀ a : α, C a) : ∀ n : WithBot α, C n
| ⊥ => bot
| (a : α) => coe a
@[simp]
theorem recBotCoe_bot {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) :
@recBotCoe _ C d f ⊥ = d :=
rfl
@[simp]
theorem recBotCoe_coe {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) (x : α) :
@recBotCoe _ C d f ↑x = f x :=
rfl
/-- Specialization of `Option.getD` to values in `WithBot α` that respects API boundaries.
-/
def unbot' (d : α) (x : WithBot α) : α :=
recBotCoe d id x
@[simp]
theorem unbot'_bot {α} (d : α) : unbot' d ⊥ = d :=
rfl
@[simp]
theorem unbot'_coe {α} (d x : α) : unbot' d x = x :=
rfl
theorem coe_eq_coe : (a : WithBot α) = b ↔ a = b := coe_inj
theorem unbot'_eq_iff {d y : α} {x : WithBot α} : unbot' d x = y ↔ x = y ∨ x = ⊥ ∧ y = d := by
induction x <;> simp [@eq_comm _ d]
@[simp] theorem unbot'_eq_self_iff {d : α} {x : WithBot α} : unbot' d x = d ↔ x = d ∨ x = ⊥ := by
simp [unbot'_eq_iff]
theorem unbot'_eq_unbot'_iff {d : α} {x y : WithBot α} :
unbot' d x = unbot' d y ↔ x = y ∨ x = d ∧ y = ⊥ ∨ x = ⊥ ∧ y = d := by
induction y <;> simp [unbot'_eq_iff, or_comm]
/-- Lift a map `f : α → β` to `WithBot α → WithBot β`. Implemented using `Option.map`. -/
def map (f : α → β) : WithBot α → WithBot β :=
Option.map f
@[simp]
theorem map_bot (f : α → β) : map f ⊥ = ⊥ :=
rfl
@[simp]
theorem map_coe (f : α → β) (a : α) : map f a = f a :=
rfl
theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ}
(h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) :
map g₁ (map f₁ a) = map g₂ (map f₂ a) :=
Option.map_comm h _
/-- The image of a binary function `f : α → β → γ` as a function
`WithBot α → WithBot β → WithBot γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ : (α → β → γ) → WithBot α → WithBot β → WithBot γ := Option.map₂
lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl
@[simp] lemma map₂_bot_left (f : α → β → γ) (b) : map₂ f ⊥ b = ⊥ := rfl
@[simp] lemma map₂_bot_right (f : α → β → γ) (a) : map₂ f a ⊥ = ⊥ := by cases a <;> rfl
@[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl
@[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by
cases a <;> rfl
@[simp] lemma map₂_eq_bot_iff {f : α → β → γ} {a : WithBot α} {b : WithBot β} :
map₂ f a b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := Option.map₂_eq_none_iff
lemma ne_bot_iff_exists {x : WithBot α} : x ≠ ⊥ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists
lemma forall_ne_iff_eq_bot {x : WithBot α} : (∀ a : α, ↑a ≠ x) ↔ x = ⊥ :=
Option.forall_some_ne_iff_eq_none
/-- Deconstruct a `x : WithBot α` to the underlying value in `α`, given a proof that `x ≠ ⊥`. -/
def unbot : ∀ x : WithBot α, x ≠ ⊥ → α | (x : α), _ => x
@[simp] lemma coe_unbot : ∀ (x : WithBot α) hx, x.unbot hx = x | (x : α), _ => rfl
@[simp]
theorem unbot_coe (x : α) (h : (x : WithBot α) ≠ ⊥ := coe_ne_bot) : (x : WithBot α).unbot h = x :=
rfl
instance canLift : CanLift (WithBot α) α (↑) fun r => r ≠ ⊥ where
prf x h := ⟨x.unbot h, coe_unbot _ _⟩
instance instTop [Top α] : Top (WithBot α) where
top := (⊤ : α)
@[simp, norm_cast] lemma coe_top [Top α] : ((⊤ : α) : WithBot α) = ⊤ := rfl
@[simp, norm_cast] lemma coe_eq_top [Top α] {a : α} : (a : WithBot α) = ⊤ ↔ a = ⊤ := coe_eq_coe
@[simp, norm_cast] lemma top_eq_coe [Top α] {a : α} : ⊤ = (a : WithBot α) ↔ ⊤ = a := coe_eq_coe
section LE
variable [LE α]
instance (priority := 10) le : LE (WithBot α) :=
⟨fun o₁ o₂ => ∀ a : α, o₁ = ↑a → ∃ b : α, o₂ = ↑b ∧ a ≤ b⟩
@[simp, norm_cast]
theorem coe_le_coe : (a : WithBot α) ≤ b ↔ a ≤ b := by
simp [LE.le]
instance orderBot : OrderBot (WithBot α) where
bot_le _ := fun _ h => Option.noConfusion h
@[simp, deprecated coe_le_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem some_le_some : @LE.le (WithBot α) _ (Option.some a) (Option.some b) ↔ a ≤ b :=
coe_le_coe
@[simp, deprecated bot_le "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem none_le {a : WithBot α} : @LE.le (WithBot α) _ none a := bot_le
instance orderTop [OrderTop α] : OrderTop (WithBot α) where
le_top o a ha := by cases ha; exact ⟨_, rfl, le_top⟩
instance instBoundedOrder [OrderTop α] : BoundedOrder (WithBot α) :=
{ WithBot.orderBot, WithBot.orderTop with }
theorem not_coe_le_bot (a : α) : ¬(a : WithBot α) ≤ ⊥ := fun h =>
let ⟨_, hb, _⟩ := h _ rfl
Option.not_mem_none _ hb
/-- There is a general version `le_bot_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem le_bot_iff : ∀ {a : WithBot α}, a ≤ ⊥ ↔ a = ⊥
| (a : α) => by simp [not_coe_le_bot _]
| ⊥ => by simp
theorem coe_le : ∀ {o : Option α}, b ∈ o → ((a : WithBot α) ≤ o ↔ a ≤ b)
| _, rfl => coe_le_coe
theorem coe_le_iff : ∀ {x : WithBot α}, (a : WithBot α) ≤ x ↔ ∃ b : α, x = b ∧ a ≤ b
| (x : α) => by simp
| ⊥ => iff_of_false (not_coe_le_bot _) <| by simp
theorem le_coe_iff : ∀ {x : WithBot α}, x ≤ b ↔ ∀ a : α, x = ↑a → a ≤ b
| (b : α) => by simp
| ⊥ => by simp
protected theorem _root_.IsMax.withBot (h : IsMax a) : IsMax (a : WithBot α)
| ⊥, _ => bot_le
| (_ : α), hb => coe_le_coe.2 <| h <| coe_le_coe.1 hb
theorem le_unbot_iff {a : α} {b : WithBot α} (h : b ≠ ⊥) :
a ≤ unbot b h ↔ (a : WithBot α) ≤ b := by
match b, h with
| some _, _ => simp only [unbot_coe, coe_le_coe]
theorem unbot_le_iff {a : WithBot α} (h : a ≠ ⊥) {b : α} :
unbot a h ≤ b ↔ a ≤ (b : WithBot α) := by
match a, h with
| some _, _ => simp only [unbot_coe, coe_le_coe]
theorem unbot'_le_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b ≤ c) :
a.unbot' b ≤ c ↔ a ≤ c := by
induction a
· simpa using h rfl
· simp
end LE
section LT
variable [LT α]
instance (priority := 10) lt : LT (WithBot α) :=
⟨fun o₁ o₂ : WithBot α => ∃ b : α, o₂ = ↑b ∧ ∀ a : α, o₁ = ↑a → a < b⟩
@[simp, norm_cast]
theorem coe_lt_coe : (a : WithBot α) < b ↔ a < b := by
simp [LT.lt]
@[simp]
theorem bot_lt_coe (a : α) : ⊥ < (a : WithBot α) :=
⟨a, rfl, fun _ hb => (Option.not_mem_none _ hb).elim⟩
@[simp]
protected theorem not_lt_bot (a : WithBot α) : ¬a < ⊥ :=
fun ⟨_, h, _⟩ => Option.not_mem_none _ h
@[simp, deprecated coe_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem some_lt_some : @LT.lt (WithBot α) _ (Option.some a) (Option.some b) ↔ a < b :=
coe_lt_coe
@[simp, deprecated bot_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem none_lt_some (a : α) : @LT.lt (WithBot α) _ none (some a) := bot_lt_coe _
@[simp, deprecated not_lt_bot "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem not_lt_none (a : WithBot α) : ¬@LT.lt (WithBot α) _ a none := WithBot.not_lt_bot _
theorem lt_iff_exists_coe : ∀ {a b : WithBot α}, a < b ↔ ∃ p : α, b = p ∧ a < p
| a, some b => by simp [coe_eq_coe]
| a, ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp
theorem lt_coe_iff : ∀ {x : WithBot α}, x < b ↔ ∀ a : α, x = a → a < b
| (_ : α) => by simp
| ⊥ => by simp [bot_lt_coe]
/-- A version of `bot_lt_iff_ne_bot` for `WithBot` that only requires `LT α`, not
`PartialOrder α`. -/
protected theorem bot_lt_iff_ne_bot : ∀ {x : WithBot α}, ⊥ < x ↔ x ≠ ⊥
| ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp
| (x : α) => by simp [bot_lt_coe]
theorem unbot'_lt_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b < c) :
a.unbot' b < c ↔ a < c := by
induction a
· simpa [bot_lt_coe] using h rfl
· simp
end LT
instance preorder [Preorder α] : Preorder (WithBot α) where
le := (· ≤ ·)
lt := (· < ·)
lt_iff_le_not_le := by
intros a b
cases a <;> cases b <;> simp [lt_iff_le_not_le]
le_refl o a ha := ⟨a, ha, le_rfl⟩
le_trans o₁ o₂ o₃ h₁ h₂ a ha :=
let ⟨b, hb, ab⟩ := h₁ a ha
let ⟨c, hc, bc⟩ := h₂ b hb
⟨c, hc, le_trans ab bc⟩
instance partialOrder [PartialOrder α] : PartialOrder (WithBot α) :=
{ WithBot.preorder with
le_antisymm := fun o₁ o₂ h₁ h₂ => by
cases' o₁ with a
· cases' o₂ with b
· rfl
rcases h₂ b rfl with ⟨_, ⟨⟩, _⟩
· rcases h₁ a rfl with ⟨b, ⟨⟩, h₁'⟩
rcases h₂ b rfl with ⟨_, ⟨⟩, h₂'⟩
rw [le_antisymm h₁' h₂'] }
section Preorder
variable [Preorder α] [Preorder β]
theorem coe_strictMono : StrictMono (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_lt_coe.2
theorem coe_mono : Monotone (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_le_coe.2
theorem monotone_iff {f : WithBot α → β} :
Monotone f ↔ Monotone (fun a ↦ f a : α → β) ∧ ∀ x : α, f ⊥ ≤ f x :=
⟨fun h ↦ ⟨h.comp WithBot.coe_mono, fun _ ↦ h bot_le⟩, fun h ↦
WithBot.forall.2
⟨WithBot.forall.2 ⟨fun _ => le_rfl, fun x _ => h.2 x⟩, fun _ =>
WithBot.forall.2 ⟨fun h => (not_coe_le_bot _ h).elim,
fun _ hle => h.1 (coe_le_coe.1 hle)⟩⟩⟩
@[simp]
theorem monotone_map_iff {f : α → β} : Monotone (WithBot.map f) ↔ Monotone f :=
monotone_iff.trans <| by simp [Monotone]
alias ⟨_, _root_.Monotone.withBot_map⟩ := monotone_map_iff
theorem strictMono_iff {f : WithBot α → β} :
StrictMono f ↔ StrictMono (fun a => f a : α → β) ∧ ∀ x : α, f ⊥ < f x :=
⟨fun h => ⟨h.comp WithBot.coe_strictMono, fun _ => h (bot_lt_coe _)⟩, fun h =>
WithBot.forall.2
⟨WithBot.forall.2 ⟨flip absurd (lt_irrefl _), fun x _ => h.2 x⟩, fun _ =>
WithBot.forall.2 ⟨fun h => (not_lt_bot h).elim, fun _ hle => h.1 (coe_lt_coe.1 hle)⟩⟩⟩
theorem strictAnti_iff {f : WithBot α → β} :
StrictAnti f ↔ StrictAnti (fun a ↦ f a : α → β) ∧ ∀ x : α, f x < f ⊥ :=
strictMono_iff (β := βᵒᵈ)
@[simp]
theorem strictMono_map_iff {f : α → β} :
StrictMono (WithBot.map f) ↔ StrictMono f :=
strictMono_iff.trans <| by simp [StrictMono, bot_lt_coe]
alias ⟨_, _root_.StrictMono.withBot_map⟩ := strictMono_map_iff
theorem map_le_iff (f : α → β) (mono_iff : ∀ {a b}, f a ≤ f b ↔ a ≤ b) :
∀ a b : WithBot α, a.map f ≤ b.map f ↔ a ≤ b
| ⊥, _ => by simp only [map_bot, bot_le]
| (a : α), ⊥ => by simp only [map_coe, map_bot, coe_ne_bot, not_coe_le_bot _]
| (a : α), (b : α) => by simpa only [map_coe, coe_le_coe] using mono_iff
theorem le_coe_unbot' : ∀ (a : WithBot α) (b : α), a ≤ a.unbot' b
| (a : α), _ => le_rfl
| ⊥, _ => bot_le
@[simp]
theorem lt_coe_bot [OrderBot α] : ∀ {x : WithBot α}, x < (⊥ : α) ↔ x = ⊥
| (x : α) => by simp
| ⊥ => by simp
end Preorder
instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (WithBot α) where
sup
-- note this is `Option.liftOrGet`, but with the right defeq when unfolding
| ⊥, ⊥ => ⊥
| (a : α), ⊥ => a
| ⊥, (b : α) => b
| (a : α), (b : α) => ↑(a ⊔ b)
le_sup_left := fun o₁ o₂ a ha => by cases ha; cases o₂ <;> simp
le_sup_right := fun o₁ o₂ a ha => by cases ha; cases o₁ <;> simp
sup_le := fun o₁ o₂ o₃ h₁ h₂ a ha => by
cases' o₁ with b <;> cases' o₂ with c <;> cases ha
· exact h₂ a rfl
· exact h₁ a rfl
· rcases h₁ b rfl with ⟨d, ⟨⟩, h₁'⟩
simp only [coe_le_coe] at h₂
exact ⟨d, rfl, sup_le h₁' h₂⟩
theorem coe_sup [SemilatticeSup α] (a b : α) : ((a ⊔ b : α) : WithBot α) = (a : WithBot α) ⊔ b :=
rfl
instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (WithBot α) :=
{ WithBot.partialOrder, @WithBot.orderBot α _ with
inf := WithBot.map₂ (· ⊓ ·),
inf_le_left := fun o₁ o₂ a ha => by
rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩
exact ⟨_, rfl, inf_le_left⟩,
inf_le_right := fun o₁ o₂ a ha => by
rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩
exact ⟨_, rfl, inf_le_right⟩,
le_inf := fun o₁ o₂ o₃ h₁ h₂ a ha => by
cases ha
rcases h₁ a rfl with ⟨b, ⟨⟩, ab⟩
rcases h₂ a rfl with ⟨c, ⟨⟩, ac⟩
exact ⟨_, rfl, le_inf ab ac⟩ }
theorem coe_inf [SemilatticeInf α] (a b : α) : ((a ⊓ b : α) : WithBot α) = (a : WithBot α) ⊓ b :=
rfl
instance lattice [Lattice α] : Lattice (WithBot α) :=
{ WithBot.semilatticeSup, WithBot.semilatticeInf with }
instance distribLattice [DistribLattice α] : DistribLattice (WithBot α) :=
{ WithBot.lattice with
le_sup_inf := fun o₁ o₂ o₃ =>
match o₁, o₂, o₃ with
| ⊥, ⊥, ⊥ => le_rfl
| ⊥, ⊥, (a₁ : α) => le_rfl
| ⊥, (a₁ : α), ⊥ => le_rfl
| ⊥, (a₁ : α), (a₃ : α) => le_rfl
| (a₁ : α), ⊥, ⊥ => inf_le_left
| (a₁ : α), ⊥, (a₃ : α) => inf_le_left
| (a₁ : α), (a₂ : α), ⊥ => inf_le_right
| (a₁ : α), (a₂ : α), (a₃ : α) => coe_le_coe.mpr le_sup_inf }
instance decidableEq [DecidableEq α] : DecidableEq (WithBot α) :=
inferInstanceAs <| DecidableEq (Option α)
instance decidableLE [LE α] [@DecidableRel α (· ≤ ·)] : @DecidableRel (WithBot α) (· ≤ ·)
| none, x => isTrue fun a h => Option.noConfusion h
| Option.some x, Option.some y =>
if h : x ≤ y then isTrue (coe_le_coe.2 h) else isFalse <| by simp [*]
| Option.some x, none => isFalse fun h => by rcases h x rfl with ⟨y, ⟨_⟩, _⟩
instance decidableLT [LT α] [@DecidableRel α (· < ·)] : @DecidableRel (WithBot α) (· < ·)
| none, Option.some x => isTrue <| by exists x, rfl; rintro _ ⟨⟩
| Option.some x, Option.some y =>
if h : x < y then isTrue <| by simp [*] else isFalse <| by simp [*]
| x, none => isFalse <| by rintro ⟨a, ⟨⟨⟩⟩⟩
instance isTotal_le [LE α] [IsTotal α (· ≤ ·)] : IsTotal (WithBot α) (· ≤ ·) :=
⟨fun a b =>
match a, b with
| none, _ => Or.inl bot_le
| _, none => Or.inr bot_le
| Option.some x, Option.some y => (total_of (· ≤ ·) x y).imp coe_le_coe.2 coe_le_coe.2⟩
instance linearOrder [LinearOrder α] : LinearOrder (WithBot α) :=
Lattice.toLinearOrder _
@[simp, norm_cast]
theorem coe_min [LinearOrder α] (x y : α) : ((min x y : α) : WithBot α) = min (x : WithBot α) y :=
rfl
@[simp, norm_cast]
theorem coe_max [LinearOrder α] (x y : α) : ((max x y : α) : WithBot α) = max (x : WithBot α) y :=
rfl
instance instWellFoundedLT [LT α] [WellFoundedLT α] : WellFoundedLT (WithBot α) where
wf :=
have not_lt_bot : ∀ a : WithBot α, ¬ a < ⊥ := nofun
have acc_bot := ⟨_, by simp [not_lt_bot]⟩
.intro fun
| ⊥ => acc_bot
| (a : α) => (wellFounded_lt.1 a).rec fun a _ ih =>
.intro _ fun
| ⊥, _ => acc_bot
| (b : α), hlt => ih _ (coe_lt_coe.1 hlt)
instance _root_.WithBot.instWellFoundedGT [LT α] [WellFoundedGT α] : WellFoundedGT (WithBot α) where
wf :=
have acc_some (a : α) : Acc ((· > ·) : WithBot α → WithBot α → Prop) a :=
(wellFounded_gt.1 a).rec fun _ _ ih =>
.intro _ fun
| (b : α), hlt => ih _ (coe_lt_coe.1 hlt)
| ⊥, hlt => absurd hlt (WithBot.not_lt_bot _)
.intro fun
| (a : α) => acc_some a
| ⊥ => .intro _ fun
| (b : α), _ => acc_some b
| ⊥, hlt => absurd hlt (WithBot.not_lt_bot _)
instance denselyOrdered [LT α] [DenselyOrdered α] [NoMinOrder α] : DenselyOrdered (WithBot α) :=
⟨fun a b =>
match a, b with
| a, none => fun h : a < ⊥ => (WithBot.not_lt_bot _ h).elim
| none, Option.some b => fun _ =>
let ⟨a, ha⟩ := exists_lt b
⟨a, bot_lt_coe a, coe_lt_coe.2 ha⟩
| Option.some _, Option.some _ => fun h =>
let ⟨a, ha₁, ha₂⟩ := exists_between (coe_lt_coe.1 h)
⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩⟩
theorem lt_iff_exists_coe_btwn [Preorder α] [DenselyOrdered α] [NoMinOrder α] {a b : WithBot α} :
a < b ↔ ∃ x : α, a < ↑x ∧ ↑x < b :=
⟨fun h =>
let ⟨_, hy⟩ := exists_between h
let ⟨x, hx⟩ := lt_iff_exists_coe.1 hy.1
⟨x, hx.1 ▸ hy⟩,
fun ⟨_, hx⟩ => lt_trans hx.1 hx.2⟩
instance noTopOrder [LE α] [NoTopOrder α] [Nonempty α] : NoTopOrder (WithBot α) :=
⟨by
apply recBotCoe
· exact ‹Nonempty α›.elim fun a => ⟨a, not_coe_le_bot a⟩
· intro a
obtain ⟨b, h⟩ := exists_not_le a
exact ⟨b, by rwa [coe_le_coe]⟩
⟩
instance noMaxOrder [LT α] [NoMaxOrder α] [Nonempty α] : NoMaxOrder (WithBot α) :=
⟨by
apply WithBot.recBotCoe
· apply ‹Nonempty α›.elim
exact fun a => ⟨a, WithBot.bot_lt_coe a⟩
· intro a
obtain ⟨b, ha⟩ := exists_gt a
exact ⟨b, coe_lt_coe.mpr ha⟩
⟩
end WithBot
--TODO(Mario): Construct using order dual on `WithBot`
/-- Attach `⊤` to a type. -/
def WithTop (α : Type*) :=
Option α
namespace WithTop
variable {a b : α}
instance [Repr α] : Repr (WithTop α) :=
⟨fun o _ =>
match o with
| none => "⊤"
| some a => "↑" ++ repr a⟩
/-- The canonical map from `α` into `WithTop α` -/
@[coe, match_pattern] def some : α → WithTop α :=
Option.some
instance coeTC : CoeTC α (WithTop α) :=
⟨some⟩
instance top : Top (WithTop α) :=
⟨none⟩
instance inhabited : Inhabited (WithTop α) :=
⟨⊤⟩
instance nontrivial [Nonempty α] : Nontrivial (WithTop α) :=
Option.nontrivial
open Function
theorem coe_injective : Injective ((↑) : α → WithTop α) :=
Option.some_injective _
@[norm_cast]
theorem coe_inj : (a : WithTop α) = b ↔ a = b :=
Option.some_inj
protected theorem «forall» {p : WithTop α → Prop} : (∀ x, p x) ↔ p ⊤ ∧ ∀ x : α, p x :=
Option.forall
protected theorem «exists» {p : WithTop α → Prop} : (∃ x, p x) ↔ p ⊤ ∨ ∃ x : α, p x :=
Option.exists
theorem none_eq_top : (none : WithTop α) = (⊤ : WithTop α) :=
rfl
theorem some_eq_coe (a : α) : (Option.some a : WithTop α) = (↑a : WithTop α) :=
rfl
@[simp]
theorem top_ne_coe : ⊤ ≠ (a : WithTop α) :=
nofun
@[simp]
theorem coe_ne_top : (a : WithTop α) ≠ ⊤ :=
nofun
/-- Recursor for `WithTop` using the preferred forms `⊤` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recTopCoe {C : WithTop α → Sort*} (top : C ⊤) (coe : ∀ a : α, C a) : ∀ n : WithTop α, C n
| none => top
| Option.some a => coe a
@[simp]
theorem recTopCoe_top {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) :
@recTopCoe _ C d f ⊤ = d :=
rfl
@[simp]
theorem recTopCoe_coe {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) (x : α) :
@recTopCoe _ C d f ↑x = f x :=
rfl
/-- `WithTop.toDual` is the equivalence sending `⊤` to `⊥` and any `a : α` to `toDual a : αᵒᵈ`.
See `WithTop.toDualBotEquiv` for the related order-iso.
-/
protected def toDual : WithTop α ≃ WithBot αᵒᵈ :=
Equiv.refl _
/-- `WithTop.ofDual` is the equivalence sending `⊤` to `⊥` and any `a : αᵒᵈ` to `ofDual a : α`.
See `WithTop.toDualBotEquiv` for the related order-iso.
-/
protected def ofDual : WithTop αᵒᵈ ≃ WithBot α :=
Equiv.refl _
/-- `WithBot.toDual` is the equivalence sending `⊥` to `⊤` and any `a : α` to `toDual a : αᵒᵈ`.
See `WithBot.toDual_top_equiv` for the related order-iso.
-/
protected def _root_.WithBot.toDual : WithBot α ≃ WithTop αᵒᵈ :=
Equiv.refl _
/-- `WithBot.ofDual` is the equivalence sending `⊥` to `⊤` and any `a : αᵒᵈ` to `ofDual a : α`.
See `WithBot.ofDual_top_equiv` for the related order-iso.
-/
protected def _root_.WithBot.ofDual : WithBot αᵒᵈ ≃ WithTop α :=
Equiv.refl _
@[simp]
theorem toDual_symm_apply (a : WithBot αᵒᵈ) : WithTop.toDual.symm a = WithBot.ofDual a :=
rfl
@[simp]
theorem ofDual_symm_apply (a : WithBot α) : WithTop.ofDual.symm a = WithBot.toDual a :=
rfl
@[simp]
theorem toDual_apply_top : WithTop.toDual (⊤ : WithTop α) = ⊥ :=
rfl
@[simp]
theorem ofDual_apply_top : WithTop.ofDual (⊤ : WithTop α) = ⊥ :=
rfl
open OrderDual
@[simp]
theorem toDual_apply_coe (a : α) : WithTop.toDual (a : WithTop α) = toDual a :=
rfl
@[simp]
theorem ofDual_apply_coe (a : αᵒᵈ) : WithTop.ofDual (a : WithTop αᵒᵈ) = ofDual a :=
rfl
/-- Specialization of `Option.getD` to values in `WithTop α` that respects API boundaries.
-/
def untop' (d : α) (x : WithTop α) : α :=
recTopCoe d id x
@[simp]
theorem untop'_top {α} (d : α) : untop' d ⊤ = d :=
rfl
@[simp]
theorem untop'_coe {α} (d x : α) : untop' d x = x :=
rfl
@[simp, norm_cast] -- Porting note: added `simp`
theorem coe_eq_coe : (a : WithTop α) = b ↔ a = b :=
Option.some_inj
theorem untop'_eq_iff {d y : α} {x : WithTop α} : untop' d x = y ↔ x = y ∨ x = ⊤ ∧ y = d :=
WithBot.unbot'_eq_iff
@[simp] theorem untop'_eq_self_iff {d : α} {x : WithTop α} : untop' d x = d ↔ x = d ∨ x = ⊤ :=
WithBot.unbot'_eq_self_iff
theorem untop'_eq_untop'_iff {d : α} {x y : WithTop α} :
untop' d x = untop' d y ↔ x = y ∨ x = d ∧ y = ⊤ ∨ x = ⊤ ∧ y = d :=
WithBot.unbot'_eq_unbot'_iff
/-- Lift a map `f : α → β` to `WithTop α → WithTop β`. Implemented using `Option.map`. -/
def map (f : α → β) : WithTop α → WithTop β :=
Option.map f
@[simp]
theorem map_top (f : α → β) : map f ⊤ = ⊤ :=
rfl
@[simp]
theorem map_coe (f : α → β) (a : α) : map f a = f a :=
rfl
theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ}
(h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : map g₁ (map f₁ a) = map g₂ (map f₂ a) :=
Option.map_comm h _
/-- The image of a binary function `f : α → β → γ` as a function
`WithTop α → WithTop β → WithTop γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ : (α → β → γ) → WithTop α → WithTop β → WithTop γ := Option.map₂
lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl
@[simp] lemma map₂_top_left (f : α → β → γ) (b) : map₂ f ⊤ b = ⊤ := rfl
@[simp] lemma map₂_top_right (f : α → β → γ) (a) : map₂ f a ⊤ = ⊤ := by cases a <;> rfl
@[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl
@[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by
cases a <;> rfl
@[simp] lemma map₂_eq_top_iff {f : α → β → γ} {a : WithTop α} {b : WithTop β} :
map₂ f a b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := Option.map₂_eq_none_iff
theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithBot α) :
map f (WithBot.toDual a) = a.map (toDual ∘ f) :=
rfl
theorem map_ofDual (f : α → β) (a : WithBot αᵒᵈ) : map f (WithBot.ofDual a) = a.map (ofDual ∘ f) :=
rfl
theorem toDual_map (f : α → β) (a : WithTop α) :
WithTop.toDual (map f a) = WithBot.map (toDual ∘ f ∘ ofDual) (WithTop.toDual a) :=
rfl
theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithTop αᵒᵈ) :
WithTop.ofDual (map f a) = WithBot.map (ofDual ∘ f ∘ toDual) (WithTop.ofDual a) :=
rfl
lemma ne_top_iff_exists {x : WithTop α} : x ≠ ⊤ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists
lemma forall_ne_iff_eq_top {x : WithTop α} : (∀ a : α, ↑a ≠ x) ↔ x = ⊤ :=
Option.forall_some_ne_iff_eq_none
/-- Deconstruct a `x : WithTop α` to the underlying value in `α`, given a proof that `x ≠ ⊤`. -/
def untop : ∀ x : WithTop α, x ≠ ⊤ → α | (x : α), _ => x
@[simp] lemma coe_untop : ∀ (x : WithTop α) hx, x.untop hx = x | (x : α), _ => rfl
@[simp]
theorem untop_coe (x : α) (h : (x : WithTop α) ≠ ⊤ := coe_ne_top) : (x : WithTop α).untop h = x :=
rfl
instance canLift : CanLift (WithTop α) α (↑) fun r => r ≠ ⊤ where
prf x h := ⟨x.untop h, coe_untop _ _⟩
instance instBot [Bot α] : Bot (WithTop α) where
bot := (⊥ : α)
@[simp, norm_cast] lemma coe_bot [Bot α] : ((⊥ : α) : WithTop α) = ⊥ := rfl
@[simp, norm_cast] lemma coe_eq_bot [Bot α] {a : α} : (a : WithTop α) = ⊥ ↔ a = ⊥ := coe_eq_coe
@[simp, norm_cast] lemma bot_eq_coe [Bot α] {a : α} : (⊥ : WithTop α) = a ↔ ⊥ = a := coe_eq_coe
section LE
variable [LE α]
instance (priority := 10) le : LE (WithTop α) :=
⟨fun o₁ o₂ => ∀ a : α, o₂ = ↑a → ∃ b : α, o₁ = ↑b ∧ b ≤ a⟩
theorem toDual_le_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
WithTop.toDual a ≤ b ↔ WithBot.ofDual b ≤ a :=
Iff.rfl
theorem le_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
a ≤ WithTop.toDual b ↔ b ≤ WithBot.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_le_toDual_iff {a b : WithTop α} : WithTop.toDual a ≤ WithTop.toDual b ↔ b ≤ a :=
Iff.rfl
theorem ofDual_le_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
WithTop.ofDual a ≤ b ↔ WithBot.toDual b ≤ a :=
Iff.rfl
theorem le_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
a ≤ WithTop.ofDual b ↔ b ≤ WithBot.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_le_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a ≤ WithTop.ofDual b ↔ b ≤ a :=
Iff.rfl
@[simp, norm_cast]
theorem coe_le_coe : (a : WithTop α) ≤ b ↔ a ≤ b := by
simp only [← toDual_le_toDual_iff, toDual_apply_coe, WithBot.coe_le_coe, toDual_le_toDual]
@[simp, deprecated coe_le_coe "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem some_le_some : @LE.le (WithTop α) _ (Option.some a) (Option.some b) ↔ a ≤ b :=
coe_le_coe
instance orderTop : OrderTop (WithTop α) where
le_top := fun _ => toDual_le_toDual_iff.mp bot_le
@[simp, deprecated le_top "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem le_none {a : WithTop α} : @LE.le (WithTop α) _ a none := le_top
instance orderBot [OrderBot α] : OrderBot (WithTop α) where
bot_le o a ha := by cases ha; exact ⟨_, rfl, bot_le⟩
instance boundedOrder [OrderBot α] : BoundedOrder (WithTop α) :=
{ WithTop.orderTop, WithTop.orderBot with }
theorem not_top_le_coe (a : α) : ¬(⊤ : WithTop α) ≤ ↑a :=
WithBot.not_coe_le_bot (toDual a)
/-- There is a general version `top_le_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem top_le_iff : ∀ {a : WithTop α}, ⊤ ≤ a ↔ a = ⊤
| (a : α) => by simp [not_top_le_coe _]
| ⊤ => by simp
theorem le_coe : ∀ {o : Option α}, a ∈ o → (@LE.le (WithTop α) _ o b ↔ a ≤ b)
| _, rfl => coe_le_coe
theorem le_coe_iff {x : WithTop α} : x ≤ b ↔ ∃ a : α, x = a ∧ a ≤ b :=
@WithBot.coe_le_iff (αᵒᵈ) _ _ (toDual x)
theorem coe_le_iff {x : WithTop α} : ↑a ≤ x ↔ ∀ b : α, x = ↑b → a ≤ b :=
@WithBot.le_coe_iff (αᵒᵈ) _ _ (toDual x)
protected theorem _root_.IsMin.withTop (h : IsMin a) : IsMin (a : WithTop α) := by
-- defeq to is_max_to_dual_iff.mp (is_max.with_bot _), but that breaks API boundary
intro _ hb
rw [← toDual_le_toDual_iff] at hb
simpa [toDual_le_iff] using h.toDual.withBot hb
theorem untop_le_iff {a : WithTop α} {b : α} (h : a ≠ ⊤) :
untop a h ≤ b ↔ a ≤ (b : WithTop α) :=
@WithBot.le_unbot_iff αᵒᵈ _ _ _ _
theorem le_untop_iff {a : α} {b : WithTop α} (h : b ≠ ⊤) :
a ≤ untop b h ↔ (a : WithTop α) ≤ b :=
@WithBot.unbot_le_iff αᵒᵈ _ _ _ _
theorem le_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c ≤ b) :
c ≤ a.untop' b ↔ c ≤ a :=
WithBot.unbot'_le_iff (α := αᵒᵈ) h
end LE
section LT
variable [LT α]
instance (priority := 10) lt : LT (WithTop α) :=
⟨fun o₁ o₂ : Option α => ∃ b ∈ o₁, ∀ a ∈ o₂, b < a⟩
theorem toDual_lt_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
WithTop.toDual a < b ↔ WithBot.ofDual b < a :=
Iff.rfl
theorem lt_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
a < WithTop.toDual b ↔ b < WithBot.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_lt_toDual_iff {a b : WithTop α} : WithTop.toDual a < WithTop.toDual b ↔ b < a :=
Iff.rfl
theorem ofDual_lt_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
WithTop.ofDual a < b ↔ WithBot.toDual b < a :=
Iff.rfl
theorem lt_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
a < WithTop.ofDual b ↔ b < WithBot.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_lt_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a < WithTop.ofDual b ↔ b < a :=
Iff.rfl
theorem lt_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c < b) :
c < a.untop' b ↔ c < a :=
WithBot.unbot'_lt_iff (α := αᵒᵈ) h
end LT
end WithTop
namespace WithBot
open OrderDual
@[simp]
theorem toDual_symm_apply (a : WithTop αᵒᵈ) : WithBot.toDual.symm a = WithTop.ofDual a :=
rfl
@[simp]
theorem ofDual_symm_apply (a : WithTop α) : WithBot.ofDual.symm a = WithTop.toDual a :=
rfl
@[simp]
theorem toDual_apply_bot : WithBot.toDual (⊥ : WithBot α) = ⊤ :=
rfl
@[simp]
theorem ofDual_apply_bot : WithBot.ofDual (⊥ : WithBot α) = ⊤ :=
rfl
@[simp]
theorem toDual_apply_coe (a : α) : WithBot.toDual (a : WithBot α) = toDual a :=
rfl
@[simp]
theorem ofDual_apply_coe (a : αᵒᵈ) : WithBot.ofDual (a : WithBot αᵒᵈ) = ofDual a :=
rfl
theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithTop α) :
WithBot.map f (WithTop.toDual a) = a.map (toDual ∘ f) :=
rfl
theorem map_ofDual (f : α → β) (a : WithTop αᵒᵈ) :
WithBot.map f (WithTop.ofDual a) = a.map (ofDual ∘ f) :=
rfl
theorem toDual_map (f : α → β) (a : WithBot α) :
WithBot.toDual (WithBot.map f a) = map (toDual ∘ f ∘ ofDual) (WithBot.toDual a) :=
rfl
theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithBot αᵒᵈ) :
WithBot.ofDual (WithBot.map f a) = map (ofDual ∘ f ∘ toDual) (WithBot.ofDual a) :=
rfl
lemma forall_lt_iff_eq_bot [Preorder α] {x : WithBot α} :
(∀ y : α, x < y) ↔ x = ⊥ :=
⟨fun h ↦ forall_ne_iff_eq_bot.mp (fun x ↦ (h x).ne'), fun h ↦ h ▸ fun y ↦ bot_lt_coe y⟩
section LE
variable [LE α] {a b : α}
theorem toDual_le_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
WithBot.toDual a ≤ b ↔ WithTop.ofDual b ≤ a :=
Iff.rfl
theorem le_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
a ≤ WithBot.toDual b ↔ b ≤ WithTop.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_le_toDual_iff {a b : WithBot α} : WithBot.toDual a ≤ WithBot.toDual b ↔ b ≤ a :=
Iff.rfl
theorem ofDual_le_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
WithBot.ofDual a ≤ b ↔ WithTop.toDual b ≤ a :=
Iff.rfl
theorem le_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
a ≤ WithBot.ofDual b ↔ b ≤ WithTop.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_le_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a ≤ WithBot.ofDual b ↔ b ≤ a :=
Iff.rfl
end LE
section LT
variable [LT α] {a b : α}
theorem toDual_lt_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
WithBot.toDual a < b ↔ WithTop.ofDual b < a :=
Iff.rfl
theorem lt_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
a < WithBot.toDual b ↔ b < WithTop.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_lt_toDual_iff {a b : WithBot α} : WithBot.toDual a < WithBot.toDual b ↔ b < a :=
Iff.rfl
theorem ofDual_lt_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
WithBot.ofDual a < b ↔ WithTop.toDual b < a :=
Iff.rfl
theorem lt_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
a < WithBot.ofDual b ↔ b < WithTop.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_lt_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a < WithBot.ofDual b ↔ b < a :=
Iff.rfl
end LT
end WithBot
namespace WithTop