Module docstring
{"# Prime powers
This file deals with prime powers: numbers which are positive integer powers of a single prime. "}
{"# Prime powers
This file deals with prime powers: numbers which are positive integer powers of a single prime. "}
IsPrimePow
definition
: Prop
/-- `n` is a prime power if there is a prime `p` and a positive natural `k` such that `n` can be
written as `p^k`. -/
def IsPrimePow : Prop :=
∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n
isPrimePow_def
theorem
: IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n
theorem isPrimePow_def : IsPrimePowIsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n :=
Iff.rfl
isPrimePow_iff_pow_succ
theorem
: IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ p ^ (k + 1) = n
/-- An equivalent definition for prime powers: `n` is a prime power iff there is a prime `p` and a
natural `k` such that `n` can be written as `p^(k+1)`. -/
theorem isPrimePow_iff_pow_succ : IsPrimePowIsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ p ^ (k + 1) = n :=
(isPrimePow_def _).trans
⟨fun ⟨p, k, hp, hk, hn⟩ => ⟨p, k - 1, hp, by rwa [Nat.sub_add_cancel hk]⟩, fun ⟨_, _, hp, hn⟩ =>
⟨_, _, hp, Nat.succ_pos', hn⟩⟩
not_isPrimePow_zero
theorem
[NoZeroDivisors R] : ¬IsPrimePow (0 : R)
theorem not_isPrimePow_zero [NoZeroDivisors R] : ¬IsPrimePow (0 : R) := by
simp only [isPrimePow_def, not_exists, not_and', and_imp]
intro x n _hn hx
rw [pow_eq_zero hx]
simp
IsPrimePow.not_unit
theorem
{n : R} (h : IsPrimePow n) : ¬IsUnit n
theorem IsPrimePow.not_unit {n : R} (h : IsPrimePow n) : ¬IsUnit n :=
let ⟨_p, _k, hp, hk, hn⟩ := h
hn ▸ (isUnit_pow_iff hk.ne').not.mpr hp.not_unit
IsUnit.not_isPrimePow
theorem
{n : R} (h : IsUnit n) : ¬IsPrimePow n
theorem IsUnit.not_isPrimePow {n : R} (h : IsUnit n) : ¬IsPrimePow n := fun h' => h'.not_unit h
not_isPrimePow_one
theorem
: ¬IsPrimePow (1 : R)
theorem not_isPrimePow_one : ¬IsPrimePow (1 : R) :=
isUnit_one.not_isPrimePow
Prime.isPrimePow
theorem
{p : R} (hp : Prime p) : IsPrimePow p
theorem Prime.isPrimePow {p : R} (hp : Prime p) : IsPrimePow p :=
⟨p, 1, hp, zero_lt_one, by simp⟩
IsPrimePow.pow
theorem
{n : R} (hn : IsPrimePow n) {k : ℕ} (hk : k ≠ 0) : IsPrimePow (n ^ k)
theorem IsPrimePow.pow {n : R} (hn : IsPrimePow n) {k : ℕ} (hk : k ≠ 0) : IsPrimePow (n ^ k) :=
let ⟨p, k', hp, hk', hn⟩ := hn
⟨p, k * k', hp, mul_pos hk.bot_lt hk', by rw [pow_mul', hn]⟩
IsPrimePow.ne_zero
theorem
[NoZeroDivisors R] {n : R} (h : IsPrimePow n) : n ≠ 0
theorem IsPrimePow.ne_zero [NoZeroDivisors R] {n : R} (h : IsPrimePow n) : n ≠ 0 := fun t =>
not_isPrimePow_zero (t ▸ h)
IsPrimePow.ne_one
theorem
{n : R} (h : IsPrimePow n) : n ≠ 1
theorem IsPrimePow.ne_one {n : R} (h : IsPrimePow n) : n ≠ 1 := fun t =>
not_isPrimePow_one (t ▸ h)
isPrimePow_nat_iff
theorem
(n : ℕ) : IsPrimePow n ↔ ∃ p k : ℕ, Nat.Prime p ∧ 0 < k ∧ p ^ k = n
theorem isPrimePow_nat_iff (n : ℕ) : IsPrimePowIsPrimePow n ↔ ∃ p k : ℕ, Nat.Prime p ∧ 0 < k ∧ p ^ k = n := by
simp only [isPrimePow_def, Nat.prime_iff]
Nat.Prime.isPrimePow
theorem
{p : ℕ} (hp : p.Prime) : IsPrimePow p
theorem Nat.Prime.isPrimePow {p : ℕ} (hp : p.Prime) : IsPrimePow p :=
_root_.Prime.isPrimePow (prime_iff.mp hp)
isPrimePow_nat_iff_bounded
theorem
(n : ℕ) : IsPrimePow n ↔ ∃ p : ℕ, p ≤ n ∧ ∃ k : ℕ, k ≤ n ∧ p.Prime ∧ 0 < k ∧ p ^ k = n
theorem isPrimePow_nat_iff_bounded (n : ℕ) :
IsPrimePowIsPrimePow n ↔ ∃ p : ℕ, p ≤ n ∧ ∃ k : ℕ, k ≤ n ∧ p.Prime ∧ 0 < k ∧ p ^ k = n := by
rw [isPrimePow_nat_iff]
refine Iff.symm ⟨fun ⟨p, _, k, _, hp, hk, hn⟩ => ⟨p, k, hp, hk, hn⟩, ?_⟩
rintro ⟨p, k, hp, hk, rfl⟩
refine ⟨p, ?_, k, (Nat.lt_pow_self hp.one_lt).le, hp, hk, rfl⟩
conv => { lhs; rw [← (pow_one p)] }
exact Nat.pow_le_pow_right hp.one_lt.le hk
instDecidableIsPrimePowNat
instance
{n : ℕ} : Decidable (IsPrimePow n)
instance {n : ℕ} : Decidable (IsPrimePow n) :=
decidable_of_iff' _ (isPrimePow_nat_iff_bounded n)
IsPrimePow.dvd
theorem
{n m : ℕ} (hn : IsPrimePow n) (hm : m ∣ n) (hm₁ : m ≠ 1) : IsPrimePow m
theorem IsPrimePow.dvd {n m : ℕ} (hn : IsPrimePow n) (hm : m ∣ n) (hm₁ : m ≠ 1) : IsPrimePow m := by
rw [isPrimePow_nat_iff] at hn ⊢
rcases hn with ⟨p, k, hp, _hk, rfl⟩
obtain ⟨i, hik, rfl⟩ := (Nat.dvd_prime_pow hp).1 hm
refine ⟨p, i, hp, ?_, rfl⟩
apply Nat.pos_of_ne_zero
rintro rfl
simp only [pow_zero, ne_eq, not_true_eq_false] at hm₁
IsPrimePow.two_le
theorem
: ∀ {n : ℕ}, IsPrimePow n → 2 ≤ n
theorem IsPrimePow.two_le : ∀ {n : ℕ}, IsPrimePow n → 2 ≤ n
| 0, h => (not_isPrimePow_zero h).elim
| 1, h => (not_isPrimePow_one h).elim
| _n + 2, _ => le_add_self
IsPrimePow.pos
theorem
{n : ℕ} (hn : IsPrimePow n) : 0 < n
theorem IsPrimePow.pos {n : ℕ} (hn : IsPrimePow n) : 0 < n :=
pos_of_gt hn.two_le
IsPrimePow.one_lt
theorem
{n : ℕ} (h : IsPrimePow n) : 1 < n
theorem IsPrimePow.one_lt {n : ℕ} (h : IsPrimePow n) : 1 < n :=
h.two_le