Skip to content

Commit

Permalink
feat(data/nat/prime): some lemmas about prime factors (#10385)
Browse files Browse the repository at this point in the history
A few small lemmas about prime factors, for use in future PRs on prime factorisations and the Euler product formula for totient
  • Loading branch information
stuart-presnell committed Nov 23, 2021
1 parent eb8b1b8 commit ac283c2
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/data/nat/prime.lean
Expand Up @@ -704,6 +704,29 @@ begin
rwa eq_of_mem_repeat hq },
end

/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
lemma perm_factors_mul_of_pos {a b : ℕ} (ha : 0 < a) (hb : 0 < b) :
(a * b).factors ~ a.factors ++ b.factors :=
begin
refine (factors_unique _ _).symm,
{ rw [list.prod_append, prod_factors ha, prod_factors hb] },
{ intros p hp,
rw list.mem_append at hp,
cases hp;
exact prime_of_mem_factors hp },
end

/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
lemma perm_factors_mul_of_coprime {a b : ℕ} (hab : coprime a b) :
(a * b).factors ~ a.factors ++ b.factors :=
begin
rcases a.eq_zero_or_pos with rfl | ha,
{ simp [(coprime_zero_left _).mp hab] },
rcases b.eq_zero_or_pos with rfl | hb,
{ simp [(coprime_zero_right _).mp hab] },
exact perm_factors_mul_of_pos ha hb,
end

end

lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : prime p) {m n k l : ℕ}
Expand Down Expand Up @@ -1022,4 +1045,44 @@ begin
rw [mem_factors_mul_of_pos ha hb p, list.mem_union]
end


open list

/-- For `b > 0`, the power of `p` in `a * b` is at least that in `a` -/
lemma le_factors_count_mul_left {p a b : ℕ} (hb : 0 < b) :
list.count p a.factors ≤ list.count p (a * b).factors :=
begin
rcases a.eq_zero_or_pos with rfl | ha,
{ simp },
{ rw [perm.count_eq (perm_factors_mul_of_pos ha hb) p, count_append p], simp },
end

/-- For `a > 0`, the power of `p` in `a * b` is at least that in `b` -/
lemma le_factors_count_mul_right {p a b : ℕ} (ha : 0 < a) :
list.count p b.factors ≤ list.count p (a * b).factors :=
by { rw mul_comm, apply le_factors_count_mul_left ha }

/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/
lemma mem_factors_mul_left {p a b : ℕ} (hpa : p ∈ a.factors) (hb : 0 < b) : p ∈ (a*b).factors :=
by { rw ←list.count_pos, exact gt_of_ge_of_gt (le_factors_count_mul_left hb) (count_pos.mpr hpa) }

/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/
lemma mem_factors_mul_right {p a b : ℕ} (hpb : p ∈ b.factors) (ha : 0 < a) : p ∈ (a*b).factors :=
by { rw mul_comm, exact mem_factors_mul_left hpb ha }

/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,
for any `b` coprime to `a`. -/
lemma factors_count_eq_of_coprime_left {p a b : ℕ} (hab : coprime a b) (hpa : p ∈ a.factors) :
list.count p (a * b).factors = list.count p a.factors :=
begin
rw [perm.count_eq (perm_factors_mul_of_coprime hab) p, count_append],
simpa only [count_eq_zero_of_not_mem (coprime_factors_disjoint hab hpa)],
end

/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,
for any `a` coprime to `b`. -/
lemma factors_count_eq_of_coprime_right {p a b : ℕ} (hab : coprime a b) (hpb : p ∈ b.factors) :
list.count p (a * b).factors = list.count p b.factors :=
by { rw mul_comm, exact factors_count_eq_of_coprime_left (coprime_comm.mp hab) hpb }

end nat

0 comments on commit ac283c2

Please sign in to comment.