Skip to content

Commit 661ebd0

Browse files
feat: add gcd_neg, neg_gcd (#12593)
1 parent 77f39e1 commit 661ebd0

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

Mathlib/Algebra/Associated.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ protected theorem refl [Monoid α] (x : α) : x ~ᵤ x :=
403403
1, by simp⟩
404404
#align associated.refl Associated.refl
405405

406+
protected theorem rfl [Monoid α] {x : α} : x ~ᵤ x :=
407+
.refl x
408+
406409
instance [Monoid α] : IsRefl α Associated :=
407410
⟨Associated.refl⟩
408411

@@ -561,6 +564,9 @@ protected theorem Associated.dvd [Monoid α] {a b : α} : a ~ᵤ b → a ∣ b :
561564
⟨u, hu.symm⟩
562565
#align associated.dvd Associated.dvd
563566

567+
protected theorem Associated.dvd' [Monoid α] {a b : α} (h : a ~ᵤ b) : b ∣ a :=
568+
h.symm.dvd
569+
564570
protected theorem Associated.dvd_dvd [Monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a :=
565571
⟨h.dvd, h.symm.dvd⟩
566572
#align associated.dvd_dvd Associated.dvd_dvd
@@ -608,6 +614,18 @@ theorem Associated.ne_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a
608614
not_congr h.eq_zero_iff
609615
#align associated.ne_zero_iff Associated.ne_zero_iff
610616

617+
theorem Associated.neg_left [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
618+
Associated (-a) b :=
619+
let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩
620+
621+
theorem Associated.neg_right [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
622+
Associated a (-b) :=
623+
h.symm.neg_left.symm
624+
625+
theorem Associated.neg_neg [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
626+
Associated (-a) (-b) :=
627+
h.neg_left.neg_right
628+
611629
protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) (hp : Prime p) :
612630
Prime q :=
613631
⟨h.ne_zero_iff.1 hp.ne_zero,

Mathlib/Algebra/GCDMonoid/Basic.lean

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : nor
191191
ha ▸ hb ▸ normalize_eq_normalize hab hba
192192
#align dvd_antisymm_of_normalize_eq dvd_antisymm_of_normalize_eq
193193

194+
theorem Associated.eq_of_normalized
195+
{a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) :
196+
a = b :=
197+
dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd'
198+
194199
--can be proven by simp
195200
theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b :=
196201
Units.dvd_mul_right
@@ -435,6 +440,11 @@ theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d
435440
dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd)
436441
#align gcd_dvd_gcd gcd_dvd_gcd
437442

443+
protected theorem Associated.gcd [GCDMonoid α]
444+
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
445+
Associated (gcd a₁ b₁) (gcd a₂ b₂) :=
446+
associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd')
447+
438448
@[simp]
439449
theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a :=
440450
gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a))
@@ -714,6 +724,24 @@ theorem Irreducible.gcd_eq_one_iff [NormalizedGCDMonoid α] {x y : α} (hx : Irr
714724
gcd x y = 1 ↔ ¬(x ∣ y) := by
715725
rw [← hx.isUnit_gcd_iff, ← normalize_eq_one, NormalizedGCDMonoid.normalize_gcd]
716726

727+
section Neg
728+
729+
variable [HasDistribNeg α]
730+
731+
lemma gcd_neg' [GCDMonoid α] {a b : α} : Associated (gcd a (-b)) (gcd a b) :=
732+
Associated.gcd .rfl (.neg_left .rfl)
733+
734+
lemma gcd_neg [NormalizedGCDMonoid α] {a b : α} : gcd a (-b) = gcd a b :=
735+
gcd_neg'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _)
736+
737+
lemma neg_gcd' [GCDMonoid α] {a b : α} : Associated (gcd (-a) b) (gcd a b) :=
738+
Associated.gcd (.neg_left .rfl) .rfl
739+
740+
lemma neg_gcd [NormalizedGCDMonoid α] {a b : α} : gcd (-a) b = gcd a b :=
741+
neg_gcd'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _)
742+
743+
end Neg
744+
717745
end GCD
718746

719747
section LCM
@@ -799,6 +827,11 @@ theorem lcm_dvd_lcm [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d
799827
lcm_dvd (hab.trans (dvd_lcm_left _ _)) (hcd.trans (dvd_lcm_right _ _))
800828
#align lcm_dvd_lcm lcm_dvd_lcm
801829

830+
protected theorem Associated.lcm [GCDMonoid α]
831+
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
832+
Associated (lcm a₁ b₁) (lcm a₂ b₂) :=
833+
associated_of_dvd_dvd (lcm_dvd_lcm ha.dvd hb.dvd) (lcm_dvd_lcm ha.dvd' hb.dvd')
834+
802835
@[simp]
803836
theorem lcm_units_coe_left [NormalizedGCDMonoid α] (u : αˣ) (a : α) : lcm (↑u) a = normalize a :=
804837
lcm_eq_normalize (lcm_dvd Units.coe_dvd dvd_rfl) (dvd_lcm_right _ _)
@@ -1424,16 +1457,6 @@ theorem normalize_eq_one {a : G₀} (h0 : a ≠ 0) : normalize a = 1 := by simp
14241457

14251458
end CommGroupWithZero
14261459

1427-
theorem Associated.gcd [CancelCommMonoidWithZero α] [GCDMonoid α]
1428-
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
1429-
Associated (gcd a₁ b₁) (gcd a₂ b₂) :=
1430-
associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.symm.dvd hb.symm.dvd)
1431-
1432-
theorem Associated.lcm [CancelCommMonoidWithZero α] [GCDMonoid α]
1433-
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
1434-
Associated (lcm a₁ b₁) (lcm a₂ b₂) :=
1435-
associated_of_dvd_dvd (lcm_dvd_lcm ha.dvd hb.dvd) (lcm_dvd_lcm ha.symm.dvd hb.symm.dvd)
1436-
14371460
namespace Associates
14381461

14391462
variable [CancelCommMonoidWithZero α] [GCDMonoid α]

0 commit comments

Comments
 (0)