@@ -3,9 +3,7 @@ Copyright (c) 2014 Robert Lewis. All rights reserved.
3
3
Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Robert Lewis, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
5
5
-/
6
-
7
6
import Mathlib.Algebra.Ring.Defs
8
- import Std.Data.Rat.Basic
9
7
import Mathlib.Data.Rat.Init
10
8
11
9
#align_import algebra.field.defs from "leanprover-community/mathlib" @"2651125b48fc5c170ab1111afd0817c903b1fc6c"
@@ -47,61 +45,84 @@ a `GroupWithZero` lemma instead.
47
45
field, division ring, skew field, skew-field, skewfield
48
46
-/
49
47
48
+ -- `NeZero` should not be needed in the basic algebraic hierarchy.
49
+ assert_not_exists NeZero
50
+
51
+ -- Check that we have not imported `Mathlib.Tactic.Common` yet.
52
+ assert_not_exists Mathlib.Tactic.LibrarySearch.librarySearch
53
+
54
+ assert_not_exists MonoidHom
50
55
51
56
open Function Set
52
57
53
58
universe u
54
59
55
60
variable {α β K : Type *}
56
61
57
- /-- The default definition of the coercion `(↑(a : ℚ) : K)` for a division ring `K`
58
- is defined as `(a / b : K) = (a : K) * (b : K)⁻¹`.
59
- Use `coe` instead of `Rat.castRec` for better definitional behaviour.
60
- -/
61
- def Rat.castRec [NatCast K] [IntCast K] [Mul K] [Inv K] : ℚ → K
62
- | ⟨a, b, _, _⟩ => ↑a * (↑b)⁻¹
62
+ /-- The default definition of the coercion `ℚ → K` for a division ring `K`.
63
+
64
+ `↑q : K` is defined as `(q.num : K) * (q.den : K)⁻¹`.
65
+
66
+ Do not use this directly (instances of `DivisionRing` are allowed to override that default for
67
+ better definitional properties). Instead, use the coercion. -/
68
+ def Rat.castRec [NatCast K] [IntCast K] [Mul K] [Inv K] (q : ℚ) : K := q.num * (q.den : K)⁻¹
63
69
#align rat.cast_rec Rat.castRec
64
70
65
- /-- The default definition of the scalar multiplication `(a : ℚ) • (x : K)` for a division ring `K`
66
- is given by `a • x = (↑ a) * x`.
67
- Use `(a : ℚ) • (x : K)` instead of `qsmulRec` for better definitional behaviour.
68
- -/
71
+ /-- The default definition of the scalar multiplication by `ℚ` on a division ring `K`.
72
+
73
+ `q • x` is defined as `↑q * x`.
74
+
75
+ Do not use directly (instances of `DivisionRing` are allowed to override that default for
76
+ better definitional properties). Instead use the `•` notation. -/
69
77
def qsmulRec (coe : ℚ → K) [Mul K] (a : ℚ) (x : K) : K :=
70
78
coe a * x
71
79
#align qsmul_rec qsmulRec
72
80
73
- /-- A `DivisionSemiring` is a `Semiring` with multiplicative inverses for nonzero elements. -/
74
- class DivisionSemiring (α : Type *) extends Semiring α, GroupWithZero α
81
+ /-- A `DivisionSemiring` is a `Semiring` with multiplicative inverses for nonzero elements.
82
+
83
+ An instance of `DivisionSemiring K` includes maps `nnratCast : ℚ≥0 → K` and `nnqsmul : ℚ≥0 → K → K`.
84
+ Those two fields are needed to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance since we
85
+ need to control the specific definitions for some special cases of `K` (in particular `K = ℚ≥0`
86
+ itself). See also note [forgetful inheritance].
87
+
88
+ If the division semiring has positive characteristic `p`, our division by zero convention forces
89
+ `nnratCast (1 / p) = 1 / 0 = 0`. -/
90
+ class DivisionSemiring (α : Type *) extends Semiring α, GroupWithZero α where
75
91
#align division_semiring DivisionSemiring
76
92
77
93
/-- A `DivisionRing` is a `Ring` with multiplicative inverses for nonzero elements.
78
94
79
95
An instance of `DivisionRing K` includes maps `ratCast : ℚ → K` and `qsmul : ℚ → K → K`.
80
- If the division ring has positive characteristic p, we define `ratCast (1 / p) = 1 / 0 = 0`
81
- for consistency with our division by zero convention.
82
- The fields `ratCast` and `qsmul` are needed to implement the
83
- `algebraRat [DivisionRing K] : Algebra ℚ K` instance, since we need to control the specific
84
- definitions for some special cases of `K` (in particular `K = ℚ` itself).
85
- See also Note [forgetful inheritance].
86
- -/
87
- class DivisionRing (K : Type u) extends Ring K, DivInvMonoid K, Nontrivial K, RatCast K where
96
+ Those two fields are needed to implement the `DivisionRing K → Algebra ℚ K` instance since we need
97
+ to control the specific definitions for some special cases of `K` (in particular `K = ℚ` itself).
98
+ See also note [forgetful inheritance]. Similarly, there are maps `nnratCast ℚ≥0 → K` and
99
+ `nnqsmul : ℚ≥0 → K → K` to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance.
100
+
101
+ If the division ring has positive characteristic `p`, our division by zero convention forces
102
+ `ratCast (1 / p) = 1 / 0 = 0`. -/
103
+ class DivisionRing (α : Type *)
104
+ extends Ring α, DivInvMonoid α, Nontrivial α, RatCast α where
88
105
/-- For a nonzero `a`, `a⁻¹` is a right multiplicative inverse. -/
89
- protected mul_inv_cancel : ∀ (a : K ), a ≠ 0 → a * a⁻¹ = 1
90
- /-- We define the inverse of `0` to be `0`. -/
91
- protected inv_zero : (0 : K )⁻¹ = 0
106
+ protected mul_inv_cancel : ∀ (a : α ), a ≠ 0 → a * a⁻¹ = 1
107
+ /-- The inverse of `0` is `0` by convention . -/
108
+ protected inv_zero : (0 : α )⁻¹ = 0
92
109
protected ratCast := Rat.castRec
93
- /-- However `ratCast` is defined, propositionally it must be equal to `a * b⁻¹`. -/
94
- protected ratCast_mk : ∀ (a : ℤ) (b : ℕ) (h1 h2), Rat.cast ⟨a, b, h1, h2⟩ = a * (b : K)⁻¹ := by
95
- intros
96
- rfl
97
- /-- Multiplication by a rational number.
98
- Set this to `qsmulRec _` unless there is a risk of a `Module ℚ _` instance diamond. -/
99
- protected qsmul : ℚ → K → K
100
- /-- However `qsmul` is defined,
101
- propositionally it must be equal to multiplication by `ratCast`. -/
102
- protected qsmul_eq_mul' : ∀ (a : ℚ) (x : K), qsmul a x = Rat.cast a * x := by
110
+ /-- However `Rat.cast` is defined, it must be propositionally equal to `a * b⁻¹`.
111
+
112
+ Do not use this lemma directly. Use `Rat.cast_def` instead. -/
113
+ protected ratCast_mk : ∀ (a : ℤ) (b : ℕ) (h1 h2), Rat.cast ⟨a, b, h1, h2⟩ = a * (b : α)⁻¹ := by
103
114
intros
104
115
rfl
116
+ /-- Scalar multiplication by a rational number.
117
+
118
+ Set this to `qsmulRec _` unless there is a risk of a `Module ℚ _` instance diamond.
119
+
120
+ Do not use directly. Instead use the `•` notation. -/
121
+ protected qsmul : ℚ → α → α
122
+ /-- However `qsmul` is defined, it must be propositionally equal to multiplication by `Rat.cast`.
123
+
124
+ Do not use this lemma directly. Use `Rat.cast_def` instead. -/
125
+ protected qsmul_eq_mul' (a : ℚ) (x : α) : qsmul a x = Rat.cast a * x := by intros; rfl
105
126
#align division_ring DivisionRing
106
127
#align division_ring.rat_cast_mk DivisionRing.ratCast_mk
107
128
@@ -110,28 +131,36 @@ instance (priority := 100) DivisionRing.toDivisionSemiring [DivisionRing α] : D
110
131
{ ‹DivisionRing α› with }
111
132
#align division_ring.to_division_semiring DivisionRing.toDivisionSemiring
112
133
113
- /-- A `Semifield` is a `CommSemiring` with multiplicative inverses for nonzero elements. -/
134
+ /-- A `Semifield` is a `CommSemiring` with multiplicative inverses for nonzero elements.
135
+
136
+ An instance of `Semifield K` includes maps `nnratCast : ℚ≥0 → K` and `nnqsmul : ℚ≥0 → K → K`.
137
+ Those two fields are needed to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance since we
138
+ need to control the specific definitions for some special cases of `K` (in particular `K = ℚ≥0`
139
+ itself). See also note [forgetful inheritance].
140
+
141
+ If the semifield has positive characteristic `p`, our division by zero convention forces
142
+ `nnratCast (1 / p) = 1 / 0 = 0`. -/
114
143
class Semifield (α : Type *) extends CommSemiring α, DivisionSemiring α, CommGroupWithZero α
115
144
#align semifield Semifield
116
145
117
146
/-- A `Field` is a `CommRing` with multiplicative inverses for nonzero elements.
118
147
119
148
An instance of `Field K` includes maps `ratCast : ℚ → K` and `qsmul : ℚ → K → K`.
120
- If the field has positive characteristic p, we define `ratCast (1 / p) = 1 / 0 = 0`
121
- for consistency with our division by zero convention.
122
- The fields `ratCast` and `qsmul` are needed to implement the
123
- `algebraRat [DivisionRing K] : Algebra ℚ K` instance, since we need to control the specific
124
- definitions for some special cases of `K` (in particular `K = ℚ` itself).
125
- See also Note [forgetful inheritance].
126
- -/
149
+ Those two fields are needed to implement the `DivisionRing K → Algebra ℚ K` instance since we need
150
+ to control the specific definitions for some special cases of `K` (in particular `K = ℚ` itself).
151
+ See also note [forgetful inheritance].
152
+
153
+ If the field has positive characteristic `p`, our division by zero convention forces
154
+ `ratCast (1 / p) = 1 / 0 = 0`. -/
127
155
class Field (K : Type u) extends CommRing K, DivisionRing K
128
156
#align field Field
129
157
130
- section DivisionRing
131
-
132
- variable [DivisionRing K] {a b : K}
158
+ -- see Note [lower instance priority]
159
+ instance (priority := 100 ) Field.toSemifield [Field α] : Semifield α := { ‹Field α› with }
160
+ #align field.to_semifield Field.toSemifield
133
161
134
162
namespace Rat
163
+ variable [DivisionRing K] {a b : K}
135
164
136
165
theorem cast_mk' (a b h1 h2) : ((⟨a, b, h1, h2⟩ : ℚ) : K) = a * (b : K)⁻¹ :=
137
166
DivisionRing.ratCast_mk _ _ _ _
@@ -145,8 +174,7 @@ instance (priority := 100) smulDivisionRing : SMul ℚ K :=
145
174
⟨DivisionRing.qsmul⟩
146
175
#align rat.smul_division_ring Rat.smulDivisionRing
147
176
148
- theorem smul_def (a : ℚ) (x : K) : a • x = ↑a * x :=
149
- DivisionRing.qsmul_eq_mul' a x
177
+ theorem smul_def (a : ℚ) (x : K) : a • x = ↑a * x := DivisionRing.qsmul_eq_mul' a x
150
178
#align rat.smul_def Rat.smul_def
151
179
152
180
@[simp]
@@ -156,32 +184,5 @@ theorem smul_one_eq_coe (A : Type*) [DivisionRing A] (m : ℚ) : m • (1 : A) =
156
184
157
185
end Rat
158
186
159
- end DivisionRing
160
-
161
- section OfScientific
162
-
163
187
instance RatCast.toOfScientific [RatCast K] : OfScientific K where
164
188
ofScientific (m : ℕ) (b : Bool) (d : ℕ) := Rat.ofScientific m b d
165
-
166
- end OfScientific
167
-
168
- section Field
169
-
170
- variable [Field K]
171
-
172
- -- see Note [lower instance priority]
173
- instance (priority := 100 ) Field.toSemifield : Semifield K :=
174
- { ‹Field K› with }
175
- #align field.to_semifield Field.toSemifield
176
-
177
- end Field
178
-
179
- /-
180
- `NeZero` should not be needed in the basic algebraic hierarchy.
181
- -/
182
- assert_not_exists NeZero
183
-
184
- /-
185
- Check that we have not imported `Mathlib.Tactic.Common` yet.
186
- -/
187
- assert_not_exists Mathlib.Tactic.LibrarySearch.librarySearch
0 commit comments