Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: some lemmas about associated and prime elements #7453

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Mathlib/Algebra/Associated.lean
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p
exact ih dvd_pow
#align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow

theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b :=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the name contain iff? (Not sure.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if we also change Nat.Prime.dvd_mul

⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩

theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b :=
hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩

end Prime

@[simp]
Expand Down Expand Up @@ -595,12 +601,24 @@ protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~
exact hp.dvd_or_dvd⟩⟩
#align associated.prime Associated.prime

theorem Irreducible.associated_of_dvd [CancelMonoidWithZero α] {p q : α} (p_irr : Irreducible p)
theorem Irreducible.dvd_iff [Monoid α] {x y : α} (hx : Irreducible x) :
y ∣ x ↔ IsUnit y ∨ Associated x y := by
constructor
· rintro ⟨z, hz⟩
obtain (h|h) := hx.isUnit_or_isUnit hz
· exact Or.inl h
· rw [hz]
exact Or.inr (associated_mul_unit_left _ _ h)
· rintro (hy|h)
· exact hy.dvd
· exact h.symm.dvd

theorem Irreducible.associated_of_dvd [Monoid α] {p q : α} (p_irr : Irreducible p)
(q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q :=
associated_of_dvd_dvd dvd (p_irr.dvd_symm q_irr dvd)
#align irreducible.associated_of_dvd Irreducible.associated_of_dvd
((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_unit).symm
#align irreducible.associated_of_dvd Irreducible.associated_of_dvdₓ

theorem Irreducible.dvd_irreducible_iff_associated [CancelMonoidWithZero α] {p q : α}
theorem Irreducible.dvd_irreducible_iff_associated [Monoid α] {p q : α}
(pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q :=
⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩
#align irreducible.dvd_irreducible_iff_associated Irreducible.dvd_irreducible_iff_associated
Expand Down Expand Up @@ -628,6 +646,10 @@ theorem Associated.isUnit_iff [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a
⟨h.isUnit, h.symm.isUnit⟩
#align associated.is_unit_iff Associated.isUnit_iff

theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid α]
{x y : α} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y :=
⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩

protected theorem Associated.irreducible [Monoid α] {p q : α} (h : p ~ᵤ q) (hp : Irreducible p) :
Irreducible q :=
⟨mt h.symm.isUnit hp.1,
Expand Down
22 changes: 22 additions & 0 deletions Mathlib/Algebra/GCDMonoid/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,17 @@ theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k
(dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd
#align dvd_gcd_mul_of_dvd_mul dvd_gcd_mul_of_dvd_mul

theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩

theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by
rw [mul_comm] at H ⊢
exact dvd_gcd_mul_of_dvd_mul H
#align dvd_mul_gcd_of_dvd_mul dvd_mul_gcd_of_dvd_mul

theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩

/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.

In other words, the nonzero elements of a `GCDMonoid` form a decomposition monoid
Expand Down Expand Up @@ -692,6 +698,22 @@ theorem extract_gcd {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] (x
exact ⟨x', y', ex, ey, isUnit_gcd_of_eq_mul_gcd ex ey h⟩
#align extract_gcd extract_gcd

theorem associated_gcd_left_iff [GCDMonoid α] {x y : α} : Associated x (gcd x y) ↔ x ∣ y :=
⟨fun hx => hx.dvd.trans (gcd_dvd_right x y),
fun hxy => associated_of_dvd_dvd (dvd_gcd dvd_rfl hxy) (gcd_dvd_left x y)⟩

theorem associated_gcd_right_iff [GCDMonoid α] {x y : α} : Associated y (gcd x y) ↔ y ∣ x :=
⟨fun hx => hx.dvd.trans (gcd_dvd_left x y),
fun hxy => associated_of_dvd_dvd (dvd_gcd hxy dvd_rfl) (gcd_dvd_right x y)⟩

theorem Irreducible.isUnit_gcd_iff [GCDMonoid α] {x y : α} (hx : Irreducible x) :
IsUnit (gcd x y) ↔ ¬(x ∣ y) := by
rw [hx.isUnit_iff_not_associated_of_dvd (gcd_dvd_left x y), not_iff_not, associated_gcd_left_iff]

theorem Irreducible.gcd_eq_one_iff [NormalizedGCDMonoid α] {x y : α} (hx : Irreducible x) :
gcd x y = 1 ↔ ¬(x ∣ y) := by
rw [← hx.isUnit_gcd_iff, ← normalize_eq_one, NormalizedGCDMonoid.normalize_gcd]

end GCD

section LCM
Expand Down
2 changes: 2 additions & 0 deletions test/propose.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ info: Try this: have : IsUnit p := isUnit_of_dvd_one h
---
info: Try this: have : p ≠ 1 := ne_one hp
---
info: Try this: have : p ∣ p * p ↔ p ∣ p ∨ p ∣ p := dvd_mul hp
---
info: Try this: have : p ∣ a := Prime.dvd_of_dvd_pow hp h
---
info: Try this: have : p ≠ 0 := ne_zero hp
Expand Down
Loading