@@ -928,7 +928,7 @@ in which `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by t
928
928
natural numbers, for example, but not the integers or other ordered groups. -/
929
929
class canonically_ordered_comm_semiring (α : Type *) extends
930
930
canonically_ordered_add_monoid α, comm_semiring α :=
931
- (mul_eq_zero_iff ( a b : α) : a * b = 0 ↔ a = 0 ∨ b = 0 )
931
+ (eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0 )
932
932
(zero_ne_one : (0 : α) ≠ 1 )
933
933
934
934
namespace canonically_ordered_semiring
@@ -939,6 +939,10 @@ open canonically_ordered_add_monoid (le_iff_exists_add)
939
939
instance canonically_ordered_comm_semiring.to_nonzero : nonzero α :=
940
940
⟨canonically_ordered_comm_semiring.zero_ne_one⟩
941
941
942
+ instance canonically_ordered_comm_semiring.to_no_zero_divisors :
943
+ no_zero_divisors α :=
944
+ ⟨canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero⟩
945
+
942
946
lemma mul_le_mul {a b c d : α} (hab : a ≤ b) (hcd : c ≤ d) :
943
947
a * c ≤ b * d :=
944
948
begin
@@ -952,22 +956,21 @@ end
952
956
lemma zero_lt_one : (0 :α) < 1 := lt_of_le_of_ne (zero_le 1 ) zero_ne_one
953
957
954
958
lemma mul_pos : 0 < a * b ↔ (0 < a) ∧ (0 < b) :=
955
- by simp only [zero_lt_iff_ne_zero, ne.def, canonically_ordered_comm_semiring.mul_eq_zero_iff,
956
- not_or_distrib]
959
+ by simp only [zero_lt_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]
957
960
958
961
end canonically_ordered_semiring
959
962
960
963
namespace with_top
961
- variables [canonically_ordered_comm_semiring α]
962
964
963
- @[simp] theorem top_ne_zero : ⊤ ≠ (0 : with_top α) .
964
- @[simp] theorem zero_ne_top : (0 : with_top α) ≠ ⊤ .
965
-
966
- @[simp] theorem zero_eq_coe {a : α} : 0 = (a : with_top α) ↔ a = 0 :=
967
- by rw [eq_comm, coe_eq_zero]
965
+ instance [has_zero α] [has_one α] [nonzero α] : nonzero (with_top α) :=
966
+ ⟨mt coe_eq_coe.1 zero_ne_one⟩
968
967
969
968
variable [decidable_eq α]
970
969
970
+ section has_mul
971
+
972
+ variables [has_zero α] [has_mul α]
973
+
971
974
instance : mul_zero_class (with_top α) :=
972
975
{ zero := 0 ,
973
976
mul := λm n, if m = 0 ∨ n = 0 then 0 else m.bind (λa, n.bind $ λb, ↑(a * b)),
@@ -986,7 +989,13 @@ by cases a; simp [mul_def, h]; refl
986
989
@[simp] lemma top_mul_top : (⊤ * ⊤ : with_top α) = ⊤ :=
987
990
top_mul top_ne_zero
988
991
989
- lemma coe_mul {a b : α} : (↑(a * b) : with_top α) = a * b :=
992
+ end has_mul
993
+
994
+ section mul_zero_class
995
+
996
+ variables [mul_zero_class α]
997
+
998
+ @[norm_cast] lemma coe_mul {a b : α} : (↑(a * b) : with_top α) = a * b :=
990
999
decidable.by_cases (assume : a = 0 , by simp [this ]) $ assume ha,
991
1000
decidable.by_cases (assume : b = 0 , by simp [this ]) $ assume hb,
992
1001
by simp [*, mul_def]; refl
@@ -996,22 +1005,38 @@ lemma mul_coe {b : α} (hb : b ≠ 0) : ∀{a : with_top α}, a * b = a.bind (λ
996
1005
by simp [hb]
997
1006
| (some a) := show ↑a * ↑b = ↑(a * b), from coe_mul.symm
998
1007
1008
+ @[simp] lemma mul_eq_top_iff {a b : with_top α} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0 ) :=
1009
+ begin
1010
+ cases a; cases b; simp only [none_eq_top, some_eq_coe],
1011
+ { simp [← coe_mul] },
1012
+ { suffices : ⊤ * (b : with_top α) = ⊤ ↔ b ≠ 0 , by simpa,
1013
+ by_cases hb : b = 0 ; simp [hb] },
1014
+ { suffices : (a : with_top α) * ⊤ = ⊤ ↔ a ≠ 0 , by simpa,
1015
+ by_cases ha : a = 0 ; simp [ha] },
1016
+ { simp [← coe_mul] }
1017
+ end
1018
+
1019
+ end mul_zero_class
1020
+
1021
+ section no_zero_divisors
1022
+
1023
+ variables [mul_zero_class α] [no_zero_divisors α]
1024
+
1025
+ instance : no_zero_divisors (with_top α) :=
1026
+ ⟨λ a b, by cases a; cases b; dsimp [mul_def]; split_ifs;
1027
+ simp [*, none_eq_top, some_eq_coe, mul_eq_zero] at *⟩
1028
+
1029
+ end no_zero_divisors
1030
+
1031
+ variables [canonically_ordered_comm_semiring α]
1032
+
999
1033
private lemma comm (a b : with_top α) : a * b = b * a :=
1000
1034
begin
1001
1035
by_cases ha : a = 0 , { simp [ha] },
1002
1036
by_cases hb : b = 0 , { simp [hb] },
1003
1037
simp [ha, hb, mul_def, option.bind_comm a b, mul_comm]
1004
1038
end
1005
1039
1006
- @[simp] lemma mul_eq_top_iff {a b : with_top α} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0 ) :=
1007
- begin
1008
- have H : ∀x:α, (¬x = 0 ) ↔ (⊤ : with_top α) * ↑x = ⊤ :=
1009
- λx, ⟨λhx, by simp [top_mul, hx], λhx f, by simpa [f] using hx⟩,
1010
- cases a; cases b; simp [none_eq_top, top_mul, coe_ne_top, some_eq_coe, coe_mul.symm],
1011
- { rw [H b] },
1012
- { rw [H a, comm] }
1013
- end
1014
-
1015
1040
private lemma distrib' (a b c : with_top α) : (a + b) * c = a * c + b * c :=
1016
1041
begin
1017
1042
cases c,
@@ -1023,21 +1048,17 @@ begin
1023
1048
repeat { refl <|> exact congr_arg some (add_mul _ _ _) } }
1024
1049
end
1025
1050
1026
- private lemma mul_eq_zero (a b : with_top α) : a * b = 0 ↔ a = 0 ∨ b = 0 :=
1027
- by cases a; cases b; dsimp [mul_def]; split_ifs;
1028
- simp [*, none_eq_top, some_eq_coe, canonically_ordered_comm_semiring.mul_eq_zero_iff] at *
1029
-
1030
1051
private lemma assoc (a b c : with_top α) : (a * b) * c = a * (b * c) :=
1031
1052
begin
1032
1053
cases a,
1033
1054
{ by_cases hb : b = 0 ; by_cases hc : c = 0 ;
1034
- simp [*, none_eq_top, mul_eq_zero b c ] },
1055
+ simp [*, none_eq_top] },
1035
1056
cases b,
1036
1057
{ by_cases ha : a = 0 ; by_cases hc : c = 0 ;
1037
- simp [*, none_eq_top, some_eq_coe, mul_eq_zero ↑a c ] },
1058
+ simp [*, none_eq_top, some_eq_coe] },
1038
1059
cases c,
1039
1060
{ by_cases ha : a = 0 ; by_cases hb : b = 0 ;
1040
- simp [*, none_eq_top, some_eq_coe, mul_eq_zero ↑a ↑b ] },
1061
+ simp [*, none_eq_top, some_eq_coe] },
1041
1062
simp [some_eq_coe, coe_mul.symm, mul_assoc]
1042
1063
end
1043
1064
@@ -1051,10 +1072,9 @@ instance : canonically_ordered_comm_semiring (with_top α) :=
1051
1072
left_distrib := assume a b c, by rw [comm, distrib', comm b, comm c]; refl,
1052
1073
mul_assoc := assoc,
1053
1074
mul_comm := comm,
1054
- mul_eq_zero_iff := mul_eq_zero,
1055
1075
one_mul := one_mul',
1056
1076
mul_one := assume a, by rw [comm, one_mul'],
1057
- zero_ne_one := assume h : (( 0 : α) : with_top α) = 1 , zero_ne_one $ option.some.inj h ,
1058
- .. with_top.add_comm_monoid , .. with_top.mul_zero_class, .. with_top.canonically_ordered_add_monoid }
1077
+ .. with_top.add_comm_monoid, .. with_top.mul_zero_class, .. with_top.canonically_ordered_add_monoid ,
1078
+ .. with_top.no_zero_divisors , .. with_top.nonzero }
1059
1079
1060
1080
end with_top
0 commit comments