The maximal power of one natural number dividing another #
Here we introduce p.maxPowDiv n
which returns the maximal k : ℕ
for
which p ^ k ∣ n
with the convention that maxPowDiv 1 n = 0
for all n
.
We prove enough about maxPowDiv
in this file to show equality with Nat.padicValNat
in
padicValNat.padicValNat_eq_maxPowDiv
.
The implementation of maxPowDiv
improves on the speed of padicValNat
.
Tail recursive function which returns the largest k : ℕ
such that p ^ k ∣ n
for any p : ℕ
.
padicValNat_eq_maxPowDiv
allows the code generator to use this definition for padicValNat
Equations
- Nat.maxPowDiv p n = Nat.maxPowDiv.go 0 p n
Instances For
Tail recursive function which returns the largest k : ℕ
such that p ^ k ∣ n
for any p : ℕ
.
padicValNat_eq_maxPowDiv
allows the code generator to use this definition for padicValNat
Equations
Instances For
theorem
Nat.maxPowDiv.go_succ
{k : ℕ}
{p : ℕ}
{n : ℕ}
:
Nat.maxPowDiv.go (k + 1) p n = Nat.maxPowDiv.go k p n + 1
theorem
Nat.maxPowDiv.base_mul_eq_succ
{p : ℕ}
{n : ℕ}
(hp : 1 < p)
(hn : 0 < n)
:
Nat.maxPowDiv p (p * n) = Nat.maxPowDiv p n + 1
theorem
Nat.maxPowDiv.base_pow_mul
{p : ℕ}
{n : ℕ}
{exp : ℕ}
(hp : 1 < p)
(hn : 0 < n)
:
Nat.maxPowDiv p (p ^ exp * n) = Nat.maxPowDiv p n + exp