A norm_num
extension for Jacobi and Legendre symbols #
We extend the norm_num
tactic so that it can be used to provably compute
the value of the Jacobi symbol J(a | b)
or the Legendre symbol legendreSym p a
when
the arguments are numerals.
Implementation notes #
We use the Law of Quadratic Reciprocity for the Jacobi symbol to compute the value of J(a | b)
efficiently, roughly comparable in effort with the euclidean algorithm for the computation
of the gcd of a
and b
. More precisely, the computation is done in the following steps.
-
Use
J(a | 0) = 1
(an artifact of the definition) andJ(a | 1) = 1
to deal with corner cases. -
Use
J(a | b) = J(a % b | b)
to reduce to the case thata
is a natural number. We define a version of the Jacobi symbol restricted to natural numbers for use in the following steps; seeNormNum.jacobiSymNat
. (But we'll continue to writeJ(a | b)
in this description.) -
Remove powers of two from
b
. This is done viaJ(2a | 2b) = 0
andJ(2a+1 | 2b) = J(2a+1 | b)
(another artifact of the definition). -
Now
0 ≤ a < b
andb
is odd. Ifb = 1
, then the value is1
. Ifa = 0
(andb > 1
), then the value is0
. Otherwise, we remove powers of two froma
viaJ(4a | b) = J(a | b)
andJ(2a | b) = ±J(a | b)
, where the sign is determined by the residue class ofb
mod 8, to reduce toa
odd. -
Once
a
is odd, we use Quadratic Reciprocity (QR) in the formJ(a | b) = ±J(b % a | a)
, where the sign is determined by the residue classes ofa
andb
mod 4. We are then back in the previous case.
We provide customized versions of these results for the various reduction steps,
where we encode the residue classes mod 2, mod 4, or mod 8 by using hypotheses like
a % n = b
. In this way, the only divisions we have to compute and prove
are the ones occurring in the use of QR above.
The Jacobi symbol restricted to natural numbers in both arguments.
Equations
- Mathlib.Meta.NormNum.jacobiSymNat a b = jacobiSym (↑a) b
Instances For
API Lemmas #
We repeat part of the API for jacobiSym
with NormNum.jacobiSymNat
and without implicit
arguments, in a form that is suitable for constructing proofs in norm_num
.
Base cases: b = 0
, b = 1
, a = 0
, a = 1
.
Turn a Legendre symbol into a Jacobi symbol.
If a
is even and b
is odd, then we can remove a factor 2
from a
,
but we may have to change the sign, depending on b % 8
.
We give one version for each of the four odd residue classes mod 8
.
Use quadratic reciproity to reduce to smaller b
.
Certified evaluation of the Jacobi symbol #
The following functions recursively evaluate a Jacobi symbol and construct the corresponding proof term.
This is the norm_num
plug-in that evaluates Jacobi symbols.
Equations
- One or more equations did not get rendered due to their size.
Instances For
This is the norm_num
plug-in that evaluates Jacobi symbols on natural numbers.
Equations
- One or more equations did not get rendered due to their size.
Instances For
This is the norm_num
plug-in that evaluates Legendre symbols.
Equations
- One or more equations did not get rendered due to their size.