The valuation of an integer at a prime #
The loop of Ratpoints.Setup.valuation, repeated division with remainder, gives for n ≠ 0 and
p > 1 an exponent v and the remainder r ≠ 0 with |n| = p ^ v m and m mod p = r: the
p-adic valuation of |n| and the unit part of |n| modulo p.
Main statements #
Ratpoints.Setup.valuation_spec: forp > 1the loop ends with|n| = p ^ v mandm mod p = r ≠ 0, and with(Ratpoints.veryBig, 0)forn = 0;Ratpoints.Setup.exists_eq_run_valuationstates this forn ≠ 0without the program logic, withp ∤ m, andRatpoints.Setup.exists_eq_of_eq_run_valuationfor a natural numberw ≠ 0, asw = p ^ v mwithp ∤ m.Ratpoints.Setup.fst_run_valuation: forp > 1andn ≠ 0, the valuation ispadicValNat p |n|.
Implementation notes #
The contract is proved with vcgen, the program logic of Lean core, with a loop invariant that is
a named definition, in a file with Mathlib, since the valuation of the C code is Mathlib's
padicValNat. Ratpoints.Setup.valuation_value gives the result as its own value, for the
contracts of the loops that bind it and read it through the plain statements.
The invariant of the loop of Ratpoints.Setup.valuation on n and p, on the quotient q,
the remainder r and the count v: |n| = p ^ v (p q + r) with r < p, and r ≠ 0 at the
exit.
Equations
Instances For
The loop ends, since the quotient drops with every pass while the remainder is 0, |n| being
p ^ v times a positive multiple of p; for p = 1 and n ≠ 0 it would not.
The result of Ratpoints.Setup.valuation as its own value, for the contracts of the loops that
bind it and read it through Ratpoints.Setup.exists_eq_run_valuation and its corollaries.
Ratpoints.Setup.valuation_spec for n ≠ 0 as a plain statement, which the proofs use without
the program logic, with p ∤ m for the remainder ≠ 0.