@@ -874,6 +874,34 @@ option.rec h₁ h₂
874
874
@[simp] lemma rec_top_coe_coe {C : with_top α → Sort *} (d : C ⊤) (f : Π (a : α), C a)
875
875
(x : α) : @rec_top_coe _ C d f ↑x = f x := rfl
876
876
877
+ /-- `with_top.to_dual` is the equivalence sending `⊤` to `⊥` and any `a : α` to `to_dual a : αᵒᵈ`.
878
+ See `with_top.to_dual_bot_equiv` for the related order-iso.
879
+ -/
880
+ protected def to_dual : with_top α ≃ with_bot αᵒᵈ := equiv.refl _
881
+ /-- `with_top.of_dual` is the equivalence sending `⊤` to `⊥` and any `a : αᵒᵈ` to `of_dual a : α`.
882
+ See `with_top.to_dual_bot_equiv` for the related order-iso.
883
+ -/
884
+ protected def of_dual : with_top αᵒᵈ ≃ with_bot α := equiv.refl _
885
+ /-- `with_bot.to_dual` is the equivalence sending `⊥` to `⊤` and any `a : α` to `to_dual a : αᵒᵈ`.
886
+ See `with_bot.to_dual_top_equiv` for the related order-iso.
887
+ -/
888
+ protected def _root_.with_bot.to_dual : with_bot α ≃ with_top αᵒᵈ := equiv.refl _
889
+ /-- `with_bot.of_dual` is the equivalence sending `⊥` to `⊤` and any `a : αᵒᵈ` to `of_dual a : α`.
890
+ See `with_bot.to_dual_top_equiv` for the related order-iso.
891
+ -/
892
+ protected def _root_.with_bot.of_dual : with_bot αᵒᵈ ≃ with_top α := equiv.refl _
893
+
894
+ @[simp] lemma to_dual_symm_apply (a : with_bot αᵒᵈ) :
895
+ with_top.to_dual.symm a = a.of_dual := rfl
896
+ @[simp] lemma of_dual_symm_apply (a : with_bot α) :
897
+ with_top.of_dual.symm a = a.to_dual := rfl
898
+
899
+ @[simp] lemma to_dual_apply_top : with_top.to_dual (⊤ : with_top α) = ⊥ := rfl
900
+ @[simp] lemma of_dual_apply_top : with_top.of_dual (⊤ : with_top α) = ⊥ := rfl
901
+
902
+ @[simp] lemma to_dual_apply_coe (a : α) : with_top.to_dual (a : with_top α) = to_dual a := rfl
903
+ @[simp] lemma of_dual_apply_coe (a : αᵒᵈ) : with_top.of_dual (a : with_top αᵒᵈ) = of_dual a := rfl
904
+
877
905
/-- Specialization of `option.get_or_else` to values in `with_top α` that respects API boundaries.
878
906
-/
879
907
def untop' (d : α) (x : with_top α) : α := rec_top_coe d id x
@@ -889,6 +917,16 @@ def map (f : α → β) : with_top α → with_top β := option.map f
889
917
@[simp] lemma map_top (f : α → β) : map f ⊤ = ⊤ := rfl
890
918
@[simp] lemma map_coe (f : α → β) (a : α) : map f a = f a := rfl
891
919
920
+ lemma map_to_dual (f : αᵒᵈ → βᵒᵈ) (a : with_bot α) :
921
+ map f (with_bot.to_dual a) = a.map (to_dual ∘ f) := rfl
922
+ lemma map_of_dual (f : α → β) (a : with_bot αᵒᵈ) :
923
+ map f (with_bot.of_dual a) = a.map (of_dual ∘ f) := rfl
924
+
925
+ lemma to_dual_map (f : α → β) (a : with_top α) :
926
+ with_top.to_dual (map f a) = with_bot.map (to_dual ∘ f ∘ of_dual) a.to_dual := rfl
927
+ lemma of_dual_map (f : αᵒᵈ → βᵒᵈ) (a : with_top αᵒᵈ) :
928
+ with_top.of_dual (map f a) = with_bot.map (of_dual ∘ f ∘ to_dual) a.of_dual := rfl
929
+
892
930
lemma ne_top_iff_exists {x : with_top α} : x ≠ ⊤ ↔ ∃ (a : α), ↑a = x := option.ne_none_iff_exists
893
931
894
932
/-- Deconstruct a `x : with_top α` to the underlying value in `α`, given a proof that `x ≠ ⊤`. -/
@@ -912,11 +950,26 @@ variables [has_le α]
912
950
@[priority 10 ]
913
951
instance : has_le (with_top α) := ⟨λ o₁ o₂ : option α, ∀ a ∈ o₂, ∃ b ∈ o₁, b ≤ a⟩
914
952
915
- @[simp] lemma some_le_some : @has_le.le (with_top α) _ (some a) (some b) ↔ a ≤ b := by simp [(≤)]
916
- @[simp, norm_cast] lemma coe_le_coe : (a : with_top α) ≤ b ↔ a ≤ b := some_le_some
953
+ lemma to_dual_le_iff {a : with_top α} {b : with_bot αᵒᵈ} :
954
+ with_top.to_dual a ≤ b ↔ with_bot.of_dual b ≤ a := iff.rfl
955
+ lemma le_to_dual_iff {a : with_bot αᵒᵈ} {b : with_top α} :
956
+ a ≤ with_top.to_dual b ↔ b ≤ with_bot.of_dual a := iff.rfl
957
+ @[simp] lemma to_dual_le_to_dual_iff {a b : with_top α} :
958
+ with_top.to_dual a ≤ with_top.to_dual b ↔ b ≤ a := iff.rfl
959
+
960
+ lemma of_dual_le_iff {a : with_top αᵒᵈ} {b : with_bot α} :
961
+ with_top.of_dual a ≤ b ↔ with_bot.to_dual b ≤ a := iff.rfl
962
+ lemma le_of_dual_iff {a : with_bot α} {b : with_top αᵒᵈ} :
963
+ a ≤ with_top.of_dual b ↔ b ≤ with_bot.to_dual a := iff.rfl
964
+ @[simp] lemma of_dual_le_of_dual_iff {a b : with_top αᵒᵈ} :
965
+ with_top.of_dual a ≤ with_top.of_dual b ↔ b ≤ a := iff.rfl
966
+
967
+ @[simp, norm_cast] lemma coe_le_coe : (a : with_top α) ≤ b ↔ a ≤ b :=
968
+ by simp only [←to_dual_le_to_dual_iff, to_dual_apply_coe, with_bot.coe_le_coe, to_dual_le_to_dual]
917
969
970
+ @[simp] lemma some_le_some : @has_le.le (with_top α) _ (some a) (some b) ↔ a ≤ b := coe_le_coe
918
971
@[simp] lemma le_none {a : with_top α} : @has_le.le (with_top α) _ a none :=
919
- λ b h, option.no_confusion h
972
+ to_dual_le_to_dual_iff.mp with_bot.none_le
920
973
921
974
instance : order_top (with_top α) := { le_top := λ a, le_none, .. with_top.has_top }
922
975
@@ -932,17 +985,23 @@ lemma not_top_le_coe (a : α) : ¬ (⊤ : with_top α) ≤ ↑a := with_bot.not_
932
985
lemma le_coe : ∀ {o : option α}, a ∈ o → (@has_le.le (with_top α) _ o b ↔ a ≤ b) | _ rfl :=
933
986
coe_le_coe
934
987
935
- lemma le_coe_iff : ∀ {x : with_top α}, x ≤ b ↔ ∃ a : α, x = a ∧ a ≤ b
936
- | (some a) := by simp [some_eq_coe, coe_eq_coe]
937
- | none := iff_of_false (not_top_le_coe _) $ by simp [none_eq_top]
988
+ lemma le_coe_iff {x : with_top α} : x ≤ b ↔ ∃ a : α, x = a ∧ a ≤ b :=
989
+ by simpa [←to_dual_le_to_dual_iff, with_bot.coe_le_iff]
938
990
939
- lemma coe_le_iff : ∀ {x : with_top α}, ↑a ≤ x ↔ ∀ b, x = ↑b → a ≤ b
940
- | (some b) := by simp [some_eq_coe, coe_eq_coe]
941
- | none := by simp [none_eq_top]
991
+ lemma coe_le_iff {x : with_top α} : ↑a ≤ x ↔ ∀ b, x = ↑b → a ≤ b :=
992
+ begin
993
+ simp only [←to_dual_le_to_dual_iff, to_dual_apply_coe, with_bot.le_coe_iff, order_dual.forall,
994
+ to_dual_le_to_dual],
995
+ exact forall₂_congr (λ _ _, iff.rfl)
996
+ end
942
997
943
- protected lemma _root_.is_min.with_top (h : is_min a) : is_min (a : with_top α)
944
- | none _ := le_top
945
- | (some b) hb := some_le_some.2 $ h $ some_le_some.1 hb
998
+ protected lemma _root_.is_min.with_top (h : is_min a) : is_min (a : with_top α) :=
999
+ begin
1000
+ -- defeq to is_max_to_dual_iff.mp (is_max.with_bot _), but that breaks API boundary
1001
+ intros _ hb,
1002
+ rw ←to_dual_le_to_dual_iff at hb,
1003
+ simpa [to_dual_le_iff] using (is_max.with_bot h : is_max (to_dual a : with_bot αᵒᵈ)) hb
1004
+ end
946
1005
947
1006
end has_le
948
1007
@@ -952,50 +1011,138 @@ variables [has_lt α]
952
1011
@[priority 10 ]
953
1012
instance : has_lt (with_top α) := ⟨λ o₁ o₂ : option α, ∃ b ∈ o₁, ∀ a ∈ o₂, b < a⟩
954
1013
955
- @[simp] lemma some_lt_some : @has_lt.lt (with_top α) _ (some a) (some b) ↔ a < b := by simp [(<)]
956
- @[simp, norm_cast] lemma coe_lt_coe : (a : with_top α) < b ↔ a < b := some_lt_some
1014
+ lemma to_dual_lt_iff {a : with_top α} {b : with_bot αᵒᵈ} :
1015
+ with_top.to_dual a < b ↔ with_bot.of_dual b < a := iff.rfl
1016
+ lemma lt_to_dual_iff {a : with_bot αᵒᵈ} {b : with_top α} :
1017
+ a < with_top.to_dual b ↔ b < with_bot.of_dual a := iff.rfl
1018
+ @[simp] lemma to_dual_lt_to_dual_iff {a b : with_top α} :
1019
+ with_top.to_dual a < with_top.to_dual b ↔ b < a := iff.rfl
957
1020
958
- @[simp] lemma some_lt_none (a : α) : @has_lt.lt (with_top α) _ (some a) none :=
959
- ⟨a, rfl, λ b hb, (option.not_mem_none _ hb).elim⟩
960
- lemma coe_lt_top (a : α) : (a : with_top α) < ⊤ := some_lt_none a
1021
+ lemma of_dual_lt_iff {a : with_top αᵒᵈ} {b : with_bot α} :
1022
+ with_top.of_dual a < b ↔ with_bot.to_dual b < a := iff.rfl
1023
+ lemma lt_of_dual_iff {a : with_bot α} {b : with_top αᵒᵈ} :
1024
+ a < with_top.of_dual b ↔ b < with_bot.to_dual a := iff.rfl
1025
+ @[simp] lemma of_dual_lt_of_dual_iff {a b : with_top αᵒᵈ} :
1026
+ with_top.of_dual a < with_top.of_dual b ↔ b < a := iff.rfl
1027
+
1028
+ end has_lt
1029
+
1030
+ end with_top
1031
+
1032
+ namespace with_bot
1033
+
1034
+ @[simp] lemma to_dual_symm_apply (a : with_top αᵒᵈ) : with_bot.to_dual.symm a = a.of_dual := rfl
1035
+ @[simp] lemma of_dual_symm_apply (a : with_top α) : with_bot.of_dual.symm a = a.to_dual := rfl
1036
+
1037
+ @[simp] lemma to_dual_apply_bot : with_bot.to_dual (⊥ : with_bot α) = ⊤ := rfl
1038
+ @[simp] lemma of_dual_apply_bot : with_bot.of_dual (⊥ : with_bot α) = ⊤ := rfl
1039
+ @[simp] lemma to_dual_apply_coe (a : α) : with_bot.to_dual (a : with_bot α) = to_dual a := rfl
1040
+ @[simp] lemma of_dual_apply_coe (a : αᵒᵈ) : with_bot.of_dual (a : with_bot αᵒᵈ) = of_dual a := rfl
1041
+
1042
+ lemma map_to_dual (f : αᵒᵈ → βᵒᵈ) (a : with_top α) :
1043
+ with_bot.map f (with_top.to_dual a) = a.map (to_dual ∘ f) := rfl
1044
+ lemma map_of_dual (f : α → β) (a : with_top αᵒᵈ) :
1045
+ with_bot.map f (with_top.of_dual a) = a.map (of_dual ∘ f) := rfl
1046
+ lemma to_dual_map (f : α → β) (a : with_bot α) :
1047
+ with_bot.to_dual (with_bot.map f a) = map (to_dual ∘ f ∘ of_dual) a.to_dual := rfl
1048
+ lemma of_dual_map (f : αᵒᵈ → βᵒᵈ) (a : with_bot αᵒᵈ) :
1049
+ with_bot.of_dual (with_bot.map f a) = map (of_dual ∘ f ∘ to_dual) a.of_dual := rfl
1050
+
1051
+ section has_le
1052
+
1053
+ variables [has_le α] {a b : α}
1054
+
1055
+ lemma to_dual_le_iff {a : with_bot α} {b : with_top αᵒᵈ} :
1056
+ with_bot.to_dual a ≤ b ↔ with_top.of_dual b ≤ a := iff.rfl
1057
+ lemma le_to_dual_iff {a : with_top αᵒᵈ} {b : with_bot α} :
1058
+ a ≤ with_bot.to_dual b ↔ b ≤ with_top.of_dual a := iff.rfl
1059
+ @[simp] lemma to_dual_le_to_dual_iff {a b : with_bot α} :
1060
+ with_bot.to_dual a ≤ with_bot.to_dual b ↔ b ≤ a := iff.rfl
1061
+
1062
+ lemma of_dual_le_iff {a : with_bot αᵒᵈ} {b : with_top α} :
1063
+ with_bot.of_dual a ≤ b ↔ with_top.to_dual b ≤ a := iff.rfl
1064
+ lemma le_of_dual_iff {a : with_top α} {b : with_bot αᵒᵈ} :
1065
+ a ≤ with_bot.of_dual b ↔ b ≤ with_top.to_dual a := iff.rfl
1066
+ @[simp] lemma of_dual_le_of_dual_iff {a b : with_bot αᵒᵈ} :
1067
+ with_bot.of_dual a ≤ with_bot.of_dual b ↔ b ≤ a := iff.rfl
1068
+
1069
+ end has_le
1070
+
1071
+ section has_lt
1072
+
1073
+ variables [has_lt α] {a b : α}
1074
+
1075
+ lemma to_dual_lt_iff {a : with_bot α} {b : with_top αᵒᵈ} :
1076
+ with_bot.to_dual a < b ↔ with_top.of_dual b < a := iff.rfl
1077
+ lemma lt_to_dual_iff {a : with_top αᵒᵈ} {b : with_bot α} :
1078
+ a < with_bot.to_dual b ↔ b < with_top.of_dual a := iff.rfl
1079
+ @[simp] lemma to_dual_lt_to_dual_iff {a b : with_bot α} :
1080
+ with_bot.to_dual a < with_bot.to_dual b ↔ b < a := iff.rfl
1081
+
1082
+ lemma of_dual_lt_iff {a : with_bot αᵒᵈ} {b : with_top α} :
1083
+ with_bot.of_dual a < b ↔ with_top.to_dual b < a := iff.rfl
1084
+ lemma lt_of_dual_iff {a : with_top α} {b : with_bot αᵒᵈ} :
1085
+ a < with_bot.of_dual b ↔ b < with_top.to_dual a := iff.rfl
1086
+ @[simp] lemma of_dual_lt_of_dual_iff {a b : with_bot αᵒᵈ} :
1087
+ with_bot.of_dual a < with_bot.of_dual b ↔ b < a := iff.rfl
1088
+
1089
+ end has_lt
1090
+
1091
+ end with_bot
1092
+
1093
+ namespace with_top
1094
+
1095
+ section has_lt
1096
+ variables [has_lt α] {a b : α}
1097
+
1098
+ @[simp, norm_cast] lemma coe_lt_coe : (a : with_top α) < b ↔ a < b :=
1099
+ by simp only [←to_dual_lt_to_dual_iff, to_dual_apply_coe, with_bot.coe_lt_coe, to_dual_lt_to_dual]
1100
+ @[simp] lemma some_lt_some : @has_lt.lt (with_top α) _ (some a) (some b) ↔ a < b := coe_lt_coe
1101
+
1102
+ lemma coe_lt_top (a : α) : (a : with_top α) < ⊤ :=
1103
+ by simpa [←to_dual_lt_to_dual_iff] using with_bot.bot_lt_coe _
1104
+ @[simp] lemma some_lt_none (a : α) : @has_lt.lt (with_top α) _ (some a) none := coe_lt_top a
961
1105
962
1106
@[simp] lemma not_none_lt (a : with_top α) : ¬ @has_lt.lt (with_top α) _ none a :=
963
- λ ⟨_, h, _⟩, option.not_mem_none _ h
1107
+ begin
1108
+ rw [←to_dual_lt_to_dual_iff],
1109
+ exact with_bot.not_lt_none _
1110
+ end
964
1111
965
- lemma lt_iff_exists_coe : ∀ {a b : with_top α}, a < b ↔ ∃ p : α, a = p ∧ ↑p < b
966
- | (some a) b := by simp [some_eq_coe, coe_eq_coe]
967
- | none b := iff_of_false (not_none_lt _) $ by simp [none_eq_top]
1112
+ lemma lt_iff_exists_coe {a b : with_top α} : a < b ↔ ∃ p : α, a = p ∧ ↑p < b :=
1113
+ begin
1114
+ rw [←to_dual_lt_to_dual_iff, with_bot.lt_iff_exists_coe, order_dual.exists],
1115
+ exact exists_congr (λ _, and_congr_left' iff.rfl)
1116
+ end
968
1117
969
- lemma coe_lt_iff : ∀ {x : with_top α}, ↑a < x ↔ ∀ b, x = ↑b → a < b
970
- | (some b) := by simp [some_eq_coe, coe_eq_coe, coe_lt_coe]
971
- | none := by simp [none_eq_top, coe_lt_top]
1118
+ lemma coe_lt_iff {x : with_top α} : ↑a < x ↔ ∀ b, x = ↑b → a < b :=
1119
+ begin
1120
+ simp only [←to_dual_lt_to_dual_iff, with_bot.lt_coe_iff, to_dual_apply_coe, order_dual.forall,
1121
+ to_dual_lt_to_dual],
1122
+ exact forall₂_congr (λ _ _, iff.rfl)
1123
+ end
972
1124
973
1125
end has_lt
974
1126
975
1127
instance [preorder α] : preorder (with_top α) :=
976
1128
{ le := (≤),
977
1129
lt := (<),
978
- lt_iff_le_not_le := by { intros, cases a; cases b; simp [lt_iff_le_not_le]; simp [(<), (≤)] },
979
- le_refl := λ o a ha, ⟨a, ha, le_rfl⟩,
980
- le_trans := λ o₁ o₂ o₃ h₁ h₂ c hc,
981
- let ⟨b, hb, bc⟩ := h₂ c hc, ⟨a, ha, ab⟩ := h₁ b hb in
982
- ⟨a, ha, le_trans ab bc⟩ }
1130
+ lt_iff_le_not_le := by simp [←to_dual_lt_to_dual_iff, lt_iff_le_not_le],
1131
+ le_refl := λ _, to_dual_le_to_dual_iff.mp le_rfl,
1132
+ le_trans := λ _ _ _, by { simp_rw [←to_dual_le_to_dual_iff], exact function.swap le_trans } }
983
1133
984
1134
instance [partial_order α] : partial_order (with_top α) :=
985
- { le_antisymm := λ o₁ o₂ h₁ h₂, begin
986
- cases o₂ with b,
987
- { cases o₁ with a, {refl},
988
- rcases h₂ a rfl with ⟨_, ⟨⟩, _⟩ },
989
- { rcases h₁ b rfl with ⟨a, ⟨⟩, h₁'⟩,
990
- rcases h₂ a rfl with ⟨_, ⟨⟩, h₂'⟩,
991
- rw le_antisymm h₁' h₂' }
992
- end ,
1135
+ { le_antisymm := λ _ _, by { simp_rw [←to_dual_le_to_dual_iff], exact function.swap le_antisymm },
993
1136
.. with_top.preorder }
994
1137
995
1138
lemma map_le_iff [preorder α] [preorder β] (f : α → β)
996
1139
(a b : with_top α) (mono_iff : ∀ {a b}, f a ≤ f b ↔ a ≤ b) :
997
1140
a.map f ≤ b.map f ↔ a ≤ b :=
998
- @with_bot.map_le_iff αᵒᵈ βᵒᵈ _ _ f (λ a b, mono_iff) b a
1141
+ begin
1142
+ rw [←to_dual_le_to_dual_iff, to_dual_map, to_dual_map, with_bot.map_le_iff,
1143
+ to_dual_le_to_dual_iff],
1144
+ simp [mono_iff]
1145
+ end
999
1146
1000
1147
instance [semilattice_inf α] : semilattice_inf (with_top α) :=
1001
1148
{ inf := option.lift_or_get (⊓),
@@ -1039,13 +1186,13 @@ instance [lattice α] : lattice (with_top α) :=
1039
1186
{ ..with_top.semilattice_sup, ..with_top.semilattice_inf }
1040
1187
1041
1188
instance decidable_le [has_le α] [@decidable_rel α (≤)] : @decidable_rel (with_top α) (≤) :=
1042
- λ x y, @ with_bot.decidable_le αᵒᵈ _ _ y x
1189
+ λ _ _, decidable_of_decidable_of_iff ( with_bot.decidable_le _ _) (to_dual_le_to_dual_iff)
1043
1190
1044
1191
instance decidable_lt [has_lt α] [@decidable_rel α (<)] : @decidable_rel (with_top α) (<) :=
1045
- λ x y, @ with_bot.decidable_lt αᵒᵈ _ _ y x
1192
+ λ _ _, decidable_of_decidable_of_iff ( with_bot.decidable_lt _ _) (to_dual_lt_to_dual_iff)
1046
1193
1047
1194
instance is_total_le [has_le α] [is_total α (≤)] : is_total (with_top α) (≤) :=
1048
- @order_dual.is_total_le (with_bot αᵒᵈ) _ _
1195
+ ⟨λ _ _, by { simp_rw ←to_dual_le_to_dual_iff, exact total_of _ _ _ }⟩
1049
1196
1050
1197
instance [linear_order α] : linear_order (with_top α) := lattice.to_linear_order _
1051
1198
@@ -1066,11 +1213,25 @@ have acc_some : ∀ a : α, acc ((<) : with_top α → with_top α → Prop) (so
1066
1213
(λ _ _, acc_some _))) acc_some⟩
1067
1214
1068
1215
lemma well_founded_gt [preorder α] (h : @well_founded α (>)) : @well_founded (with_top α) (>) :=
1069
- @with_bot.well_founded_lt αᵒᵈ _ h
1216
+ ⟨λ a, begin
1217
+ -- ideally, use rel_hom_class.acc, but that is defined later
1218
+ have : acc (<) a.to_dual := well_founded.apply (with_bot.well_founded_lt h) _,
1219
+ revert this ,
1220
+ generalize ha : a.to_dual = b, intro ac,
1221
+ induction ac with _ H IH generalizing a, subst ha,
1222
+ exact ⟨_, λ a' h, IH (a'.to_dual) (to_dual_lt_to_dual.mpr h) _ rfl⟩
1223
+ end ⟩
1070
1224
1071
1225
lemma _root_.with_bot.well_founded_gt [preorder α] (h : @well_founded α (>)) :
1072
1226
@well_founded (with_bot α) (>) :=
1073
- @with_top.well_founded_lt αᵒᵈ _ h
1227
+ ⟨λ a, begin
1228
+ -- ideally, use rel_hom_class.acc, but that is defined later
1229
+ have : acc (<) a.to_dual := well_founded.apply (with_top.well_founded_lt h) _,
1230
+ revert this ,
1231
+ generalize ha : a.to_dual = b, intro ac,
1232
+ induction ac with _ H IH generalizing a, subst ha,
1233
+ exact ⟨_, λ a' h, IH (a'.to_dual) (to_dual_lt_to_dual.mpr h) _ rfl⟩
1234
+ end ⟩
1074
1235
1075
1236
instance trichotomous.lt [preorder α] [is_trichotomous α (<)] : is_trichotomous (with_top α) (<) :=
1076
1237
⟨begin
0 commit comments