The Jacobi test by the binary algorithm #
The binary algorithm of the C code (Ratpoints.Sieve.jacobi) computes the Jacobi symbol
(lcf / b*) for b ≥ 1, where b* is the largest divisor of b prime to 2 lcf,
b.coprimePart (2 * lcf.natAbs) (Nat.coprimePart): each round on two numbers f and b
(Ratpoints.Sieve.jacobiRound) keeps the symbol with its sign, taking out the factors 2 of one
number with the sign of (2 / m) for the other, odd, number m (Ratpoints.Sieve.twoSign) and
exchanging the two numbers with the sign of the reciprocity, and gives the symbol (f / b) when
f and b are coprime and otherwise their gcd, which the algorithm divides out of b. For a
polynomial of even degree the symbol is 1 on the denominator b of every point, since c_d is a
square modulo every prime factor of b prime to c_d
(Ratpoints.Sieve.isSquare_getD_degree_of_sq_eq_binaryForm); so the binary algorithm lets the
denominator of every point through, and so does the test by tables, which computes the same symbol
(Ratpoints.Sieve.run_jacobiTest).
Main definitions #
Ratpoints.Sieve.IsJacobiReduction: what the subtraction loop of the binary algorithm returns.
Main statements #
Ratpoints.Sieve.twoSign_eq: the sign of(2 / m).Ratpoints.Sieve.jacobiReduce_spec,Ratpoints.Sieve.jacobiRound_spec: the contracts of the subtraction loop and of a round.Ratpoints.Sieve.jacobi_spec,Ratpoints.Sieve.run_jacobi: the binary algorithm computes(lcf / b*).Ratpoints.Sieve.jacobiSym_eq_one_of_sq_eq_binaryForm: the symbol ofc_dover a divisor of the denominator of a point of a curve of even degree prime toc_dis1, and so is(c_d / b*)(Ratpoints.Sieve.jacobiSym_coprimePart_eq_one_of_sq_eq).Ratpoints.Sieve.run_jacobi_eq_one_of_sq_eq: the binary algorithm gives1on the denominator of every point of a curve of even degree.
Implementation notes #
The contracts are proved with vcgen, with loop invariants that are named definitions, in a file
with Mathlib, since they speak of the Jacobi symbol; the early return of the main loop of
Ratpoints.Sieve.jacobi is part of the invariant of that loop.
The binary algorithm #
The exchange of two odd numbers in the binary algorithm, with the sign of the reciprocity,
-1 exactly when both are 3 (mod 4), as Ratpoints.Sieve.jacobiRound tests it on their bits.
What the subtraction loop Ratpoints.Sieve.jacobiReduce returns on the odd x and y with the
sign s: an odd x' ≤ x, y and a sign s' with s' J(x' | y) = s J(x | y) and
gcd(x', y) = gcd(x, y).
Equations
Instances For
The invariant of the outer loop of Ratpoints.Sieve.jacobiReduce on the odd x and y with
the sign s: the current x' is odd, at most x, has the gcd of x with y, and
s' J(x' | y) = s J(x | y); at the exit x' ≤ y.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the inner loop of Ratpoints.Sieve.jacobiReduce, which halves x₀ - y, for
the value x₀ of the outer loop: the current x' is positive and below x₀, keeps the symbol and
the gcd of x and y, and is even while the loop goes on and odd at its exit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The subtraction loop of the binary algorithm keeps the symbol with its sign and the gcd, and
ends with an odd x' ≤ y; its loops end, since x' drops with every pass.
The invariant of the loop of Ratpoints.Sieve.jacobiRound on f > 0 and the odd b that
takes the factors 2 out of n = f: n is positive, s J(n | b) = J(f | b), the gcd with b is
that of f, and n is odd at the exit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the main loop of Ratpoints.Sieve.jacobiRound on f and b, on the sign s
and the odd n and m: s J(n | m) = J(f | b), the gcd of n and m is that of f and b, and
n = m at the exit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The exchange of the odd a and c with the sign of the reciprocity, followed by the
subtraction loop Ratpoints.Sieve.jacobiReduce of c by a, keeps the symbol with its sign and
the gcd; a pass of the main loop of Ratpoints.Sieve.jacobiRound takes two such steps.
A round of the binary algorithm on f > 0 and the odd b gives their gcd, with the symbol
J(f | b) when it is 1; its main loop ends, since n + m drops with every pass.
The invariant of the loop of Ratpoints.Sieve.jacobi that takes the factors 2 out of b:
the current b' is positive with the part of b prime to 2 lcf, and odd at the exit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the main loop of Ratpoints.Sieve.jacobi on b and lcf, on the result of an
early return, the current b' and f: without a result, b' is odd and positive, f < b',
f ≡ lcf (mod b'), the part of b' prime to 2 lcf is that of b, and f = 0 at the exit; a
result comes only at the exit and is the symbol (lcf / b*) of the part b* of b prime to
2 lcf.
Equations
- One or more equations did not get rendered due to their size.
Instances For
At the exit of Ratpoints.Sieve.jacobi without a result, b' ∣ lcf, so that the part of b
prime to 2 lcf, that of b', is 1.
When gcd(f, b') = 1, the symbol of the round is J(lcf | b'), and b' is the part of b
prime to 2 lcf, being odd and prime to lcf.
Dividing b' by g = gcd(f, b') > 1 keeps the part of b' prime to 2 lcf, since the primes
of g divide lcf, and f ≡ lcf modulo the quotient, which stays odd.
The binary algorithm. Ratpoints.Sieve.jacobi b lcf is the Jacobi symbol (lcf / b*) for
b ≥ 1, b* the largest divisor of b prime to 2 lcf; its main loop ends, since every round
that does not return divides b by a gcd above 1.
The denominators of the points #
Soundness of every form of the Jacobi test. For a point (a, y, b) of a curve of even
degree, every divisor b' of b prime to the leading coefficient c_d has J(c_d | b') = 1: a
prime q ∣ b' divides b, so c_d is a square modulo q
(Ratpoints.Sieve.isSquare_getD_degree_of_sq_eq_binaryForm), and a Jacobi symbol -1 would have a
prime factor q with J(c_d | q) = -1 (jacobiSym.eq_neg_one_at_prime_divisor_of_eq_neg_one).
The binary algorithm gives the symbol 1 on the denominator b of every point of a curve of
even degree: it computes the Jacobi symbol (c_d / b*), and modulo a prime q ∣ b with q ∤ c_d,
c_d is the square of y / a ^ (d / 2).