The tables of a prime, the soundness of the rows and the exit #
The tables of the sieve compute what they claim: the squares, the inverses and Horner's rule modulo
p. With them, the row of a denominator b in the table of a prime p lets the numerator a of
every point (a, y, b) through (Ratpoints.Sieve.admits_examinePrime_of_sq_eq): for p ∤ b, since
F(a, b) ≡ b ^ D f(a / b) (mod p) with D even, so that f(a / b) is a square modulo p
(Ratpoints.Sieve.isSquare_sum_mul_div_pow_of_sq_eq_binaryForm), which the table of the prime marks
(Ratpoints.Sieve.getElem!_isFSquare_examinePrime_of_isSquare); for p ∣ b, since gcd(a, b) = 1,
so that p ∤ a (Int.toNat_emod_ne_zero_of_gcd_eq_one). The model computes modulo p in ℕ; the
proofs go through ZMod p.
The table of a prime with the exit (Ratpoints.Sieve.examinePrime?) reduces the coefficients on two
paths with the same result, since the helper mod of the C code is the Euclidean %
(Ratpoints.Sieve.modLong_eq_emod), and computes the values of f by Horner's rule with Barrett's
reduction on a fixed schedule (Ratpoints.Sieve.hornerBarrett): Barrett's reduction gives the
remainder of every u < 2 ^ 64 (Ratpoints.Sieve.barrett_eq), and for p < maxPrimeEven the
accumulator stays below p ^ (hornerSteps + 1) < 2 ^ 64 between two reductions
(Ratpoints.Sieve.HornerInvariant.lt_two_pow_64). So for 0 < p < maxPrimeEven the table that its
loop over the residues gives is that of the reference Ratpoints.Sieve.examinePrime, handed back
with the coefficients reduced modulo p, and when it gives none for a prime p, the curve has no
points (Ratpoints.Sieve.not_isPoint_of_run_examinePrime?_eq_none): a point (a, y, b) gives a
residue that the table marks for p ∤ b, and for p ∣ b a point at infinity modulo p, the last
entry of the table, since c_d is then a square modulo p for even d
(Ratpoints.Sieve.isSquare_getD_degree_of_sq_eq_binaryForm). The values of the C code that could
leave the range of a long stay in it: those of mod for moduli below 2 ^ 59, whose inputs are
longs by the flag of the longs, the negations of the map of a reversed search, and the negation
of a negative leading coefficient in jacobi1, with LONG_MIN replaced by its quarter; these
lemmas discharge the range obligations that the Deviation paragraphs and the docstrings of the model
state, and no proof consumes them.
Main definitions #
Ratpoints.Sieve.HornerInvariant,Ratpoints.Sieve.ExaminePrimeInvariant: the invariants of the loop of Horner's rule inRatpoints.Sieve.hornerBarrettand of the loop over the residues inRatpoints.Sieve.examinePrime?.
Main statements #
Ratpoints.sum_mul_pow_mul_pow_sub_of_eq_mul,Ratpoints.sum_mul_pow_mul_pow_sub_of_eq_mul_right: the binary form of degreeData = k bisf(k) b ^ D, and atb = t athe value attof the reversed polynomial timesa ^ D, in any commutative semiring.Ratpoints.isSquare_sum_mul_pow_of_sq_eq_binaryForm,Ratpoints.isSquare_sum_mul_pow_sub_of_sq_eq_binaryForm: a point whose denominator, or numerator, is a unit of a commutative ring makesf, or the reversed polynomial, take a square value there.Ratpoints.Sieve.getElem!_squaresMod_mul_self_mod,Ratpoints.Sieve.getElem!_squaresMod_of_isSquare,Ratpoints.Sieve.getElem!_inversesMod_mul_mod,Ratpoints.Sieve.natCast_evalMod,Ratpoints.Sieve.natCast_evalMod_reverse: the tables compute their definitions.Ratpoints.Sieve.getElem!_isFSquare_examinePrime_of_isSquare: the table of a prime marks every residue at whichftakes a square value.Ratpoints.Sieve.getElem!_isFSquare_examinePrime_self: the entry of the table of a prime atpsays whether there are points at infinity modulop.Ratpoints.Sieve.admits_examinePrime_of_sq_eq: the rows let every point through.Ratpoints.Sieve.isPrimeEntry_examinePrime: a sieve entry of a primep ≤ 2 ^ 32whose single factor is its table, with its reciprocal, has the shape that the third stage needs.Ratpoints.Sieve.barrett_eq: Barrett's reduction computes the remainder of everyu < 2 ^ 64.Ratpoints.Sieve.HornerInvariant.lt_two_pow_64: the accumulator of Horner's rule in the table ofp < maxPrimeEvenstays below2 ^ 64(Ratpoints.pow_hornerSteps_add_one_lt).Ratpoints.Sieve.hornerBarrett_spec: Horner's rule with Barrett's reduction on its schedule computes the value modulop(Ratpoints.Sieve.evalMod).Ratpoints.Sieve.examinePrime?_eq_examinePrime?_false,Ratpoints.Sieve.examinePrime?_spec, with its plain formsRatpoints.Sieve.run_examinePrime?,Ratpoints.Sieve.eq_examinePrime_of_run_examinePrime?_eq_some,Ratpoints.Sieve.eq_map_range_of_run_examinePrime?_eq_someandRatpoints.Sieve.run_examinePrime?_eq_none_iff: the two paths of the table with the exit give the same result, which is the table of the reference with the coefficients reduced modulopfor0 < p < maxPrimeEven, and when it gives none;Ratpoints.Sieve.eq_examinePrime_of_lt_numPrimes_of_run_examinePrime?_eq_some: so for the prime at a position belowRatpoints.numPrimesof the table.Ratpoints.Sieve.any_isFSquare_examinePrime_of_sq_eq,Ratpoints.Sieve.not_isPoint_of_run_examinePrime?_eq_none,Ratpoints.Sieve.not_isPoint_of_lt_numPrimes_of_run_examinePrime?_eq_none: a point makes an entry of the table of a prime true, so a curve without points modulo a prime has no points.Ratpoints.fitsLong_natCast: a natural number is alongexactly when it is below2 ^ 63.Ratpoints.fitsLong_sixteen_mul,Ratpoints.fitsLong_add_sixteen_mul,Ratpoints.fitsLong_neg,Ratpoints.fitsLong_neg_ite_div_four: the values of the C code that could leave the range of alongstay in it.Ratpoints.Setup.fitsLong_getD_of_useCLong: the inputs ofmodarelongs.
Notation #
Local to the file: reducedCoeffs c d p and reducedCoeffArray c d p, the list and the array of
the coefficients c₀, …, c_d reduced modulo p.
The binary form ∑ fᵢ aⁱ b^(D - i) of degree D ≥ d at a = k b is f(k) b ^ D, in any
commutative semiring; over a field, k = a / b for b ≠ 0, as Polynomial.eval_homogenize says
for polynomials.
The binary form ∑ fᵢ aⁱ b^(D - i) of degree D ≥ d at b = t a is the value
∑ fᵢ t^(D - i) of the reversed polynomial times a ^ D, in any commutative semiring.
A point (a, y, b) whose denominator b is a unit of the commutative ring R makes f take a
square value at the k with a = k b in R: F(a, b) = f(k) b ^ D with D even.
A point (a, y, b) whose numerator a is a unit of the commutative ring R makes the reversed
polynomial take a square value ∑ cᵢ t^(D - i) at the t with b = t a in R:
F(a, b) = a ^ D ∑ cᵢ t^(D - i) with D even.
The squares, the inverses and Horner's rule modulo p #
Modulo a prime p, the square of a residue s ≠ 0 below p is the square of an odd residue,
of s or of p - s: the squares that the generator of the tables of ratpoints marks.
Modulo a prime p, a residue 0 < r < p has an inverse among 1, …, p - 1, so that the trial
of Ratpoints.Sieve.inversesMod finds one.
Horner's rule modulo m on the reversed list of coefficients: the value at x of the
polynomial whose coefficient of x ^ (n - 1 - k) is entry k of the list of length n.
Barrett's reduction and the schedule of Horner's rule #
Barrett's reduction with the reciprocal ⌊(2 ^ 64 - 1) / p⌋ computes u mod p for every
u < 2 ^ 64: the estimate of the quotient is ⌊u / p⌋ or one less
(Nat.mul_sub_one_div_div_mul_le, Nat.lt_mul_sub_one_div_div_add_two_mul), so that one
conditional subtraction finishes.
The invariant of the loops of Horner's rule of Ratpoints.Sieve.hornerBarrett after i
steps, the last reduction k steps back: the accumulator s is congruent modulo p to the value
at a of the polynomial with the coefficients cm[d - i], …, cm[d], and below p ^ (k + 1).
Equations
Instances For
The range obligation of the accumulator of Horner's rule in examine_prime: for
p < maxPrimeEven, the values s a + c of the steps (find_points.c:1729, find_points.c:1741)
and the values that Barrett's reduction takes (find_points.c:1731, find_points.c:1742,
find_points.c:1744) are below p ^ (k + 1) with k ≤ hornerSteps, so below 2 ^ 64: the
unsigned long does not wrap.
The reduction by Barrett's method in the loop of Horner's rule keeps the invariant and restarts the bound.
The step of the loop of Horner's rule of Ratpoints.Sieve.hornerBarrett without reductions,
for d ≤ hornerSteps.
The step of the loop of Horner's rule of Ratpoints.Sieve.hornerBarrett with reductions, for
d > hornerSteps, that reduces.
The step of the loop of Horner's rule of Ratpoints.Sieve.hornerBarrett with reductions, for
d > hornerSteps, that does not reduce.
The exit of the loop of Horner's rule of Ratpoints.Sieve.hornerBarrett without reductions,
for d ≤ hornerSteps, with the reduction at the end.
The exit of the loop of Horner's rule of Ratpoints.Sieve.hornerBarrett with reductions, for
d > hornerSteps, with the reduction at the end.
The contract of Ratpoints.Sieve.hornerBarrett: for a modulus p < maxPrimeEven, a residue
a < p and d + 1 coefficients below p, Horner's rule with Barrett's reduction on its schedule
computes the value modulo p at a (Ratpoints.Sieve.evalMod); the accumulator stays below
2 ^ 64 (Ratpoints.Sieve.HornerInvariant.lt_two_pow_64).
The table of a prime #
The sieve entry of a prime p ≤ 2 ^ 32 whose single factor is the table of the reference, with
the reciprocal of p, has the shape that the third stage needs
(Ratpoints.Sieve.SieveEntry.IsPrimeEntry), whatever its fields of the packing: the inverses of
the nonzero residues are residues, and nonzero, since they are inverses.
The rows let every point through #
The row of the denominator b in the table of the prime p admits the numerator a of every
point (a, y, b) with gcd(a, b) = 1; neither b ≥ 1 nor an odd p is needed.
The table of a prime with the exit #
The path through longs, with the helper mod of the C code, and the path through GMP
integers give the same table, whatever the coefficients: the flag of the longs changes nothing.
The invariant of the loop of Ratpoints.Sieve.examinePrime? over the residues 1, …, k, on the
table t: entry 0 and the entries of these residues, each whether the value modulo p of
Horner's rule (Ratpoints.Sieve.evalMod) on the coefficients reduced modulo p is a square modulo
p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The step of the loop of Ratpoints.Sieve.examinePrime? at the residue cur, the value s of
Horner's rule with Barrett's reduction being that of Horner's rule reduced at every step.
At the end of the loop of Ratpoints.Sieve.examinePrime? over the residues, for p > 0, the
table with the entry at infinity is that of the reference.
The exit of Ratpoints.Sieve.examinePrime?: no entry of the table is true.
The entry that Ratpoints.Sieve.examinePrime? returns when an entry of the table is true.
The contract of Ratpoints.Sieve.examinePrime?: for 0 < p < maxPrimeEven, on both paths of
the reduction of the coefficients, the table with the exit is that of
Ratpoints.Sieve.examinePrime, handed back with the d + 1 coefficients reduced modulo p (the
code and the density of the prime projected away: no contract reads them), when one of its entries
is true, and none otherwise. Horner's rule with Barrett's reduction on its schedule gives the values
of Horner's rule reduced at every step (Ratpoints.Sieve.hornerBarrett_spec).
The exit of examine_prime, for 0 < p < maxPrimeEven: no entry of the table of the reference
is true.
The exit #
A point (a, y, b) with p ∣ b, among them the points at infinity, makes the leading
coefficient c_d a square modulo p for even d: since gcd(a, b) = 1, p ∤ a, and
y ^ 2 ≡ c_d a ^ d (mod p).
For a point (a, y, b) of a curve of even degree and a prime p ∣ b, the residue of c_d
modulo p is marked as a square (Ratpoints.Sieve.isSquare_getD_degree_of_sq_eq_binaryForm).
A point (a, y, b) makes an entry of the table of the prime p true: the residue a / b for
p ∤ b, and the entry p at infinity for p ∣ b, since the degree is odd or c_d is a square
modulo p (Ratpoints.Sieve.getElem!_squaresMod_of_sq_eq).
When the table of the prime p < maxPrimeEven is none, where examine_prime returns -1 and
the search ends, the curve has no points of any height.
The coefficients as longs #
A natural number is a long exactly when it is below 2 ^ 63: the height bounds that
Ratpoints.findPoints does not refuse are those from 1 to 2 ^ 63 - 1.
The value b1 = 16 b that the helper mod of the C code (Ratpoints.Sieve.modLong) computes
first is a long for 0 ≤ b < 2 ^ 59, and so is its negation (Ratpoints.fitsLong_neg), which
mod compares with a.
The value a + 16 b that the helper mod of the C code (Ratpoints.Sieve.modLong) computes
for -16 b ≤ a < 0 is a long for b < 2 ^ 59. The other values that mod computes, but for
16 b and its negation (Ratpoints.fitsLong_sixteen_mul, Ratpoints.fitsLong_neg), lie between
-b and 16 b.
The negation of an integer of absolute value below 2 ^ 63 is a long: so is the negation
-16 b that the helper mod of the C code (Ratpoints.Sieve.modLong) computes for
0 ≤ b < 2 ^ 59, and so are the negations -b and -a of the map of a reversed search
(Ratpoints.Sieve.swapPoint) for a point (a, y, b) with |a| ≤ H and 1 ≤ b ≤ H, since the
height bound H is a long.
The value -f that jacobi1 forms from a negative long leading coefficient f, after it
replaces LONG_MIN by LONG_MIN / 4 (find_points.c:579-584), is a long. The helper mod that
jacobi1 then calls for b < 2 ^ 59 (find_points.c:585) keeps its values in the range of a
long (Ratpoints.fitsLong_sixteen_mul, Ratpoints.fitsLong_neg,
Ratpoints.fitsLong_add_sixteen_mul), and the other values of jacobi1 and jacobi lie between
0 and the larger of b and |f|.