Mathlib.Data.Nat.MaxPowDiv
15 declarations. Mathlib docs · Source
The maximal power of one natural number dividing another
Here we introduce p.maxPowDvd n which returns the maximal k : ℕ for
which p ^ k ∣ n with the convention that maxPowDvd 1 n = 0 for all n.
We prove enough about maxPowDvd in this file to show equality with Nat.padicValNat in
padicValNat.padicValNat_eq_maxPowDvd.
The implementation of maxPowDvd improves on the speed of padicValNat.
theorem Nat.maxPowDvdDiv.go.congr_simp E1 #
∀ (n n_1 : ℕ) (e_n : n = n_1) (p p_1 : ℕ) (e_p : p = p_1) (hp : 1 < p ∧ n ≠ 0),
Nat.maxPowDvdDiv.go n p hp = Nat.maxPowDvdDiv.go n_1 p_1 ⋯
theorem Nat.maxPowDvdDiv.go.induct_unfolding E1 #
∀ (n : ℕ) (motive : (p : ℕ) → 1 < p ∧ n ≠ 0 → ℕ × ℕ → Prop),
(∀ (p : ℕ) (hp : 1 < p ∧ n ≠ 0),
n % p = 0 →
∀ (e q : ℕ),
Nat.maxPowDvdDiv.go n (p * p) ⋯ = (e, q) →
q % p = 0 → motive (p * p) ⋯ (Nat.maxPowDvdDiv.go n (p * p) ⋯) → motive p hp (2 * e + 1, q / p)) →
(∀ (p : ℕ) (hp : 1 < p ∧ n ≠ 0),
n % p = 0 →
∀ (e q : ℕ),
Nat.maxPowDvdDiv.go n (p * p) ⋯ = (e, q) →
¬q % p = 0 → motive (p * p) ⋯ (Nat.maxPowDvdDiv.go n (p * p) ⋯) → motive p hp (2 * e, q)) →
(∀ (p : ℕ) (hp : 1 < p ∧ n ≠ 0), ¬n % p = 0 → motive p hp (0, n)) →
∀ (p : ℕ) (hp : 1 < p ∧ n ≠ 0), motive p hp (Nat.maxPowDvdDiv.go n p hp)
theorem Nat.maxPowDvdDiv.match_1.congr_eq_1 E1 #
∀ (motive : ℕ × ℕ → Sort u_1) (x : ℕ × ℕ) (h_1 : (e q : ℕ) → motive (e, q)) (e q : ℕ),
x = (e, q) →
(match x with
| (e, q) => h_1 e q) ≍
h_1 e q
def Nat.maxPowDvdDiv E1 #
ℕ → ℕ → ℕ × ℕ
Find largest k : ℕ such that p ^ k ∣ n for any p : ℕ, as well as the ratio n / p ^ k.
The implementation recurses from (p, n) to (p * p, n),
so the recursion depth is $$O(\log(\nu_p(n)))$$, thus it is $$O(\log(\log(n)))$$.
def Nat.maxPowDvdDiv.go E1 #
(n p : ℕ) → 1 < p ∧ n ≠ 0 → ℕ × ℕ
Auxiliary definition for Nat.maxPowDvdDiv.
def Nat.divMaxPow E1 #
ℕ → ℕ → ℕ
Divide n by the maximal power of p that divides n.
theorem Nat.maxPowDvdDiv.go_spec E1 #
∀ {n p : ℕ} (hnp : 1 < p ∧ n ≠ 0),
(Nat.maxPowDvdDiv.go n p hnp).2 * p ^ (Nat.maxPowDvdDiv.go n p hnp).1 = n ∧ ¬p ∣ (Nat.maxPowDvdDiv.go n p hnp).2
theorem Nat.maxPowDvdDiv_of_base_le_one E1 #
∀ {p : ℕ}, p ≤ 1 → ∀ (n : ℕ), p.maxPowDvdDiv n = (0, n)
theorem Nat.maxPowDvdDiv_zero_left E0 #
∀ (n : ℕ), Nat.maxPowDvdDiv 0 n = (0, n)
theorem Nat.divMaxPow_zero_right E0 #
∀ (n : ℕ), n.divMaxPow 0 = n
theorem Nat.maxPowDvdDiv_one_left E0 #
∀ (n : ℕ), Nat.maxPowDvdDiv 1 n = (0, n)
theorem Nat.divMaxPow_one_right E0 #
∀ (n : ℕ), n.divMaxPow 1 = n
theorem Nat.maxPowDvdDiv_zero_right E0 #
∀ (p : ℕ), p.maxPowDvdDiv 0 = (0, 0)
theorem Nat.divMaxPow_zero_left E0 #
∀ (p : ℕ), Nat.divMaxPow 0 p = 0
theorem Nat.not_dvd_divMaxPow E1 #
∀ {p n : ℕ}, 1 < p → n ≠ 0 → ¬p ∣ n.divMaxPow p