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.
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)))$$.
Equations
- p.maxPowDvdDiv n = if H : 1 < p ∧ n ≠ 0 then Nat.maxPowDvdDiv.go n p H else (0, n)
Instances For
For p ≠ 1, the p-adic valuation of a natural n ≠ 0 is the largest natural number k such
that p^k divides n. If n = 0 or p = 1, then padicValNat p n defaults to 0.
Equations
- padicValNat p n = (p.maxPowDvdDiv n).fst
Instances For
Divide n by the maximal power of p that divides n.
Equations
- n.divMaxPow p = (p.maxPowDvdDiv n).snd
Instances For
If p > 1, n > 0, then the first component of maxPowDvdDiv is the maximal power of p
that divides n.
Alias of padicValNat.
For p ≠ 1, the p-adic valuation of a natural n ≠ 0 is the largest natural number k such
that p^k divides n. If n = 0 or p = 1, then padicValNat p n defaults to 0.
Equations
Instances For
Alias of padicValNat_base_mul.
Alias of padicValNat_base_pow_mul.
Alias of the reverse direction of Nat.pow_dvd_iff_le_padicValNat.
If p > 1, n > 0, then the first component of maxPowDvdDiv is the maximal power of p
that divides n.
Alias of pow_padicValNat_dvd.
Alias of padicValNat_zero_right.
Alias of padicValNat_zero_left.