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
- p.maxPowDiv n = Nat.maxPowDiv.go 0 p n
Instances For
@[irreducible]
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