@@ -14,16 +14,162 @@ local infix ` ~ᵤ ` : 50 := associated
14
14
15
15
/-- Unique factorization domains.
16
16
17
- In a unique factorization domain each element (except zero) is uniquely represented as a multiset
18
- of irreducible factors. Uniqueness is only up to associated elements.
17
+ In a unique factorization domain each element (except zero) is uniquely
18
+ represented as a multiset of irreducible factors.
19
+ Uniqueness is only up to associated elements.
20
+
21
+ This is equivalent to defining a unique factorization domain as a domain in
22
+ which each element (except zero) is represented as a multiset of prime factors.
23
+ This definition is used.
24
+
25
+ To define a UFD using the traditional definition in terms of multisets of irreducible
26
+ factors, use the definition `of_unique_irreducible_factorization
27
+
19
28
-/
20
29
class unique_factorization_domain (α : Type *) [integral_domain α] :=
21
30
(factors : α → multiset α)
22
31
(factors_prod : ∀{a : α}, a ≠ 0 → (factors a).prod ~ᵤ a)
32
+ (prime_factors : ∀{a : α}, a ≠ 0 → ∀x∈factors a, prime x)
33
+
34
+ namespace unique_factorization_domain
35
+
36
+ variables [integral_domain α] [unique_factorization_domain α]
37
+
38
+ @[elab_as_eliminator] lemma induction_on_prime {P : α → Prop }
39
+ (a : α) (h₁ : P 0 ) (h₂ : ∀ x : α, is_unit x → P x)
40
+ (h₃ : ∀ a p : α, a ≠ 0 → prime p → P a → P (p * a)) : P a :=
41
+ by haveI := classical.dec_eq α; exact
42
+ if ha0 : a = 0 then ha0.symm ▸ h₁
43
+ else @multiset.induction_on _
44
+ (λ s : multiset α, ∀ (a : α), a ≠ 0 → s.prod ~ᵤ a → (∀ p ∈ s, prime p) → P a)
45
+ (factors a)
46
+ (λ _ _ h _, h₂ _ ((is_unit_iff_of_associated h.symm).2 is_unit_one))
47
+ (λ p s ih a ha0 ⟨u, hu⟩ hsp,
48
+ have ha : a = (p * u) * s.prod, by simp [hu.symm, mul_comm, mul_assoc],
49
+ have hs0 : s.prod ≠ 0 , from λ _ : s.prod = 0 , by simp * at *,
50
+ ha.symm ▸ h₃ _ _ hs0
51
+ (prime_of_associated ⟨u, rfl⟩ (hsp p (multiset.mem_cons_self _ _)))
52
+ (ih _ hs0 (by refl) (λ p hp, hsp p (multiset.mem_cons.2 (or.inr hp)))))
53
+ _
54
+ ha0
55
+ (factors_prod ha0)
56
+ (prime_factors ha0)
57
+
58
+ lemma factors_irreducible {a : α} (ha : irreducible a) :
59
+ ∃ p, a ~ᵤ p ∧ factors a = p :: 0 :=
60
+ by haveI := classical.dec_eq α; exact
61
+ multiset.induction_on (factors a)
62
+ (λ h, (ha.1 (associated_one_iff_is_unit.1 h.symm)).elim)
63
+ (λ p s _ hp hs, let ⟨u, hu⟩ := hp in ⟨p,
64
+ have hs0 : s = 0 , from classical.by_contradiction
65
+ (λ hs0, let ⟨q, hq⟩ := multiset.exists_mem_of_ne_zero hs0 in
66
+ (hs q (by simp [hq])).2 .1 $
67
+ (ha.2 ((p * u) * (s.erase q).prod) _
68
+ (by rw [mul_right_comm _ _ q, mul_assoc, ← multiset.prod_cons,
69
+ multiset.cons_erase hq]; simp [hu.symm, mul_comm, mul_assoc])).resolve_left $
70
+ mt is_unit_of_mul_is_unit_left $ mt is_unit_of_mul_is_unit_left
71
+ (hs p (multiset.mem_cons_self _ _)).2 .1 ),
72
+ ⟨associated.symm (by clear _let_match; simp * at *), hs0 ▸ rfl⟩⟩)
73
+ (factors_prod (nonzero_of_irreducible ha))
74
+ (prime_factors (nonzero_of_irreducible ha))
75
+
76
+ lemma irreducible_iff_prime {p : α} : irreducible p ↔ prime p :=
77
+ by letI := classical.dec_eq α; exact
78
+ if hp0 : p = 0 then by simp [hp0]
79
+ else
80
+ ⟨λ h, let ⟨q, hq⟩ := factors_irreducible h in
81
+ have prime q, from hq.2 ▸ prime_factors hp0 _ (by simp [hq.2 ]),
82
+ suffices prime (factors p).prod,
83
+ from prime_of_associated (factors_prod hp0) this ,
84
+ hq.2 .symm ▸ by simp [this ],
85
+ irreducible_of_prime⟩
86
+
87
+ lemma irreducible_factors : ∀{a : α}, a ≠ 0 → ∀x∈factors a, irreducible x :=
88
+ by simp only [irreducible_iff_prime]; exact @prime_factors _ _ _
89
+
90
+ lemma unique : ∀{f g : multiset α},
91
+ (∀x∈f, irreducible x) → (∀x∈g, irreducible x) → f.prod ~ᵤ g.prod →
92
+ multiset.rel associated f g :=
93
+ by haveI := classical.dec_eq α; exact
94
+ λ f, multiset.induction_on f
95
+ (λ g _ hg h,
96
+ multiset.rel_zero_left.2 $
97
+ multiset.eq_zero_of_forall_not_mem (λ x hx,
98
+ have is_unit g.prod, by simpa [associated_one_iff_is_unit] using h.symm,
99
+ (hg x hx).1 (is_unit_iff_dvd_one.2 (dvd.trans (multiset.dvd_prod hx)
100
+ (is_unit_iff_dvd_one.1 this )))))
101
+ (λ p f ih g hf hg hfg,
102
+ let ⟨b, hbg, hb⟩ := exists_associated_mem_of_dvd_prod
103
+ (irreducible_iff_prime.1 (hf p (by simp)))
104
+ (λ q hq, irreducible_iff_prime.1 (hg _ hq)) $
105
+ (dvd_iff_dvd_of_rel_right hfg).1
106
+ (show p ∣ (p :: f).prod, by simp) in
107
+ begin
108
+ rw ← multiset.cons_erase hbg,
109
+ exact multiset.rel.cons hb (ih (λ q hq, hf _ (by simp [hq]))
110
+ (λ q (hq : q ∈ g.erase b), hg q (multiset.mem_of_mem_erase hq))
111
+ (associated_mul_left_cancel
112
+ (by rwa [← multiset.prod_cons, ← multiset.prod_cons, multiset.cons_erase hbg]) hb
113
+ (nonzero_of_irreducible (hf p (by simp)))))
114
+ end )
115
+
116
+ end unique_factorization_domain
117
+
118
+ structure unique_irreducible_factorization (α : Type *) [integral_domain α] :=
119
+ (factors : α → multiset α)
120
+ (factors_prod : ∀{a : α}, a ≠ 0 → (factors a).prod ~ᵤ a)
23
121
(irreducible_factors : ∀{a : α}, a ≠ 0 → ∀x∈factors a, irreducible x)
24
122
(unique : ∀{f g : multiset α},
25
123
(∀x∈f, irreducible x) → (∀x∈g, irreducible x) → f.prod ~ᵤ g.prod → multiset.rel associated f g)
26
124
125
+ namespace unique_factorization_domain
126
+
127
+ def of_unique_irreducible_factorization {α : Type *} [integral_domain α]
128
+ (o : unique_irreducible_factorization α) : unique_factorization_domain α :=
129
+ by letI := classical.dec_eq α; exact
130
+ { prime_factors := λ a h p (hpa : p ∈ o.factors a),
131
+ have hpi : irreducible p, from o.irreducible_factors h _ hpa,
132
+ ⟨nonzero_of_irreducible hpi, hpi.1 ,
133
+ λ a b ⟨x, hx⟩,
134
+ if hab0 : a * b = 0
135
+ then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim
136
+ (λ ha0, by simp [ha0])
137
+ (λ hb0, by simp [hb0])
138
+ else
139
+ have hx0 : x ≠ 0 , from λ hx0, by simp * at *,
140
+ have ha0 : a ≠ 0 , from ne_zero_of_mul_ne_zero_right hab0,
141
+ have hb0 : b ≠ 0 , from ne_zero_of_mul_ne_zero_left hab0,
142
+ have multiset.rel associated (p :: o.factors x) (o.factors a + o.factors b),
143
+ from o.unique
144
+ (λ i hi, (multiset.mem_cons.1 hi).elim
145
+ (λ hip, hip.symm ▸ hpi)
146
+ (o.irreducible_factors hx0 _))
147
+ (show ∀ x ∈ o.factors a + o.factors b, irreducible x,
148
+ from λ x hx, (multiset.mem_add.1 hx).elim
149
+ (o.irreducible_factors (ne_zero_of_mul_ne_zero_right hab0) _)
150
+ (o.irreducible_factors (ne_zero_of_mul_ne_zero_left hab0) _)) $
151
+ calc multiset.prod (p :: o.factors x)
152
+ ~ᵤ a * b : by rw [hx, multiset.prod_cons];
153
+ exact associated_mul_mul (by refl)
154
+ (o.factors_prod hx0)
155
+ ... ~ᵤ (o.factors a).prod * (o.factors b).prod :
156
+ associated_mul_mul
157
+ (o.factors_prod ha0).symm
158
+ (o.factors_prod hb0).symm
159
+ ... = _ : by rw multiset.prod_add,
160
+ let ⟨q, hqf, hq⟩ := multiset.exists_mem_of_rel_of_mem this
161
+ (multiset.mem_cons_self p _) in
162
+ (multiset.mem_add.1 hqf).elim
163
+ (λ hqa, or.inl $ (dvd_iff_dvd_of_rel_left hq).2 $
164
+ (dvd_iff_dvd_of_rel_right (o.factors_prod ha0)).1
165
+ (multiset.dvd_prod hqa))
166
+ (λ hqb, or.inr $ (dvd_iff_dvd_of_rel_left hq).2 $
167
+ (dvd_iff_dvd_of_rel_right (o.factors_prod hb0)).1
168
+ (multiset.dvd_prod hqb))⟩,
169
+ ..o }
170
+
171
+ end unique_factorization_domain
172
+
27
173
namespace associates
28
174
open unique_factorization_domain associated lattice
29
175
variables [integral_domain α] [unique_factorization_domain α] [decidable_eq (associates α)]
0 commit comments