@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Johannes Hölzl, Jens Wagemaker
5
5
-/
6
6
import data.multiset.basic
7
+ import algebra.divisibility
7
8
8
9
/-!
9
10
# Associated, prime, and irreducible elements.
@@ -14,36 +15,23 @@ variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
14
15
lemma is_unit_pow [monoid α] {a : α} (n : ℕ) : is_unit a → is_unit (a ^ n) :=
15
16
λ ⟨u, hu⟩, ⟨u ^ n, by simp *⟩
16
17
17
- theorem is_unit_iff_dvd_one [comm_semiring α] {x : α} : is_unit x ↔ x ∣ 1 :=
18
+ theorem is_unit_iff_dvd_one [comm_monoid α] {x : α} : is_unit x ↔ x ∣ 1 :=
18
19
⟨by rintro ⟨u, rfl⟩; exact ⟨_, u.mul_inv.symm⟩,
19
20
λ ⟨y, h⟩, ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩
20
21
21
- theorem is_unit_iff_forall_dvd [comm_semiring α] {x : α} :
22
+ theorem is_unit_iff_forall_dvd [comm_monoid α] {x : α} :
22
23
is_unit x ↔ ∀ y, x ∣ y :=
23
24
is_unit_iff_dvd_one.trans ⟨λ h y, dvd.trans h (one_dvd _), λ h, h _⟩
24
25
25
- theorem mul_dvd_of_is_unit_left [comm_semiring α] {x y z : α} (h : is_unit x) : x * y ∣ z ↔ y ∣ z :=
26
- ⟨dvd_trans (dvd_mul_left _ _),
27
- dvd_trans $ by simpa using mul_dvd_mul_right (is_unit_iff_dvd_one.1 h) y⟩
28
-
29
- theorem mul_dvd_of_is_unit_right [comm_semiring α] {x y z : α} (h : is_unit y) : x * y ∣ z ↔ x ∣ z :=
30
- by rw [mul_comm, mul_dvd_of_is_unit_left h]
31
-
32
- @[simp] lemma unit_mul_dvd_iff [comm_semiring α] {a b : α} {u : units α} : (u : α) * a ∣ b ↔ a ∣ b :=
33
- mul_dvd_of_is_unit_left (is_unit_unit _)
34
-
35
- lemma mul_unit_dvd_iff [comm_semiring α] {a b : α} {u : units α} : a * u ∣ b ↔ a ∣ b :=
36
- units.coe_mul_dvd _ _ _
37
-
38
- theorem is_unit_of_dvd_unit {α} [comm_semiring α] {x y : α}
26
+ theorem is_unit_of_dvd_unit {α} [comm_monoid α] {x y : α}
39
27
(xy : x ∣ y) (hu : is_unit y) : is_unit x :=
40
28
is_unit_iff_dvd_one.2 $ dvd_trans xy $ is_unit_iff_dvd_one.1 hu
41
29
42
30
theorem is_unit_int {n : ℤ} : is_unit n ↔ n.nat_abs = 1 :=
43
31
⟨begin rintro ⟨u, rfl⟩, exact (int.units_eq_one_or u).elim (by simp) (by simp) end ,
44
32
λ h, is_unit_iff_dvd_one.2 ⟨n, by rw [← int.nat_abs_mul_self, h]; refl⟩⟩
45
33
46
- lemma is_unit_of_dvd_one [comm_semiring α] : ∀a ∣ 1 , is_unit (a:α)
34
+ lemma is_unit_of_dvd_one [comm_monoid α] : ∀a ∣ 1 , is_unit (a:α)
47
35
| a ⟨b, eq⟩ := ⟨units.mk_of_mul_eq_one a b eq.symm, rfl⟩
48
36
49
37
lemma dvd_and_not_dvd_iff [integral_domain α] {x y : α} :
@@ -58,29 +46,33 @@ lemma pow_dvd_pow_iff [integral_domain α] {x : α} {n m : ℕ} (h0 : x ≠ 0) (
58
46
begin
59
47
split,
60
48
{ intro h, rw [← not_lt], intro hmn, apply h1,
61
- have : x * x ^ m ∣ 1 * x ^ m,
62
- { rw [← pow_succ, one_mul ], exact dvd_trans (pow_dvd_pow _ (nat.succ_le_of_lt hmn)) h },
63
- rwa [mul_dvd_mul_iff_right , ← is_unit_iff_dvd_one] at this , apply pow_ne_zero m h0 },
49
+ have : x ^ m * x ∣ x ^ m * 1 ,
50
+ { rw [← pow_succ', mul_one ], exact dvd_trans (pow_dvd_pow _ (nat.succ_le_of_lt hmn)) h },
51
+ rwa [mul_dvd_mul_iff_left , ← is_unit_iff_dvd_one] at this , apply pow_ne_zero m h0 },
64
52
{ apply pow_dvd_pow }
65
53
end
66
54
67
- /-- prime element of a semiring -/
68
- def prime [comm_semiring α] (p : α) : Prop :=
55
+ section prime
56
+ variables [comm_monoid_with_zero α]
57
+
58
+ /-- prime element of a `comm_monoid_with_zero` -/
59
+ def prime (p : α) : Prop :=
69
60
p ≠ 0 ∧ ¬ is_unit p ∧ (∀a b, p ∣ a * b → p ∣ a ∨ p ∣ b)
70
61
71
62
namespace prime
63
+ variables {p : α} (hp : prime p)
72
64
73
- lemma ne_zero [comm_semiring α] {p : α} (hp : prime p) : p ≠ 0 :=
65
+ lemma ne_zero (hp : prime p) : p ≠ 0 :=
74
66
hp.1
75
67
76
- lemma not_unit [comm_semiring α] {p : α} (hp : prime p) : ¬ is_unit p :=
68
+ lemma not_unit (hp : prime p) : ¬ is_unit p :=
77
69
hp.2 .1
78
70
79
- lemma div_or_div [comm_semiring α] {p : α} (hp : prime p) {a b : α} (h : p ∣ a * b) :
71
+ lemma div_or_div (hp : prime p) {a b : α} (h : p ∣ a * b) :
80
72
p ∣ a ∨ p ∣ b :=
81
73
hp.2 .2 a b h
82
74
83
- lemma dvd_of_dvd_pow [comm_semiring α] {p : α} (hp : prime p) {a : α} {n : ℕ} (h : p ∣ a^n) :
75
+ lemma dvd_of_dvd_pow (hp : prime p) {a : α} {n : ℕ} (h : p ∣ a^n) :
84
76
p ∣ a :=
85
77
begin
86
78
induction n with n ih,
96
88
97
89
end prime
98
90
99
- @[simp] lemma not_prime_zero [comm_semiring α] : ¬ prime (0 : α) :=
91
+ @[simp] lemma not_prime_zero : ¬ prime (0 : α) :=
100
92
λ h, h.ne_zero rfl
101
93
102
- @[simp] lemma not_prime_one [comm_semiring α] : ¬ prime (1 : α) :=
94
+ @[simp] lemma not_prime_one : ¬ prime (1 : α) :=
103
95
λ h, h.not_unit is_unit_one
104
96
105
- lemma exists_mem_multiset_dvd_of_prime [comm_semiring α] {s : multiset α} {p : α} (hp : prime p) :
97
+ lemma exists_mem_multiset_dvd_of_prime {s : multiset α} {p : α} (hp : prime p) :
106
98
p ∣ s.prod → ∃a∈s, p ∣ a :=
107
99
multiset.induction_on s (assume h, (hp.not_unit $ is_unit_of_dvd_one _ h).elim) $
108
100
assume a s ih h,
@@ -112,6 +104,8 @@ assume a s ih h,
112
104
| or.inr h := let ⟨a, has, h⟩ := ih h in ⟨a, multiset.mem_cons_of_mem has, h⟩
113
105
end
114
106
107
+ end prime
108
+
115
109
/-- `irreducible p` states that `p` is non-unit and only factors into units.
116
110
117
111
We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a
@@ -134,11 +128,11 @@ end irreducible
134
128
@[simp] theorem not_irreducible_one [monoid α] : ¬ irreducible (1 : α) :=
135
129
by simp [irreducible]
136
130
137
- @[simp] theorem not_irreducible_zero [semiring α] : ¬ irreducible (0 : α)
131
+ @[simp] theorem not_irreducible_zero [monoid_with_zero α] : ¬ irreducible (0 : α)
138
132
| ⟨hn0, h⟩ := have is_unit (0 :α) ∨ is_unit (0 :α), from h 0 0 ((mul_zero 0 ).symm),
139
133
this.elim hn0 hn0
140
134
141
- theorem irreducible.ne_zero [semiring α] : ∀ {p:α}, irreducible p → p ≠ 0
135
+ theorem irreducible.ne_zero [monoid_with_zero α] : ∀ {p:α}, irreducible p → p ≠ 0
142
136
| _ hp rfl := not_irreducible_zero hp
143
137
144
138
theorem of_irreducible_mul {α} [monoid α] {x y : α} :
@@ -179,17 +173,15 @@ have hpd : p ∣ x * y, from ⟨z, by rwa [mul_right_inj' hp0] at h⟩,
179
173
(λ ⟨d, hd⟩, or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩)
180
174
181
175
/-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/
182
- lemma dvd_symm_of_irreducible [comm_semiring α] {p q : α}
176
+ lemma dvd_symm_of_irreducible [monoid α] {p q : α}
183
177
(hp : irreducible p) (hq : irreducible q) : p ∣ q → q ∣ p :=
184
178
begin
185
179
tactic.unfreeze_local_instances,
186
180
rintros ⟨q', rfl⟩,
187
- exact is_unit.mul_right_dvd_of_dvd
188
- (or.resolve_left (of_irreducible_mul hq) hp.not_unit)
189
- (dvd_refl p)
181
+ rw is_unit.mul_right_dvd (or.resolve_left (of_irreducible_mul hq) hp.not_unit),
190
182
end
191
183
192
- lemma dvd_symm_iff_of_irreducible [comm_semiring α] {p q : α}
184
+ lemma dvd_symm_iff_of_irreducible [monoid α] {p q : α}
193
185
(hp : irreducible p) (hq : irreducible q) : p ∣ q ↔ q ∣ p :=
194
186
⟨dvd_symm_of_irreducible hp hq, dvd_symm_of_irreducible hq hp⟩
195
187
@@ -239,25 +231,28 @@ lemma associated_mul_mul [comm_monoid α] {a₁ a₂ b₁ b₂ : α} :
239
231
a₁ ~ᵤ b₁ → a₂ ~ᵤ b₂ → (a₁ * a₂) ~ᵤ (b₁ * b₂)
240
232
| ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ := ⟨c₁ * c₂, by simp [h₁.symm, h₂.symm, mul_assoc, mul_comm, mul_left_comm]⟩
241
233
242
- lemma dvd_of_associated [comm_ring α] {a b : α} : a ~ᵤ b → a ∣ b := λ ⟨u, hu⟩, ⟨u, hu.symm⟩
234
+ lemma dvd_of_associated [monoid α] {a b : α} : a ~ᵤ b → a ∣ b := λ ⟨u, hu⟩, ⟨u, hu.symm⟩
243
235
244
- lemma dvd_dvd_of_associated [comm_ring α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a :=
236
+ lemma dvd_dvd_of_associated [monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a :=
245
237
⟨dvd_of_associated h, dvd_of_associated h.symm⟩
246
238
247
- theorem associated_of_dvd_dvd [integral_domain α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b :=
239
+ theorem associated_of_dvd_dvd [cancel_monoid_with_zero α]
240
+ {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b :=
248
241
begin
249
- haveI := classical.dec_eq α,
250
242
rcases hab with ⟨c, rfl⟩,
251
243
rcases hba with ⟨d, a_eq⟩,
252
244
by_cases ha0 : a = 0 ,
253
245
{ simp [*] at * },
254
- have : a * 1 = a * (c * d),
255
- { simpa [mul_assoc] using a_eq },
256
- have : 1 = (c * d), from mul_left_cancel' ha0 this ,
257
- exact ⟨units.mk_of_mul_eq_one c d (this.symm), by rw [units.mk_of_mul_eq_one, units.val_coe]⟩
246
+ have hac0 : a * c ≠ 0 ,
247
+ { intro con, rw [con, zero_mul] at a_eq, apply ha0 a_eq, },
248
+ have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one],
249
+ have hcd : (c * d) = 1 , from mul_left_cancel' ha0 this ,
250
+ have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one],
251
+ have hdc : d * c = 1 , from mul_left_cancel' hac0 this ,
252
+ exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩
258
253
end
259
254
260
- theorem dvd_dvd_iff_associated [integral_domain α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b :=
255
+ theorem dvd_dvd_iff_associated [cancel_monoid_with_zero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b :=
261
256
⟨λ ⟨h1, h2⟩, associated_of_dvd_dvd h1 h2, dvd_dvd_of_associated⟩
262
257
263
258
lemma exists_associated_mem_of_dvd_prod [integral_domain α] {p : α}
@@ -275,14 +270,11 @@ multiset.induction_on s (by simp [mt is_unit_iff_dvd_one.2 hp.not_unit])
275
270
exact ⟨q, multiset.mem_cons.2 (or.inr hq₁), hq₂⟩ }
276
271
end )
277
272
278
- lemma dvd_iff_dvd_of_rel_left [comm_semiring α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c :=
279
- let ⟨u, hu⟩ := h in hu ▸ mul_unit_dvd_iff.symm
280
-
281
- lemma dvd_mul_unit_iff [comm_semiring α] {a b : α} {u : units α} : a ∣ b * u ↔ a ∣ b :=
282
- units.dvd_coe_mul _ _ _
273
+ lemma dvd_iff_dvd_of_rel_left [comm_monoid_with_zero α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c :=
274
+ let ⟨u, hu⟩ := h in hu ▸ units.mul_right_dvd.symm
283
275
284
276
lemma dvd_iff_dvd_of_rel_right [comm_semiring α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c :=
285
- let ⟨u, hu⟩ := h in hu ▸ dvd_mul_unit_iff .symm
277
+ let ⟨u, hu⟩ := h in hu ▸ units.dvd_mul_right .symm
286
278
287
279
lemma eq_zero_iff_of_associated [comm_semiring α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 :=
288
280
⟨λ ha, let ⟨u, hu⟩ := h in by simp [hu.symm, ha],
@@ -295,7 +287,7 @@ lemma prime_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) (hp : pri
295
287
⟨(ne_zero_iff_of_associated h).1 hp.ne_zero,
296
288
let ⟨u, hu⟩ := h in
297
289
⟨λ ⟨v, hv⟩, hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩,
298
- hu ▸ by { simp [mul_unit_dvd_iff ], intros a b, exact hp.div_or_div }⟩⟩
290
+ hu ▸ by { simp [units.mul_right_dvd ], intros a b, exact hp.div_or_div }⟩⟩
299
291
300
292
lemma prime_iff_of_associated [comm_semiring α] {p q : α}
301
293
(h : p ~ᵤ q) : prime p ↔ prime q :=
@@ -386,11 +378,9 @@ instance : comm_monoid (associates α) :=
386
378
assume a b, show ⟦a * b⟧ = ⟦b * a⟧, by rw [mul_comm] }
387
379
388
380
instance : preorder (associates α) :=
389
- { le := λa b, ∃c, a * c = b,
390
- le_refl := assume a, ⟨1 , by simp⟩,
391
- le_trans := assume a b c ⟨f₁, h₁⟩ ⟨f₂, h₂⟩, ⟨f₁ * f₂, h₂ ▸ h₁ ▸ (mul_assoc _ _ _).symm⟩}
392
-
393
- instance : has_dvd (associates α) := ⟨(≤)⟩
381
+ { le := has_dvd.dvd,
382
+ le_refl := dvd_refl,
383
+ le_trans := λ a b c, dvd_trans}
394
384
395
385
@[simp] lemma mk_one : associates.mk (1 : α) = 1 := rfl
396
386
@@ -439,10 +429,10 @@ section order
439
429
theorem mul_mono {a b c d : associates α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
440
430
a * c ≤ b * d :=
441
431
let ⟨x, hx⟩ := h₁, ⟨y, hy⟩ := h₂ in
442
- ⟨x * y, by simp [hx.symm , hy.symm , mul_comm, mul_assoc, mul_left_comm]⟩
432
+ ⟨x * y, by simp [hx, hy, mul_comm, mul_assoc, mul_left_comm]⟩
443
433
444
434
theorem one_le {a : associates α} : 1 ≤ a :=
445
- ⟨a, one_mul a⟩
435
+ dvd.intro _ ( one_mul a)
446
436
447
437
theorem prod_le_prod {p q : multiset (associates α)} (h : p ≤ q) : p.prod ≤ q.prod :=
448
438
begin
@@ -493,9 +483,9 @@ variables [comm_semiring α]
493
483
theorem dvd_of_mk_le_mk {a b : α} : associates.mk a ≤ associates.mk b → a ∣ b
494
484
| ⟨c', hc'⟩ := (quotient.induction_on c' $ assume c hc,
495
485
let ⟨d, hd⟩ := (quotient.exact hc).symm in
496
- ⟨(↑d⁻¹ ) * c,
497
- calc b = (a * c) * ↑d⁻¹ : by rw [← hd, mul_assoc, units.mul_inv, mul_one]
498
- ... = a * (↑d⁻¹ * c) : by ac_refl⟩) hc'
486
+ ⟨(↑d) * c,
487
+ calc b = (a * c) * ↑d : hd.symm
488
+ ... = a * (↑d * c) : by ac_refl⟩) hc'
499
489
500
490
theorem mk_le_mk_of_dvd {a b : α} : a ∣ b → associates.mk a ≤ associates.mk b :=
501
491
assume ⟨c, hc⟩, ⟨associates.mk c, by simp [hc]; refl⟩
@@ -518,7 +508,7 @@ hp.2.2 a b h
518
508
lemma exists_mem_multiset_le_of_prime {s : multiset (associates α)} {p : associates α}
519
509
(hp : prime p) :
520
510
p ≤ s.prod → ∃a∈s, p ≤ a :=
521
- multiset.induction_on s (assume ⟨d, eq⟩, (hp.ne_one (mul_eq_one_iff.1 eq).1 ).elim) $
511
+ multiset.induction_on s (assume ⟨d, eq⟩, (hp.ne_one (mul_eq_one_iff.1 eq.symm ).1 ).elim) $
522
512
assume a s ih h,
523
513
have p ≤ a * s.prod, by simpa using h,
524
514
match hp.le_or_le this with
@@ -549,13 +539,8 @@ section integral_domain
549
539
variable [integral_domain α]
550
540
551
541
instance : partial_order (associates α) :=
552
- { le_antisymm := assume a' b',
553
- quotient.induction_on₂ a' b' $ assume a b ⟨f₁', h₁⟩ ⟨f₂', h₂⟩,
554
- (quotient.induction_on₂ f₁' f₂' $ assume f₁ f₂ h₁ h₂,
555
- let ⟨c₁, h₁⟩ := quotient.exact h₁, ⟨c₂, h₂⟩ := quotient.exact h₂ in
556
- quotient.sound $ associated_of_dvd_dvd
557
- (h₁ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)
558
- (h₂ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)) h₁ h₂
542
+ { le_antisymm := λ a' b', quotient.induction_on₂ a' b' (λ a b hab hba,
543
+ quot.sound $ associated_of_dvd_dvd (dvd_of_mk_le_mk hab) (dvd_of_mk_le_mk hba))
559
544
.. associates.preorder }
560
545
561
546
instance : order_bot (associates α) :=
@@ -565,7 +550,7 @@ instance : order_bot (associates α) :=
565
550
566
551
instance : order_top (associates α) :=
567
552
{ top := 0 ,
568
- le_top := assume a, ⟨0 , mul_zero a⟩,
553
+ le_top := assume a, ⟨0 , ( mul_zero a).symm ⟩,
569
554
.. associates.partial_order }
570
555
571
556
instance : no_zero_divisors (associates α) :=
0 commit comments