Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 8863666

Browse files
kl-ikckennylau
andcommitted
feat(ring_theory/ideals): prod_dvd_of_coprime (#2815)
Co-authored-by: kckennylau <kc_kennylau@yahoo.com.hk>
1 parent 2779093 commit 8863666

File tree

4 files changed

+178
-13
lines changed

4 files changed

+178
-13
lines changed

src/data/polynomial.lean

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,14 @@ prime_of_associated normalize_associated this
23712371
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
23722372
irreducible_of_prime (prime_of_degree_eq_one hp1)
23732373

2374+
theorem pairwise_coprime_X_sub {α : Type u} [field α] {I : Type v}
2375+
{s : I → α} (H : function.injective s) :
2376+
pairwise (is_coprime on (λ i : I, polynomial.X - polynomial.C (s i))) :=
2377+
λ i j hij, have h : s j - s i ≠ 0, from sub_ne_zero_of_ne $ function.injective.ne H hij.symm,
2378+
⟨polynomial.C (s j - s i)⁻¹, -polynomial.C (s j - s i)⁻¹,
2379+
by rw [neg_mul_eq_neg_mul_symm, ← sub_eq_add_neg, ← mul_sub, sub_sub_sub_cancel_left,
2380+
← polynomial.C_sub, ← polynomial.C_mul, inv_mul_cancel h, polynomial.C_1]⟩
2381+
23742382
end field
23752383

23762384
section derivative
@@ -2482,7 +2490,7 @@ then `f / (X - a)` is coprime with `X - a`.
24822490
Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/
24832491
lemma is_coprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [field K]
24842492
(f : polynomial K) (a : K) (hf' : f.derivative.eval a ≠ 0) :
2485-
ideal.is_coprime (X - C a : polynomial K) (f /ₘ (X - C a)) :=
2493+
is_coprime (X - C a : polynomial K) (f /ₘ (X - C a)) :=
24862494
begin
24872495
refine or.resolve_left (dvd_or_coprime (X - C a) (f /ₘ (X - C a))
24882496
(irreducible_of_degree_eq_one (polynomial.degree_X_sub_C a))) _,

src/ring_theory/coprime.lean

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/-
2+
Copyright (c) 2020 Kenny Lau. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kenny Lau, Ken Lee, Chris Hughes
5+
-/
6+
7+
import algebra.big_operators
8+
import data.fintype.basic
9+
import data.int.gcd
10+
import data.set.disjointed
11+
12+
/-!
13+
# Coprime elements of a ring
14+
15+
## Main definitions
16+
17+
* `is_coprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such
18+
that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime,
19+
e.g., the multivariate polynomials `x₁` and `x₂` are not coprime.
20+
21+
-/
22+
23+
open_locale classical big_operators
24+
25+
universes u v
26+
27+
variables {R : Type u} [comm_semiring R] (x y z : R)
28+
29+
/-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such
30+
that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime,
31+
e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/
32+
@[simp] def is_coprime : Prop :=
33+
∃ a b, a * x + b * y = 1
34+
35+
theorem nat.is_coprime_iff_coprime {m n : ℕ} : is_coprime (m : ℤ) n ↔ nat.coprime m n :=
36+
⟨λ ⟨a, b, H⟩, nat.eq_one_of_dvd_one $ int.coe_nat_dvd.1 $ by { rw [int.coe_nat_one, ← H],
37+
exact dvd_add (dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_left m n) _)
38+
(dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_right m n) _) },
39+
λ H, ⟨nat.gcd_a m n, nat.gcd_b m n, by rw [mul_comm _ (m : ℤ), mul_comm _ (n : ℤ),
40+
← nat.gcd_eq_gcd_ab, show _ = _, from H, int.coe_nat_one]⟩⟩
41+
42+
variables {x y z}
43+
44+
theorem is_coprime.symm (H : is_coprime x y) : is_coprime y x :=
45+
let ⟨a, b, H⟩ := H in ⟨b, a, by rw [add_comm, H]⟩
46+
47+
theorem is_coprime_comm : is_coprime x y ↔ is_coprime y x :=
48+
⟨is_coprime.symm, is_coprime.symm⟩
49+
50+
theorem is_coprime_self : is_coprime x x ↔ is_unit x :=
51+
⟨λ ⟨a, b, h⟩, is_unit_of_mul_eq_one x (a + b) $ by rwa [mul_comm, add_mul],
52+
λ h, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 h in ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩
53+
54+
theorem is_coprime_zero_left : is_coprime 0 x ↔ is_unit x :=
55+
⟨λ ⟨a, b, H⟩, is_unit_of_mul_eq_one x b $ by rwa [mul_zero, zero_add, mul_comm] at H,
56+
λ H, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 H in1, b, by rwa [one_mul, zero_add]⟩⟩
57+
58+
theorem is_coprime_zero_right : is_coprime x 0 ↔ is_unit x :=
59+
is_coprime_comm.trans is_coprime_zero_left
60+
61+
theorem is_coprime_one_left : is_coprime 1 x :=
62+
1, 0, by rw [one_mul, zero_mul, add_zero]⟩
63+
64+
theorem is_coprime_one_right : is_coprime x 1 :=
65+
0, 1, by rw [one_mul, zero_mul, zero_add]⟩
66+
67+
theorem is_coprime.dvd_of_dvd_mul_right (H1 : is_coprime x z) (H2 : x ∣ y * z) : x ∣ y :=
68+
let ⟨a, b, H⟩ := H1 in by { rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm],
69+
exact dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_right H2 _) }
70+
71+
theorem is_coprime.dvd_of_dvd_mul_left (H1 : is_coprime x y) (H2 : x ∣ y * z) : x ∣ z :=
72+
let ⟨a, b, H⟩ := H1 in by { rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b],
73+
exact dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_right H2 _) }
74+
75+
theorem is_coprime.mul_left (H1 : is_coprime x z) (H2 : is_coprime y z) : is_coprime (x * y) z :=
76+
let ⟨a, b, h1⟩ := H1, ⟨c, d, h2⟩ := H2 in
77+
⟨a * c, a * x * d + b * c * y + b * d * z,
78+
calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z
79+
= (a * x + b * z) * (c * y + d * z) : by ring
80+
... = 1 : by rw [h1, h2, mul_one]⟩
81+
82+
theorem is_coprime.mul_right (H1 : is_coprime x y) (H2 : is_coprime x z) : is_coprime x (y * z) :=
83+
by { rw is_coprime_comm at H1 H2 ⊢, exact H1.mul_left H2 }
84+
85+
variables {I : Type v} {s : I → R} {t : finset I}
86+
87+
theorem is_coprime.prod_left : (∀ i ∈ t, is_coprime (s i) x) → is_coprime (∏ i in t, s i) x :=
88+
finset.induction_on t (λ _, is_coprime_one_left) $ λ b t hbt ih H,
89+
by { rw finset.prod_insert hbt, rw finset.forall_mem_insert at H, exact H.1.mul_left (ih H.2) }
90+
91+
theorem is_coprime.prod_right : (∀ i ∈ t, is_coprime x (s i)) → is_coprime x (∏ i in t, s i) :=
92+
by simpa only [is_coprime_comm] using is_coprime.prod_left
93+
94+
theorem is_coprime.mul_dvd (H : is_coprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z :=
95+
begin
96+
obtain ⟨a, b, h⟩ := H,
97+
rw [← mul_one z, ← h, mul_add],
98+
apply dvd_add,
99+
{ rw [mul_comm z, mul_assoc],
100+
exact dvd_mul_of_dvd_right (mul_dvd_mul_left _ H2) _ },
101+
{ rw [mul_comm b, ← mul_assoc],
102+
exact dvd_mul_of_dvd_left (mul_dvd_mul_right H1 _) _ }
103+
end
104+
105+
theorem finset.prod_dvd_of_coprime (Hs : pairwise (is_coprime on s)) (Hs1 : ∀ i, s i ∣ z) :
106+
∏ x in t, s x ∣ z :=
107+
finset.induction_on t (one_dvd z) (λ a r har ih, by { rw finset.prod_insert har,
108+
exact (is_coprime.prod_right $ λ i hir, Hs a i $ λ hai, har $ hai.symm ▸ hir).mul_dvd (Hs1 a) ih })
109+
110+
theorem fintype.prod_dvd_of_coprime [fintype I] (Hs : pairwise (is_coprime on s))
111+
(Hs1 : ∀ i, s i ∣ z) : ∏ x, s x ∣ z :=
112+
finset.prod_dvd_of_coprime Hs Hs1
113+
114+
theorem is_coprime.of_mul_left_left (H : is_coprime (x * y) z) : is_coprime x z :=
115+
let ⟨a, b, h⟩ := H in ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩
116+
117+
theorem is_coprime.of_mul_left_right (H : is_coprime (x * y) z) : is_coprime y z :=
118+
by { rw mul_comm at H, exact H.of_mul_left_left }
119+
120+
theorem is_coprime.of_mul_right_left (H : is_coprime x (y * z)) : is_coprime x y :=
121+
by { rw is_coprime_comm at H ⊢, exact H.of_mul_left_left }
122+
123+
theorem is_coprime.of_mul_right_right (H : is_coprime x (y * z)) : is_coprime x z :=
124+
by { rw mul_comm at H, exact H.of_mul_right_left }
125+
126+
theorem is_coprime.mul_left_iff : is_coprime (x * y) z ↔ is_coprime x z ∧ is_coprime y z :=
127+
⟨λ H, ⟨H.of_mul_left_left, H.of_mul_left_right⟩, λ ⟨H1, H2⟩, H1.mul_left H2⟩
128+
129+
theorem is_coprime.mul_right_iff : is_coprime x (y * z) ↔ is_coprime x y ∧ is_coprime x z :=
130+
by rw [is_coprime_comm, is_coprime.mul_left_iff, is_coprime_comm, @is_coprime_comm _ _ z]
131+
132+
theorem is_coprime.prod_left_iff : is_coprime (∏ i in t, s i) x ↔ ∀ i ∈ t, is_coprime (s i) x :=
133+
finset.induction_on t (iff_of_true is_coprime_one_left $ λ _, false.elim) $ λ b t hbt ih,
134+
by rw [finset.prod_insert hbt, is_coprime.mul_left_iff, ih, finset.forall_mem_insert]
135+
136+
theorem is_coprime.prod_right_iff : is_coprime x (∏ i in t, s i) ↔ ∀ i ∈ t, is_coprime x (s i) :=
137+
by simpa only [is_coprime_comm] using is_coprime.prod_left_iff
138+
139+
theorem is_coprime.of_prod_left (H1 : is_coprime (∏ i in t, s i) x) (i : I) (hit : i ∈ t) :
140+
is_coprime (s i) x :=
141+
is_coprime.prod_left_iff.1 H1 i hit
142+
143+
theorem is_coprime.of_prod_right (H1 : is_coprime x (∏ i in t, s i)) (i : I) (hit : i ∈ t) :
144+
is_coprime x (s i) :=
145+
is_coprime.prod_right_iff.1 H1 i hit
146+
147+
variables {m n : ℕ}
148+
149+
theorem is_coprime.pow_left (H : is_coprime x y) : is_coprime (x ^ m) y :=
150+
by { rw [← finset.card_range m, ← finset.prod_const], exact is_coprime.prod_left (λ _ _, H) }
151+
152+
theorem is_coprime.pow_right (H : is_coprime x y) : is_coprime x (y ^ n) :=
153+
by { rw [← finset.card_range n, ← finset.prod_const], exact is_coprime.prod_right (λ _ _, H) }
154+
155+
theorem is_coprime.pow (H : is_coprime x y) : is_coprime (x ^ m) (y ^ n) :=
156+
H.pow_left.pow_right
157+
158+
theorem is_coprime.is_unit_of_dvd (H : is_coprime x y) (d : x ∣ y) : is_unit x :=
159+
let ⟨k, hk⟩ := d in is_coprime_self.1 $ is_coprime.of_mul_right_left $
160+
show is_coprime x (x * k), from hk ▸ H
161+
162+
theorem is_coprime.map (H : is_coprime x y) {S : Type v} [comm_semiring S] (f : R →+* S) :
163+
is_coprime (f x) (f y) :=
164+
let ⟨a, b, h⟩ := H in ⟨f a, f b, by rw [← f.map_mul, ← f.map_mul, ← f.map_add, h, f.map_one]⟩

src/ring_theory/euclidean_domain.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Chris Hughes
55
-/
6+
import ring_theory.coprime
67
import ring_theory.ideals
78
noncomputable theory
89
open_locale classical
@@ -26,7 +27,10 @@ end
2627

2728
theorem gcd_is_unit_iff {α} [euclidean_domain α] {x y : α} :
2829
is_unit (gcd x y) ↔ is_coprime x y :=
29-
by rw [← span_singleton_eq_top, span_gcd, is_coprime]
30+
⟨λ h, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 h in ⟨b * gcd_a x y, b * gcd_b x y,
31+
by rw [← hb, gcd_eq_gcd_ab, mul_comm x, mul_comm y, mul_add, mul_assoc, mul_assoc]⟩,
32+
λ ⟨a, b, h⟩, is_unit_iff_dvd_one.2 $ h ▸ dvd_add (dvd_mul_of_dvd_right (gcd_dvd_left x y) _)
33+
(dvd_mul_of_dvd_right (gcd_dvd_right x y) _)⟩
3034

3135
theorem is_coprime_of_dvd {α} [euclidean_domain α] {x y : α}
3236
(z : ¬ (x = 0 ∧ y = 0)) (H : ∀ z ∈ nonunits α, z ≠ 0 → z ∣ x → ¬ z ∣ y) :

src/ring_theory/ideals.lean

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,10 @@ begin
149149
exact SC JS ((eq_top_iff_one _).2 J0) }
150150
end
151151

152-
def is_coprime (x y : α) : Prop :=
153-
span ({x, y} : set α) = ⊤
154-
155152
theorem mem_span_pair {x y z : α} :
156153
z ∈ span ({x, y} : set α) ↔ ∃ a b, a * x + b * y = z :=
157154
by simp [mem_span_insert, mem_span_singleton', @eq_comm _ _ z]
158155

159-
theorem is_coprime_def {x y : α} :
160-
is_coprime x y ↔ ∀ z, ∃ a b, a * x + b * y = z :=
161-
by simp [is_coprime, submodule.eq_top_iff', mem_span_pair]
162-
163-
theorem is_coprime_self {x : α} :
164-
is_coprime x x ↔ is_unit x :=
165-
by rw [← span_singleton_eq_top]; simp [is_coprime]
166-
167156
lemma span_singleton_lt_span_singleton [integral_domain β] {x y : β} :
168157
span ({x} : set β) < span ({y} : set β) ↔ y ≠ 0 ∧ ∃ d : β, ¬ is_unit d ∧ x = y * d :=
169158
by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,

0 commit comments

Comments
 (0)