state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
α : Type u_1
β : Type u_2
inst✝² : CommMonoidWithZero α
inst✝¹ : DecidableRel fun x x_1 => x ∣ x_1
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a b : α
h : ¬Finite a b
n : ℕ
⊢ a ^ n ∣ b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
|
exact not_finite_iff_forall.mp h n
|
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
|
Mathlib.RingTheory.Multiplicity.382_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Semiring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≤ multiplicity p b
⊢ min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
|
rw [min_eq_left h, multiplicity_le_multiplicity_iff]
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
|
Mathlib.RingTheory.Multiplicity.409_0.uTHZeAJqYiw3Jx8
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Semiring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≤ multiplicity p b
⊢ ∀ (n : ℕ), p ^ n ∣ a → p ^ n ∣ a + b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
|
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn)
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
|
Mathlib.RingTheory.Multiplicity.409_0.uTHZeAJqYiw3Jx8
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Semiring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b ≤ multiplicity p a
⊢ min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
|
rw [min_eq_right h, multiplicity_le_multiplicity_iff]
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
|
Mathlib.RingTheory.Multiplicity.409_0.uTHZeAJqYiw3Jx8
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Semiring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b ≤ multiplicity p a
⊢ ∀ (n : ℕ), p ^ n ∣ b → p ^ n ∣ a + b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
|
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
|
Mathlib.RingTheory.Multiplicity.409_0.uTHZeAJqYiw3Jx8
|
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a b : α
⊢ (multiplicity a (-b)).Dom ↔ (multiplicity a b).Dom
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by
|
simp only [multiplicity, PartENat.find, dvd_neg]
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by
|
Mathlib.RingTheory.Multiplicity.426_0.uTHZeAJqYiw3Jx8
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a b : α
h₁ : (multiplicity a (-b)).Dom
h₂ : (multiplicity a b).Dom
⊢ ↑(Part.get (multiplicity a (-b)) h₁) = ↑(Part.get (multiplicity a b) h₂)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
|
rw [PartENat.natCast_get]
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
|
Mathlib.RingTheory.Multiplicity.426_0.uTHZeAJqYiw3Jx8
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a b : α
h₁ : (multiplicity a (-b)).Dom
h₂ : (multiplicity a b).Dom
⊢ multiplicity a (-b) = ↑(Part.get (multiplicity a b) h₂)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
|
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _))))
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
|
Mathlib.RingTheory.Multiplicity.426_0.uTHZeAJqYiw3Jx8
|
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
⊢ multiplicity a (_root_.Int.natAbs b) = multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
|
cases' Int.natAbs_eq b with h h
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
case inl
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = ↑(_root_.Int.natAbs b)
⊢ multiplicity a (_root_.Int.natAbs b) = multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;>
|
conv_rhs => rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = ↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = ↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = ↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
case inr
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = -↑(_root_.Int.natAbs b)
⊢ multiplicity a (_root_.Int.natAbs b) = multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;>
|
conv_rhs => rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = -↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = -↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = -↑(_root_.Int.natAbs b)
| multiplicity (↑a) b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
rw [h]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs =>
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
case inl
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = ↑(_root_.Int.natAbs b)
⊢ multiplicity a (_root_.Int.natAbs b) = multiplicity ↑a ↑(_root_.Int.natAbs b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
·
|
rw [Int.coe_nat_multiplicity]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
·
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
case inr
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : ℕ
b : ℤ
h : b = -↑(_root_.Int.natAbs b)
⊢ multiplicity a (_root_.Int.natAbs b) = multiplicity (↑a) (-↑(_root_.Int.natAbs b))
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
·
|
rw [multiplicity.neg, Int.coe_nat_multiplicity]
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
·
|
Mathlib.RingTheory.Multiplicity.436_0.uTHZeAJqYiw3Jx8
|
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (a + b) = multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
|
apply le_antisymm
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (a + b) ≤ multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
·
|
apply PartENat.le_of_lt_add_one
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
·
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (a + b) < multiplicity p b + 1
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
|
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ multiplicity p (a + b) < multiplicity p b + 1
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
|
rw [hk]
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ multiplicity p (a + b) < ↑k + 1
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
|
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ ¬p ^ (k + 1) ∣ b
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ p ^ (k + 1) ∣ a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
|
intro h_dvd
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
h_dvd : p ^ (k + 1) ∣ b
⊢ False
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
·
|
apply multiplicity.is_greatest _ h_dvd
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
·
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
h_dvd : p ^ (k + 1) ∣ b
⊢ multiplicity p b < ↑(k + 1)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
|
rw [hk, ← Nat.succ_eq_add_one]
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
h_dvd : p ^ (k + 1) ∣ b
⊢ ↑k < ↑(succ k)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
|
norm_cast
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
h_dvd : p ^ (k + 1) ∣ b
⊢ k < succ k
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
|
apply Nat.lt_succ_self k
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ p ^ (k + 1) ∣ a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
·
|
rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
·
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a.h.intro
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
k : ℕ
hk : multiplicity p b = ↑k
⊢ multiplicity p b + 1 ≤ multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
|
exact PartENat.add_one_le_of_lt h
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p b ≤ multiplicity p (a + b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
·
|
have := @min_le_multiplicity_add α _ _ p a b
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
·
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case a
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
this : min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b)
⊢ multiplicity p b ≤ multiplicity p (a + b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
|
rwa [← min_eq_right (le_of_lt h)]
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
|
Mathlib.RingTheory.Multiplicity.442_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (a - b) = multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
|
rw [sub_eq_add_neg, multiplicity_add_of_gt]
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
|
Mathlib.RingTheory.Multiplicity.460_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (-b) = multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;>
|
rw [multiplicity.neg]
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;>
|
Mathlib.RingTheory.Multiplicity.460_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p (-b) < multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;>
|
rw [multiplicity.neg]
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;>
|
Mathlib.RingTheory.Multiplicity.460_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p b < multiplicity p a
⊢ multiplicity p b < multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg];
|
assumption
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg];
|
Mathlib.RingTheory.Multiplicity.460_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
⊢ multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
|
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
case inl
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
hab : multiplicity p a < multiplicity p b
⊢ multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
·
|
rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
·
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
case inl
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
hab : multiplicity p a < multiplicity p b
⊢ multiplicity p a ≤ multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
|
exact le_of_lt hab
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
case inr.inl
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
hab : multiplicity p a = multiplicity p b
⊢ multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
·
|
contradiction
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
·
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
case inr.inr
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
hab : multiplicity p b < multiplicity p a
⊢ multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
·
|
rw [multiplicity_add_of_gt hab, min_eq_right]
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
·
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
case inr.inr
α : Type u_1
β : Type u_2
inst✝¹ : Ring α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
h : multiplicity p a ≠ multiplicity p b
hab : multiplicity p b < multiplicity p a
⊢ multiplicity p b ≤ multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
|
exact le_of_lt hab
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
|
Mathlib.RingTheory.Multiplicity.465_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
⊢ a * b = p * (p ^ (n + m) * s)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by
|
simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝ : p ∣ a
x : α
hx : a = p * x
hn0 : n = 0
⊢ False
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by
|
simp [hx, hn0] at ha
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝² : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝¹ : p ∣ a
x : α
hx : a = p * x
hn0 : 0 < n
x✝ : p ^ (n - 1 + 1) ∣ x
y : α
hy : x = p ^ (n - 1 + 1) * y
⊢ p * x * p = p ^ (n + 1) * y * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
|
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝² : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝¹ : p ∣ a
x : α
hx : a = p * x
hn0 : 0 < n
x✝ : p ^ (n - 1 + 1) ∣ x
y : α
hy : x = p ^ n * y
⊢ p * x * p = p ^ (n + 1) * y * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
|
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this✝ : p ∣ a * b
x✝ : p ∣ a
x : α
hx : a = p * x
hn0 : 0 < n
hpx : ¬p ^ (n - 1 + 1) ∣ x
this : 1 ≤ n + m
⊢ x * b * p = p ^ (n - 1 + m + 1) * s * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
|
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this✝ : p ∣ a * b
x✝ : p ∣ a
x : α
hx : a = p * x
hn0 : 0 < n
hpx : ¬p ^ (n - 1 + 1) ∣ x
this : 1 ≤ n + m
⊢ x * b * p = p ^ (n + m) * s * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
|
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝ : p ∣ b
x : α
hx : b = p * x
hm0 : m = 0
⊢ False
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by
|
simp [hx, hm0] at hb
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝² : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝¹ : p ∣ b
x : α
hx : b = p * x
hm0 : 0 < m
x✝ : p ^ (m - 1 + 1) ∣ x
y : α
hy : x = p ^ (m - 1 + 1) * y
⊢ p * x * p = p ^ (m + 1) * y * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
|
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝² : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝¹ : p ∣ b
x : α
hx : b = p * x
hm0 : 0 < m
x✝ : p ^ (m - 1 + 1) ∣ x
y : α
hy : x = p ^ m * y
⊢ p * x * p = p ^ (m + 1) * y * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
|
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝ : p ∣ b
x : α
hx : b = p * x
hm0 : 0 < m
hpx : ¬p ^ (m - 1 + 1) ∣ x
⊢ a * x * p = p ^ (n + (m - 1) + 1) * s * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
|
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p : α
hp : Prime p
a b : α
n m : ℕ
ha : ¬p ^ (n + 1) ∣ a
hb : ¬p ^ (m + 1) ∣ b
x✝¹ : p ^ (n + m + 1) ∣ a * b
s : α
hs : a * b = p ^ (n + m + 1) * s
this : p ∣ a * b
x✝ : p ∣ b
x : α
hx : b = p * x
hm0 : 0 < m
hpx : ¬p ^ (m - 1 + 1) ∣ x
⊢ a * x * p = p ^ (n + m) * s * p
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
|
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add]
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
|
Mathlib.RingTheory.Multiplicity.483_0.uTHZeAJqYiw3Jx8
|
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p a : α
hp : Prime p
x✝ : Finite p a
⊢ ¬p ^ (0 + 1) ∣ a ^ 0
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by
|
simp [mt isUnit_iff_dvd_one.2 hp.2.1]
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by
|
Mathlib.RingTheory.Multiplicity.526_0.uTHZeAJqYiw3Jx8
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p a : α
hp : Prime p
k : ℕ
ha : Finite p a
⊢ Finite p (a ^ (k + 1))
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by
|
rw [_root_.pow_succ]
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by
|
Mathlib.RingTheory.Multiplicity.526_0.uTHZeAJqYiw3Jx8
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝ : CancelCommMonoidWithZero α
p a : α
hp : Prime p
k : ℕ
ha : Finite p a
⊢ Finite p (a * a ^ k)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ];
|
exact finite_mul hp ha (finite_pow hp ha)
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ];
|
Mathlib.RingTheory.Multiplicity.526_0.uTHZeAJqYiw3Jx8
|
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : ¬IsUnit a
ha0 : a ≠ 0
⊢ multiplicity a a = 1
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
|
rw [← Nat.cast_one]
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
|
Mathlib.RingTheory.Multiplicity.533_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : ¬IsUnit a
ha0 : a ≠ 0
⊢ multiplicity a a = ↑1
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
|
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
|
Mathlib.RingTheory.Multiplicity.533_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : ¬IsUnit a
ha0 : a ≠ 0
⊢ a ^ 1 ∣ a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by
|
simp
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by
|
Mathlib.RingTheory.Multiplicity.533_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : ¬IsUnit a
ha0 : a ≠ 0
x✝ : a ^ (1 + 1) ∣ a
b : α
hb : a = a ^ (1 + 1) * b
⊢ a * 1 = a * (a * b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by
|
simpa [_root_.pow_succ, mul_assoc] using hb
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by
|
Mathlib.RingTheory.Multiplicity.533_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : Finite a a
⊢ a ^ 1 ∣ a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by
|
simp
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by
|
Mathlib.RingTheory.Multiplicity.540_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : Finite a a
x✝ : a ^ (1 + 1) ∣ a
b : α
hb : a = a ^ (1 + 1) * b
⊢ False
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
|
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
|
Mathlib.RingTheory.Multiplicity.540_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : Finite a a
x✝ : a ^ (1 + 1) ∣ a
b : α
hb : 1 = 1 * (a * 1 * b)
⊢ False
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
|
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
|
Mathlib.RingTheory.Multiplicity.540_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
a : α
ha : Finite a a
x✝ : a ^ (1 + 1) ∣ a
b : α
hb : 1 = 1 * (a * 1 * b)
⊢ 1 = a * b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by
|
simp_all
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by
|
Mathlib.RingTheory.Multiplicity.540_0.uTHZeAJqYiw3Jx8
|
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
|
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
|
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
|
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
⊢ p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by
|
simp [pow_add]
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
|
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
⊢ p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) ∣ a * b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by
|
rw [hpoweq]
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
⊢ p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ a * b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq];
|
apply mul_dvd_mul
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq];
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
case a
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
⊢ p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;>
|
assumption
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;>
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
case a
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
⊢ p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;>
|
assumption
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;>
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
hdiv : p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) ∣ a * b
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
|
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
hdiv : p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) ∣ a * b
hsucc : ¬p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b) + 1) ∣ a * b
⊢ Part.get (multiplicity p (a * b)) h =
Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
|
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : (multiplicity p (a * b)).Dom
hdiva : p ^ Part.get (multiplicity p a) (_ : Finite p a) ∣ a
hdivb : p ^ Part.get (multiplicity p b) (_ : Finite p b) ∣ b
hpoweq :
p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) =
p ^ Part.get (multiplicity p a) (_ : Finite p a) * p ^ Part.get (multiplicity p b) (_ : Finite p b)
hdiv : p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) ∣ a * b
hsucc : ¬p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b) + 1) ∣ a * b
⊢ p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b)) ∣ a * b ∧
¬p ^ (Part.get (multiplicity p a) (_ : Finite p a) + Part.get (multiplicity p b) (_ : Finite p b) + 1) ∣ a * b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff];
|
exact ⟨hdiv, hsucc⟩
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff];
|
Mathlib.RingTheory.Multiplicity.551_0.uTHZeAJqYiw3Jx8
|
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : Finite p a ∧ Finite p b
⊢ multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
|
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
|
Mathlib.RingTheory.Multiplicity.581_0.uTHZeAJqYiw3Jx8
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : ¬(Finite p a ∧ Finite p b)
⊢ multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
|
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
|
Mathlib.RingTheory.Multiplicity.581_0.uTHZeAJqYiw3Jx8
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h : ¬(Finite p a ∧ Finite p b)
⊢ ⊤ = multiplicity p a + multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
|
cases' not_and_or.1 h with h h
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
|
Mathlib.RingTheory.Multiplicity.581_0.uTHZeAJqYiw3Jx8
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case inl
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h✝ : ¬(Finite p a ∧ Finite p b)
h : ¬Finite p a
⊢ ⊤ = multiplicity p a + multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;>
|
simp [eq_top_iff_not_finite.2 h]
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;>
|
Mathlib.RingTheory.Multiplicity.581_0.uTHZeAJqYiw3Jx8
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
case inr
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a b : α
hp : Prime p
h✝ : ¬(Finite p a ∧ Finite p b)
h : ¬Finite p b
⊢ ⊤ = multiplicity p a + multiplicity p b
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;>
|
simp [eq_top_iff_not_finite.2 h]
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;>
|
Mathlib.RingTheory.Multiplicity.581_0.uTHZeAJqYiw3Jx8
|
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
s : Finset β
f : β → α
⊢ multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
|
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
s : Finset β
f : β → α
⊢ multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
|
induction' s using Finset.induction with a s has ih h
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
case empty
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
f : β → α
⊢ multiplicity p (∏ x in ∅, f x) = ∑ x in ∅, multiplicity p (f x)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
·
|
simp only [Finset.sum_empty, Finset.prod_empty]
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
·
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
case empty
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
f : β → α
⊢ multiplicity p 1 = 0
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
|
convert one_right hp.not_unit
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
case insert
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
f : β → α
a : β
s : Finset β
has : a ∉ s
ih : multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
⊢ multiplicity p (∏ x in insert a s, f x) = ∑ x in insert a s, multiplicity p (f x)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
·
|
simp [has, ← ih]
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
·
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
case insert
α : Type u_1
β✝ : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
β : Type u_3
p : α
hp : Prime p
f : β → α
a : β
s : Finset β
has : a ∉ s
ih : multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
⊢ multiplicity p (f a * ∏ x in s, f x) = multiplicity p (f a) + multiplicity p (∏ x in s, f x)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
|
convert multiplicity.mul hp
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
|
Mathlib.RingTheory.Multiplicity.593_0.uTHZeAJqYiw3Jx8
|
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x)
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
⊢ ∀ {k : ℕ}, Part.get (multiplicity p (a ^ k)) (_ : Finite p (a ^ k)) = k * Part.get (multiplicity p a) ha
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
|
intro k
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
k : ℕ
⊢ Part.get (multiplicity p (a ^ k)) (_ : Finite p (a ^ k)) = k * Part.get (multiplicity p a) ha
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
|
induction' k with k hk
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
case zero
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
⊢ Part.get (multiplicity p (a ^ zero)) (_ : Finite p (a ^ zero)) = zero * Part.get (multiplicity p a) ha
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
·
|
simp [one_right hp.not_unit]
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
·
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
case succ
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
k : ℕ
hk : Part.get (multiplicity p (a ^ k)) (_ : Finite p (a ^ k)) = k * Part.get (multiplicity p a) ha
⊢ Part.get (multiplicity p (a ^ succ k)) (_ : Finite p (a ^ succ k)) = succ k * Part.get (multiplicity p a) ha
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
·
|
have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
·
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
k : ℕ
hk : Part.get (multiplicity p (a ^ k)) (_ : Finite p (a ^ k)) = k * Part.get (multiplicity p a) ha
⊢ multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k)
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by
|
rw [_root_.pow_succ]
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
case succ
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
ha : Finite p a
k : ℕ
hk : Part.get (multiplicity p (a ^ k)) (_ : Finite p (a ^ k)) = k * Part.get (multiplicity p a) ha
this : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k)
⊢ Part.get (multiplicity p (a ^ succ k)) (_ : Finite p (a ^ succ k)) = succ k * Part.get (multiplicity p a) ha
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
|
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
|
Mathlib.RingTheory.Multiplicity.604_0.uTHZeAJqYiw3Jx8
|
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
⊢ multiplicity p (a ^ 0) = 0 • multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by
|
simp [one_right hp.not_unit]
|
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by
|
Mathlib.RingTheory.Multiplicity.614_0.uTHZeAJqYiw3Jx8
|
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p a : α
hp : Prime p
k : ℕ
⊢ multiplicity p (a ^ succ k) = succ k • multiplicity p a
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by
|
simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
|
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by
|
Mathlib.RingTheory.Multiplicity.614_0.uTHZeAJqYiw3Jx8
|
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p : α
h0 : p ≠ 0
hu : ¬IsUnit p
n : ℕ
⊢ multiplicity p (p ^ n) = ↑n
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
#align multiplicity.pow multiplicity.pow
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
|
rw [eq_coe_iff]
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
|
Mathlib.RingTheory.Multiplicity.619_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n
|
Mathlib_RingTheory_Multiplicity
|
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p : α
h0 : p ≠ 0
hu : ¬IsUnit p
n : ℕ
⊢ p ^ n ∣ p ^ n ∧ ¬p ^ (n + 1) ∣ p ^ n
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
#align multiplicity.pow multiplicity.pow
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
|
use dvd_rfl
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
|
Mathlib.RingTheory.Multiplicity.619_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n
|
Mathlib_RingTheory_Multiplicity
|
case right
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p : α
h0 : p ≠ 0
hu : ¬IsUnit p
n : ℕ
⊢ ¬p ^ (n + 1) ∣ p ^ n
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
#align multiplicity.pow multiplicity.pow
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
use dvd_rfl
|
rw [pow_dvd_pow_iff h0 hu]
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
use dvd_rfl
|
Mathlib.RingTheory.Multiplicity.619_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n
|
Mathlib_RingTheory_Multiplicity
|
case right
α : Type u_1
β : Type u_2
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : DecidableRel fun x x_1 => x ∣ x_1
p : α
h0 : p ≠ 0
hu : ¬IsUnit p
n : ℕ
⊢ ¬n + 1 ≤ n
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.SMulWithZero
import Mathlib.Data.Nat.PartENat
import Mathlib.Tactic.Linarith
#align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
variable {α β : Type*}
open Nat Part
open BigOperators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat :=
PartENat.find fun n => ¬a ^ (n + 1) ∣ b
#align multiplicity multiplicity
namespace multiplicity
section Monoid
variable [Monoid α] [Monoid β]
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible]
def Finite (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
#align multiplicity.finite multiplicity.Finite
theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} :
Finite a b ↔ (multiplicity a b).Dom :=
Iff.rfl
#align multiplicity.finite_iff_dom multiplicity.finite_iff_dom
theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
#align multiplicity.finite_def multiplicity.finite_def
theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ =>
hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
#align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right
@[norm_cast]
theorem Int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by
apply Part.ext'
· rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ]
norm_cast
· intro h1 h2
apply _root_.le_antisymm <;>
· apply Nat.find_mono
norm_cast
simp
#align multiplicity.int.coe_nat_multiplicity multiplicity.Int.coe_nat_multiplicity
theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [Finite, Classical.not_not] using h),
by simp [Finite, multiplicity, Classical.not_not]; tauto⟩
#align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall
theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
#align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite
theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
#align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right
variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)]
theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} :
(k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
Nat.casesOn k
(fun _ => by
rw [_root_.pow_zero]
exact one_dvd _)
fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk
#align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity
theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get])
#align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd
theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by
rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h)
#align multiplicity.is_greatest multiplicity.is_greatest
theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm)
#align multiplicity.is_greatest' multiplicity.is_greatest'
theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) :
0 < (multiplicity a b).get hfin := by
refine' zero_lt_iff.2 fun h => _
simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h)
#align multiplicity.pos_of_dvd multiplicity.pos_of_dvd
theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : PartENat) = multiplicity a b :=
le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by
have : Finite a b := ⟨k, hsucc⟩
rw [PartENat.le_coe_iff]
exact ⟨this, Nat.find_min' _ hsucc⟩
#align multiplicity.unique multiplicity.unique
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
#align multiplicity.unique' multiplicity.unique'
theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) :
(k : PartENat) ≤ multiplicity a b :=
le_of_not_gt fun hk' => is_greatest hk' hk
#align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} :
a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
#align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le]
#align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd
theorem eq_coe_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
rw [← PartENat.some_eq_natCast]
exact
⟨fun h =>
let ⟨h₁, h₂⟩ := eq_some_iff.1 h
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by
rw [PartENat.lt_coe_iff]
exact ⟨h₁, lt_succ_self _⟩)⟩,
fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩
#align multiplicity.eq_coe_iff multiplicity.eq_coe_iff
theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(PartENat.find_eq_top_iff _).trans <| by
simp only [Classical.not_not]
exact
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
fun n => h _,
fun h n => h _⟩
#align multiplicity.eq_top_iff multiplicity.eq_top_iff
@[simp]
theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _)
#align multiplicity.is_unit_left multiplicity.isUnit_left
-- @[simp] Porting note: simp can prove this
theorem one_left (b : α) : multiplicity 1 b = ⊤ :=
isUnit_left b isUnit_one
#align multiplicity.one_left multiplicity.one_left
@[simp]
theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by
rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero]
simp [not_dvd_one_of_finite_one_right ha]
#align multiplicity.get_one_right multiplicity.get_one_right
-- @[simp] Porting note: simp can prove this
theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ :=
isUnit_left a u.isUnit
#align multiplicity.unit_left multiplicity.unit_left
theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by
rw [← Nat.cast_zero, eq_coe_iff]
simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and]
#align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero
theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b :=
multiplicity_eq_zero.not_left
#align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero
theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b :=
Part.eq_none_iff'
#align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite
theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by
rw [Ne.def, eq_top_iff_not_finite, Classical.not_not]
#align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]
#align multiplicity.lt_top_iff_finite multiplicity.lt_top_iff_finite
theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) :
∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin
refine' ⟨c, hc, _⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ'] at hc
have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩
exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁
#align multiplicity.exists_eq_pow_mul_and_not_dvd multiplicity.exists_eq_pow_mul_and_not_dvd
theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d :=
⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h =>
letI := Classical.dec (Finite a b)
if hab : Finite a b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else by
have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _)
rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩
#align multiplicity.multiplicity_le_multiplicity_iff multiplicity.multiplicity_le_multiplicity_iff
theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} :
multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩,
fun h =>
le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp)
(multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩
#align multiplicity.multiplicity_eq_multiplicity_iff multiplicity.multiplicity_eq_multiplicity_iff
theorem le_multiplicity_map {F : Type*} [MonoidHomClass F α β] (f : F) {a b : α} :
multiplicity a b ≤ multiplicity (f a) (f b) :=
multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem multiplicity_map_eq {F : Type*} [MulEquivClass F α β] (f : F) {a b : α} :
multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f
theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
multiplicity a b ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_right multiplicity.multiplicity_le_multiplicity_of_dvd_right
theorem eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd)
(multiplicity_le_multiplicity_of_dvd_right h.symm.dvd)
#align multiplicity.eq_of_associated_right multiplicity.eq_of_associated_right
theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by
rw [← pow_one a]
apply pow_dvd_of_le_multiplicity
simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h
#align multiplicity.dvd_of_multiplicity_pos multiplicity.dvd_of_multiplicity_pos
theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd =>
lt_of_le_of_ne (zero_le _) fun heq =>
is_greatest
(show multiplicity a b < ↑1 by
simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one)
(by rwa [pow_one a])⟩
#align multiplicity.dvd_iff_multiplicity_pos multiplicity.dvd_iff_multiplicity_pos
theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne.def, Classical.not_not, not_lt,
le_zero_iff]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by linarith
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b),
fun h => by cases h <;> simp [*]⟩
#align multiplicity.finite_nat_iff multiplicity.finite_nat_iff
alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by
rw [mul_comm]; exact finite_of_finite_mul_right
#align multiplicity.finite_of_finite_mul_left multiplicity.finite_of_finite_mul_left
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 :=
eq_coe_iff.2
⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by
rw [pow_one]
exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩
#align multiplicity.is_unit_right multiplicity.isUnit_right
theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
isUnit_right ha isUnit_one
#align multiplicity.one_right multiplicity.one_right
theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
isUnit_right ha u.isUnit
#align multiplicity.unit_right multiplicity.unit_right
open Classical
theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
#align multiplicity.multiplicity_le_multiplicity_of_dvd_left multiplicity.multiplicity_le_multiplicity_of_dvd_left
theorem eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd)
(multiplicity_le_multiplicity_of_dvd_left h.symm.dvd)
#align multiplicity.eq_of_associated_left multiplicity.eq_of_associated_left
-- Porting note: this was doing nothing in mathlib3 also
-- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
#align multiplicity.ne_zero_of_finite multiplicity.ne_zero_of_finite
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem zero (a : α) : multiplicity a 0 = ⊤ :=
Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _)
#align multiplicity.zero multiplicity.zero
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
#align multiplicity.multiplicity_zero_eq_zero_of_ne_zero multiplicity.multiplicity_zero_eq_zero_of_ne_zero
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem multiplicity_mk_eq_multiplicity
[DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} :
multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by
by_cases h : Finite a b
· rw [← PartENat.natCast_get (finite_iff_dom.mp h)]
refine'
(multiplicity.unique
(show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from _) _).symm <;>
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
· exact pow_multiplicity_dvd h
· exact is_greatest
((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _)))
· suffices ¬Finite (Associates.mk a) (Associates.mk b) by
rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this
rw [h, this]
refine'
not_finite_iff_forall.mpr fun n => by
rw [← Associates.mk_pow, Associates.mk_dvd_mk]
exact not_finite_iff_forall.mp h n
#align multiplicity.multiplicity_mk_eq_multiplicity multiplicity.multiplicity_mk_eq_multiplicity
end CommMonoidWithZero
section Semiring
variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
theorem min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(fun h => by
rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
fun h => by
rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn
#align multiplicity.min_le_multiplicity_add multiplicity.min_le_multiplicity_add
end Semiring
section Ring
variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ =>
PartENat.natCast_inj.1 (by
rw [PartENat.natCast_get]
exact Eq.symm
(unique (pow_multiplicity_dvd _).neg_right
(mt dvd_neg.1 (is_greatest' _ (lt_succ_self _)))))
#align multiplicity.neg multiplicity.neg
theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by
cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h]
· rw [Int.coe_nat_multiplicity]
· rw [multiplicity.neg, Int.coe_nat_multiplicity]
#align multiplicity.int.nat_abs multiplicity.Int.natAbs
theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b := by
apply le_antisymm
· apply PartENat.le_of_lt_add_one
cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk
rw [hk]
rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right]
intro h_dvd
· apply multiplicity.is_greatest _ h_dvd
rw [hk, ← Nat.succ_eq_add_one]
norm_cast
apply Nat.lt_succ_self k
· rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one]
exact PartENat.add_one_le_of_lt h
· have := @min_le_multiplicity_add α _ _ p a b
rwa [← min_eq_right (le_of_lt h)]
#align multiplicity.multiplicity_add_of_gt multiplicity.multiplicity_add_of_gt
theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b := by
rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption
#align multiplicity.multiplicity_sub_of_gt multiplicity.multiplicity_sub_of_gt
theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab)
· rw [add_comm, multiplicity_add_of_gt hab, min_eq_left]
exact le_of_lt hab
· contradiction
· rw [multiplicity_add_of_gt hab, min_eq_right]
exact le_of_lt hab
#align multiplicity.multiplicity_add_eq_min multiplicity.multiplicity_add_eq_min
end Ring
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
/- Porting note: removed previous wf recursion hints and added termination_by
Also pulled a b intro parameters since Lean parses that more easily -/
theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} :
∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n, m => fun ha hb ⟨s, hs⟩ =>
have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩
(hp.2.2 a b this).elim
(fun ⟨x, hx⟩ =>
have hn0 : 0 < n :=
Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha
have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m)
finite_mul_aux hp hpx hb
⟨s, mul_right_cancel₀ hp.1 (by
rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩)
fun ⟨x, hx⟩ =>
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb
have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ =>
hb
(hx.symm ▸
⟨y,
mul_right_cancel₀ hp.1 <| by
rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩)
finite_mul_aux hp ha hpx
⟨s, mul_right_cancel₀ hp.1 (by
rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)]
simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩
termination_by finite_mul_aux _ _ n m => n+m
#align multiplicity.finite_mul_aux multiplicity.finite_mul_aux
theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) :=
fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩
#align multiplicity.finite_mul multiplicity.finite_mul
theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b :=
⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h =>
finite_mul hp h.1 h.2⟩
#align multiplicity.finite_mul_iff multiplicity.finite_mul_iff
theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k)
| 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩
| k + 1, ha => by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow hp ha)
#align multiplicity.finite_pow multiplicity.finite_pow
variable [DecidableRel ((· ∣ ·) : α → α → Prop)]
@[simp]
theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by
rw [← Nat.cast_one]
exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2
⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
#align multiplicity.multiplicity_self multiplicity.multiplicity_self
@[simp]
theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 :=
PartENat.get_eq_iff_eq_coe.2
(eq_coe_iff.2
⟨by simp, fun ⟨b, hb⟩ => by
rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact
mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩)
#align multiplicity.get_multiplicity_self multiplicity.get_multiplicity_self
protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _
have hpoweq :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
by simp [pow_add]
have hdiv :
p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣
a * b :=
by rw [hpoweq]; apply mul_dvd_mul <;> assumption
have hsucc :
¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 +
1) ∣
a * b :=
fun h =>
not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h)
rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩
#align multiplicity.mul' multiplicity.mul'
open Classical
protected theorem mul {p a b : α} (hp : Prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : Finite p a ∧ Finite p b then by
rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ←
PartENat.natCast_get (finite_iff_dom.1 h.2), ←
PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add,
PartENat.natCast_inj, multiplicity.mul' hp]
else by
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)]
cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h]
#align multiplicity.mul multiplicity.mul
theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := by
classical
induction' s using Finset.induction with a s has ih h
· simp only [Finset.sum_empty, Finset.prod_empty]
convert one_right hp.not_unit
· simp [has, ← ih]
convert multiplicity.mul hp
#align multiplicity.finset.prod multiplicity.Finset.prod
-- Porting note: with protected could not use pow' k in the succ branch
protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) :
∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by
intro k
induction' k with k hk
· simp [one_right hp.not_unit]
· have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ]
rw [succ_eq_add_one, get_eq_get_of_eq _ _ this,
multiplicity.mul' hp, hk, add_mul, one_mul, add_comm]
#align multiplicity.pow' multiplicity.pow'
theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a
| 0 => by simp [one_right hp.not_unit]
| succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp]
#align multiplicity.pow multiplicity.pow
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
use dvd_rfl
rw [pow_dvd_pow_iff h0 hu]
|
apply Nat.not_succ_le_self
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n := by
rw [eq_coe_iff]
use dvd_rfl
rw [pow_dvd_pow_iff h0 hu]
|
Mathlib.RingTheory.Multiplicity.619_0.uTHZeAJqYiw3Jx8
|
theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) :
multiplicity p (p ^ n) = n
|
Mathlib_RingTheory_Multiplicity
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.