Skip to content

Commit

Permalink
feat(data/nat/prime): add nat.eq_two_pow_or_exists_odd_prime_and_dvd (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben-VandeVelde committed Mar 5, 2022
1 parent 8b91390 commit fa6b16e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/data/nat/prime.lean
Expand Up @@ -396,6 +396,9 @@ lemma prime.eq_two_or_odd {p : ℕ} (hp : prime p) : p = 2 ∨ p % 2 = 1 :=
p.mod_two_eq_zero_or_one.imp_left
(λ h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)

lemma prime.eq_two_or_odd' {p : ℕ} (hp : prime p) : p = 2 ∨ odd p :=
or.imp_right (λ h, ⟨p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)⟩) hp.eq_two_or_odd

theorem coprime_of_dvd {m n : ℕ} (H : ∀ k, prime k → k ∣ m → ¬ k ∣ n) : coprime m n :=
begin
rw [coprime_iff_gcd_eq_one],
Expand Down Expand Up @@ -726,6 +729,15 @@ begin
rwa eq_of_mem_repeat hq,
end

lemma eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0)
(h : ∀ {d}, nat.prime d → d ∣ n → d = p) :
n = p ^ n.factors.length :=
begin
set k := n.factors.length,
rw [←prod_factors hpos, ←prod_repeat p k,
eq_repeat_of_mem (λ d hd, h (prime_of_mem_factors hd) (dvd_of_mem_factors hd))],
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 {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a * b).factors ~ a.factors ++ b.factors :=
Expand Down Expand Up @@ -1150,6 +1162,15 @@ end
lemma mem_factors_mul_right {p a b : ℕ} (hpb : p ∈ b.factors) (ha : a ≠ 0) : p ∈ (a*b).factors :=
by { rw mul_comm, exact mem_factors_mul_left hpb ha }

lemma eq_two_pow_or_exists_odd_prime_and_dvd (n : ℕ) :
(∃ k : ℕ, n = 2 ^ k) ∨ ∃ p, nat.prime p ∧ p ∣ n ∧ odd p :=
(eq_or_ne n 0).elim
(λ hn, (or.inr ⟨3, prime_three, hn.symm ▸ dvd_zero 3, ⟨1, rfl⟩⟩))
(λ hn, or_iff_not_imp_right.mpr
(λ H, ⟨n.factors.length, eq_prime_pow_of_unique_prime_dvd hn
(λ p hprime hdvd, hprime.eq_two_or_odd'.resolve_right
(λ hodd, H ⟨p, hprime, hdvd, hodd⟩))⟩))

end nat

namespace int
Expand Down

0 comments on commit fa6b16e

Please sign in to comment.