@@ -12,6 +12,8 @@ set_option old_structure_cmd true
12
12
universe u
13
13
variable {α : Type u}
14
14
15
+ /-- An `ordered_semiring α` is a semiring `α` with a partial order such that
16
+ multiplication with a positive number and addition are monotone. -/
15
17
class ordered_semiring (α : Type u) extends semiring α, ordered_cancel_add_comm_monoid α :=
16
18
(mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b)
17
19
(mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c)
53
55
a * b ≤ c * b : mul_le_mul_of_nonneg_right hac nn_b
54
56
... ≤ c * d : mul_le_mul_of_nonneg_left hbd nn_c
55
57
56
- lemma mul_nonneg (ha : a ≥ 0 ) (hb : b ≥ 0 ) : a * b ≥ 0 :=
58
+ lemma mul_nonneg (ha : 0 ≤ a ) (hb : 0 ≤ b ) : 0 ≤ a * b :=
57
59
have h : 0 * b ≤ a * b, from mul_le_mul_of_nonneg_right ha hb,
58
60
by rwa [zero_mul] at h
59
61
60
- -- `mul_nonneg` and `mul_pos` in core are stated in terms of `≥` and `>`, so we restate them here
61
- -- for use in syntactic tactics (e.g. `simp` and `rw`).
62
- lemma mul_nonneg' : 0 ≤ a → 0 ≤ b → 0 ≤ a * b :=
63
- mul_nonneg
64
-
65
62
lemma mul_nonpos_of_nonneg_of_nonpos (ha : a ≥ 0 ) (hb : b ≤ 0 ) : a * b ≤ 0 :=
66
63
have h : a * b ≤ a * 0 , from mul_le_mul_of_nonneg_left hb ha,
67
64
by rwa mul_zero at h
80
77
a * b ≤ c * b : mul_le_mul_of_nonneg_right h1 h3
81
78
... < c * d : mul_lt_mul_of_pos_left h2 h4
82
79
83
- lemma mul_pos (ha : a > 0 ) (hb : b > 0 ) : a * b > 0 :=
80
+ lemma mul_pos (ha : 0 < a ) (hb : 0 < b ) : 0 < a * b :=
84
81
have h : 0 * b < a * b, from mul_lt_mul_of_pos_right ha hb,
85
82
by rwa zero_mul at h
86
83
87
- lemma mul_pos' (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
88
- mul_pos ha hb
89
-
90
84
lemma mul_neg_of_pos_of_neg (ha : a > 0 ) (hb : b < 0 ) : a * b < 0 :=
91
85
have h : a * b < a * 0 , from mul_lt_mul_of_pos_left hb ha,
92
86
by rwa mul_zero at h
@@ -103,6 +97,8 @@ mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2)
103
97
104
98
end ordered_semiring
105
99
100
+ /-- A `linear_ordered_semiring α` is a semiring `α` with a linear order
101
+ such that multiplication with a positive number and addition are monotone. -/
106
102
class linear_ordered_semiring (α : Type u) extends ordered_semiring α, linear_order α :=
107
103
(zero_lt_one : zero < one)
108
104
@@ -120,14 +116,14 @@ lemma two_pos : 0 < (2:α) := add_pos zero_lt_one zero_lt_one
120
116
@[field_simps] lemma two_ne_zero : (2 :α) ≠ 0 :=
121
117
ne.symm (ne_of_lt two_pos)
122
118
123
- lemma two_gt_one : (2 :α) > 1 :=
119
+ lemma two_gt_one : 1 < (2 :α) :=
124
120
calc (2 :α) = 1 +1 : one_add_one_eq_two
125
121
... > 1 +0 : add_lt_add_left zero_lt_one _
126
122
... = 1 : add_zero 1
127
123
128
- lemma two_ge_one : (2 :α) ≥ 1 := le_of_lt two_gt_one
124
+ lemma two_ge_one : 1 ≤ (2 :α) := le_of_lt two_gt_one
129
125
130
- lemma four_pos : (4 :α) > 0 := add_pos two_pos two_pos
126
+ lemma four_pos : 0 < (4 :α) := add_pos two_pos two_pos
131
127
132
128
lemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : c ≥ 0 ) : a < b :=
133
129
lt_of_not_ge
@@ -415,7 +411,10 @@ lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0
415
411
416
412
end mono
417
413
418
- class decidable_linear_ordered_semiring (α : Type u) extends linear_ordered_semiring α, decidable_linear_order α
414
+ /-- A `decidable_linear_ordered_semiring α` is a semiring `α` with a decidable linear order
415
+ such that multiplication with a positive number and addition are monotone. -/
416
+ class decidable_linear_ordered_semiring (α : Type u)
417
+ extends linear_ordered_semiring α, decidable_linear_order α
419
418
420
419
section decidable_linear_ordered_semiring
421
420
variables [decidable_linear_ordered_semiring α] {a b c : α}
@@ -428,6 +427,8 @@ decidable.le_iff_le_iff_lt_iff_lt.2 $ mul_lt_mul_right h
428
427
429
428
end decidable_linear_ordered_semiring
430
429
430
+ /-- An `ordered_ring α` is a ring `α` with a partial order such that
431
+ multiplication with a positive number and addition are monotone. -/
431
432
class ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α, zero_ne_one_class α :=
432
433
(mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b)
433
434
@@ -517,6 +518,8 @@ by rwa zero_mul at this
517
518
518
519
end ordered_ring
519
520
521
+ /-- A `linear_ordered_ring α` is a ring `α` with a linear order such that
522
+ multiplication with a positive number and addition are monotone. -/
520
523
class linear_ordered_ring (α : Type u) extends ordered_ring α, linear_order α :=
521
524
(zero_lt_one : zero < one)
522
525
@@ -534,13 +537,13 @@ instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semirin
534
537
le_total := linear_ordered_ring.le_total,
535
538
..‹linear_ordered_ring α› }
536
539
537
- lemma mul_self_nonneg (a : α) : a * a ≥ 0 :=
540
+ lemma mul_self_nonneg (a : α) : 0 ≤ a * a :=
538
541
or.elim (le_total 0 a)
539
542
(assume h : a ≥ 0 , mul_nonneg h h)
540
543
(assume h : a ≤ 0 , mul_nonneg_of_nonpos_of_nonpos h h)
541
544
542
- lemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : a * b > 0 ) :
543
- (a > 0 ∧ b > 0 ) ∨ (a < 0 ∧ b < 0 ) :=
545
+ lemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :
546
+ (0 < a ∧ 0 < b ) ∨ (a < 0 ∧ b < 0 ) :=
544
547
match lt_trichotomy 0 a with
545
548
| or.inl hlt₁ :=
546
549
match lt_trichotomy 0 b with
@@ -557,8 +560,8 @@ match lt_trichotomy 0 a with
557
560
end
558
561
end
559
562
560
- lemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c ≤ 0 ) : a > b :=
561
- have nhc : -c ≥ 0 , from neg_nonneg_of_nonpos hc,
563
+ lemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c ≤ 0 ) : b < a :=
564
+ have nhc : 0 ≤ -c , from neg_nonneg_of_nonpos hc,
562
565
have h2 : -(c * b) < -(c * a), from neg_lt_neg h,
563
566
have h3 : (-c) * b < (-c) * a, from calc
564
567
(-c) * b = - (c * b) : by rewrite neg_mul_eq_neg_mul
@@ -676,12 +679,17 @@ end
676
679
677
680
end linear_ordered_ring
678
681
682
+ /-- A `linear_ordered_comm_ring α` is a commutative ring `α` with a linear order
683
+ such that multiplication with a positive number and addition are monotone. -/
679
684
class linear_ordered_comm_ring (α : Type u) extends linear_ordered_ring α, comm_monoid α
680
685
681
686
instance linear_ordered_comm_ring.to_integral_domain [s: linear_ordered_comm_ring α] : integral_domain α :=
682
687
{ eq_zero_or_eq_zero_of_mul_eq_zero := @linear_ordered_ring.eq_zero_or_eq_zero_of_mul_eq_zero α _,
683
688
..s }
684
689
690
+ /-- A `decidable_linear_ordered_comm_ring α` is a commutative ring `α` with a
691
+ decidable linear order such that multiplication with a positive number and
692
+ addition are monotone. -/
685
693
class decidable_linear_ordered_comm_ring (α : Type u) extends linear_ordered_comm_ring α,
686
694
decidable_linear_ordered_add_comm_group α
687
695
@@ -827,6 +835,8 @@ instance to_ordered_ring : ordered_ring α :=
827
835
mul_pos := λ a b, by simp [pos_def.symm]; exact mul_pos,
828
836
..‹nonneg_ring α› }
829
837
838
+ /-- `to_linear_nonneg_ring` shows that a `nonneg_ring` with a total order is a `domain`,
839
+ hence a `linear_nonneg_ring`. -/
830
840
def to_linear_nonneg_ring
831
841
(nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a))
832
842
: linear_nonneg_ring α :=
@@ -907,6 +917,9 @@ def to_decidable_linear_ordered_comm_ring
907
917
908
918
end linear_nonneg_ring
909
919
920
+ /-- A canonically ordered commutative semiring is an ordered, commutative semiring
921
+ in which `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the
922
+ natural numbers, for example, but not the integers or other ordered groups. -/
910
923
class canonically_ordered_comm_semiring (α : Type *) extends
911
924
canonically_ordered_add_monoid α, comm_semiring α, zero_ne_one_class α :=
912
925
(mul_eq_zero_iff (a b : α) : a * b = 0 ↔ a = 0 ∨ b = 0 )
@@ -935,31 +948,33 @@ by simp only [zero_lt_iff_ne_zero, ne.def, canonically_ordered_comm_semiring.mul
935
948
end canonically_ordered_semiring
936
949
937
950
namespace with_top
938
- variables [canonically_ordered_comm_semiring α] [decidable_eq α]
939
-
940
- instance : mul_zero_class (with_top α) :=
941
- { zero := 0 ,
942
- mul := λm n, if m = 0 ∨ n = 0 then 0 else m.bind (λa, n.bind $ λb, ↑(a * b)),
943
- zero_mul := assume a, if_pos $ or.inl rfl,
944
- mul_zero := assume a, if_pos $ or.inr rfl }
951
+ variables [canonically_ordered_comm_semiring α]
945
952
946
953
instance : has_one (with_top α) := ⟨↑(1 :α)⟩
947
954
948
- lemma mul_def {a b : with_top α} :
949
- a * b = if a = 0 ∨ b = 0 then 0 else a.bind (λa, b.bind $ λb, ↑(a * b)) := rfl
950
-
951
- @[simp] theorem top_ne_zero [partial_order α] : ⊤ ≠ (0 : with_top α) .
952
- @[simp] theorem zero_ne_top [partial_order α] : (0 : with_top α) ≠ ⊤ .
955
+ @[simp] theorem top_ne_zero : ⊤ ≠ (0 : with_top α) .
956
+ @[simp] theorem zero_ne_top : (0 : with_top α) ≠ ⊤ .
953
957
954
- @[simp] theorem coe_eq_zero [partial_order α] {a : α} : (a : with_top α) = 0 ↔ a = 0 :=
958
+ @[simp] theorem coe_eq_zero {a : α} : (a : with_top α) = 0 ↔ a = 0 :=
955
959
iff.intro
956
960
(assume h, match a, h with _, rfl := rfl end )
957
961
(assume h, h.symm ▸ rfl)
958
962
959
- @[simp] theorem zero_eq_coe [partial_order α] {a : α} : 0 = (a : with_top α) ↔ a = 0 :=
963
+ @[simp] theorem zero_eq_coe {a : α} : 0 = (a : with_top α) ↔ a = 0 :=
960
964
by rw [eq_comm, coe_eq_zero]
961
965
962
- @[simp] theorem coe_zero [partial_order α] : ↑(0 : α) = (0 : with_top α) := rfl
966
+ @[simp] theorem coe_zero : ↑(0 : α) = (0 : with_top α) := rfl
967
+
968
+ variable [decidable_eq α]
969
+
970
+ instance : mul_zero_class (with_top α) :=
971
+ { zero := 0 ,
972
+ mul := λm n, if m = 0 ∨ n = 0 then 0 else m.bind (λa, n.bind $ λb, ↑(a * b)),
973
+ zero_mul := assume a, if_pos $ or.inl rfl,
974
+ mul_zero := assume a, if_pos $ or.inr rfl }
975
+
976
+ lemma mul_def {a b : with_top α} :
977
+ a * b = if a = 0 ∨ b = 0 then 0 else a.bind (λa, b.bind $ λb, ↑(a * b)) := rfl
963
978
964
979
@[simp] lemma mul_top {a : with_top α} (h : a ≠ 0 ) : a * ⊤ = ⊤ :=
965
980
by cases a; simp [mul_def, h]; refl
@@ -1029,8 +1044,7 @@ private lemma one_mul' : ∀a : with_top α, 1 * a = a
1029
1044
| none := show ((1 :α) : with_top α) * ⊤ = ⊤, by simp [-with_bot.coe_one]
1030
1045
| (some a) := show ((1 :α) : with_top α) * a = a, by simp [coe_mul.symm, -with_bot.coe_one]
1031
1046
1032
- instance [canonically_ordered_comm_semiring α] [decidable_eq α] :
1033
- canonically_ordered_comm_semiring (with_top α) :=
1047
+ instance : canonically_ordered_comm_semiring (with_top α) :=
1034
1048
{ one := (1 : α),
1035
1049
right_distrib := distrib',
1036
1050
left_distrib := assume a b c, by rw [comm, distrib', comm b, comm c]; refl,
0 commit comments