The correction of the moduli and the run #
The run sifts its blocks in order (Ratpoints.Sieve.sieveRun), each with the cut points of the
decision for it (Ratpoints.Sieve.findDecision), and folds the counters of each block into the
state of the correction (Ratpoints.Sieve.runFold), which may push a decision for the blocks from
Ratpoints.adaptLag + 1 blocks later on (Ratpoints.Sieve.adaptPrimes). The counters are counted
before the exact check, so that the decisions depend neither on the callback nor on the flags of the
output: while the callback does not stop the search, the state of the correction is a fold of the
reports of the blocks in closed form (Ratpoints.Sieve.correctionAfter), and a stop of the callback
in a block ends the run before any decision that the fold of that block pushes is read. So the run
delivers the points of its blocks in order, each with the decision of the block
(Ratpoints.Sieve.blockDecision), and, over the denominators of its shape in the order of its
loops, the points of the numerators that pass the class word and survive the entries of the first
three stages of the decision of the block of the denominator, a decision that is a function of the
denominator alone. The correction keeps the decisions well-formed (Ratpoints.Sieve.DecisionWF) for
any values of the doubles of its cost model, and the decision of a block reads only the folds of the
blocks at least Ratpoints.adaptLag + 1 blocks before it.
Main definitions #
Ratpoints.Sieve.Correction.WF: a well-formed state of the correction.Ratpoints.Sieve.correctionAfter,Ratpoints.Sieve.blockDecision: the state of the correction after the folds of the first blocks with their reports in closed form (Ratpoints.Sieve.blockReport), and the decision of a block, both free of the callback and the flags.Ratpoints.Sieve.blockPoints: the points that a block delivers.Ratpoints.Sieve.deliverSlots: the calling thread of a run with threads, which delivers the slots of the blocks in their order.
Main statements #
Ratpoints.Sieve.adaptPrimes_spec,Ratpoints.Sieve.runFold_spec,Ratpoints.Sieve.wf_correctionAfter: the correction keeps the decisions well-formed.Ratpoints.Sieve.getElem!_findDecision_correctionAfter: the lag of the correction, the decision in force for blockiis the same after the folds of anyk ≥ i - adaptLagblocks.Ratpoints.Sieve.sieveRun_spec,Ratpoints.Sieve.fst_run_sieveRun: the block lemma, the run delivers the points of its blocks in order, each with its decision.Ratpoints.Sieve.exists_run_sieveRun_eq_deliver: the contract of the run per denominator.Ratpoints.Sieve.run_deliverSlots_eq_fst_run_sieveRun: the property that the threads, which the model leaves out, preserve: the blocks sifted apart into slots with the decisions after enough folds, each with a store of its own, and delivered in their order give the output of the run.
Implementation notes #
The contracts of the loops of the correction state only what the natural numbers of the C code do:
no proof reads a value of the doubles, so every statement holds for whatever values the cost model
computes. The run's invariant (Ratpoints.Sieve.SieveRunLoopInvariant) states the delivery for
every choice of the words of the classes and the ranges of the numerators
(Ratpoints.Sieve.RunWords), as the contract of one block does (Ratpoints.Sieve.runBlock_spec).
The correction keeps the decisions well-formed #
The invariant of the loop of Ratpoints.Sieve.adaptUp over the entries from start on, on
the new end of the second stage: at least start, and at most start plus the entries passed.
Equations
Instances For
The walk of the correction up from the end start of the second stage takes some of the
entries from start on: for any values of the doubles, the new end is at least start and at most
the number of the entries, if start is.
The invariant of the loop of Ratpoints.Sieve.adaptDown on the new end want of the second
stage and the position n of the next entry, from the end sp2: want at most sp2 and at least
sp1 if sp2 is, the entries from want to sp2 primes of the table, and n the position just
below want while it is not 0.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The walk of the correction down from the end sp2 of the second stage drops some of the
entries below sp2, only primes of the table and never below sp1: for any values of the doubles,
the new end is at most sp2, at least sp1 if sp2 is, and the entries from it to sp2 count no
factors.
The invariant of the loop of Ratpoints.Sieve.adaptThird on the end sp3 of the third stage,
from the end sp2 of the second: at least sp2 and at most sp2 and the number of the entries.
Equations
Instances For
The correction of the third stage takes some of the entries from the end sp2 of the second
stage on: for any values of the doubles, the end of the third stage is at least sp2 and at most
the number of the entries, if sp2 is.
The correction of the end of the second stage keeps it well-formed.
The correction of the choice of the moduli keeps the decision well-formed.
The fold of a block #
The state of the correction of the moduli is well-formed for the sieve entries es and the end
sp1 of the first stage: its decisions, the first for block 0, well-formed
(Ratpoints.Sieve.DecisionWF), as are the latest decision and the end of the second stage that the
counters of the run were counted under.
There is a decision.
The first decision is for block
0.- decisionWF (d : Decision) : d ∈ corr.decisions → DecisionWF es sp1 d
Every decision is well-formed.
- latest : DecisionWF es sp1 { block := 0, sp2 := corr.sp2, sp3 := corr.sp3 }
The latest decision is well-formed.
The end of the second stage of the counters is one of a well-formed decision.
Instances For
The decision in force for block i among the decisions of a well-formed state of the
correction (Ratpoints.Sieve.findDecision_spec).
The decision in force for a block among the decisions of a well-formed state of the correction is well-formed.
The fold of a block reported with one of the decisions keeps the correction well-formed: the
counters are then counted under the end of the second stage of that decision, and the decision that
the correction may push is well-formed (Ratpoints.Sieve.adaptPrimes_spec).
The fold of a block counts one more block folded and pushes at most a decision, for the blocks
from Ratpoints.adaptLag + 1 blocks later on.
The correction of the run in closed form #
The state of the correction of the moduli after the folds of the first k blocks of the run
(Ratpoints.Sieve.runFold), each with its report in closed form (Ratpoints.Sieve.blockReport),
from the choice (Ratpoints.Sieve.Correction.start, with the ends P.sp2 and P.sp3 and the words
P.adaptAt): what the run keeps while the callback does not stop the search, a function of the
arguments of the run that depends neither on the callback nor on the flags of the output, for the
height H, the options s, the result P of the choice, the sieve entries entries with the
reciprocals magics of their moduli, the classes cls, the word db of the classes that admit a
numerator, the shape shape, the bounds iv of the search intervals and the denominators from
bLow to bHigh.
Equations
- One or more equations did not get rendered due to their size.
- Ratpoints.Sieve.correctionAfter H s P entries magics cls db shape iv bLow bHigh 0 = Ratpoints.Sieve.Correction.start P.sp2 P.sp3 P.adaptAt
Instances For
The decision of the correction of the moduli in force for block i of the run
(Ratpoints.Sieve.findDecision), among the decisions after the folds of the blocks before it
(Ratpoints.Sieve.correctionAfter), which depends neither on the callback nor on the flags of the
output.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The blocks folded so far.
The decisions after the folds of the first k blocks are those after the first m ≤ k
followed by decisions for the blocks from m + Ratpoints.adaptLag + 1 on.
There is a decision, and the first is for block 0.
The state of the correction of the moduli after the folds of the first k blocks of the run is
well-formed, for a well-formed decision of the choice.
The decision in force for a block: the lag #
The index of the decision in force for block i among decisions of which the first is for
block 0 is also that among these decisions followed by decisions for blocks after block i: the
decision in force is unique (Ratpoints.Sieve.Decision.InForce.unique).
The decision in force for block i among decisions of which the first is for block 0 is
also that among these decisions followed by decisions for blocks after block i.
The lag of the correction of the moduli: the decision in force for block i among the decisions
after the folds of the first k blocks is the decision of block i
(Ratpoints.Sieve.blockDecision) for every k ≥ i - Ratpoints.adaptLag, since a decision made at
the fold of block j is for the blocks from j + Ratpoints.adaptLag + 1 on: block i reads only
the decisions made at the folds of the blocks before block i - Ratpoints.adaptLag.
The run #
The points that block i of the run delivers, for the polynomial of degree d with the
coefficient list c, the height H, the flags fl and the words x.1 of the classes and the
ranges x.2 of the numerators of Ratpoints.Sieve.RunWords: those of its denominators
(Ratpoints.Sieve.blockDens) that pass the tests of the shape, in order, each with the first sp3
sieve entries of the decision of the block (Ratpoints.Sieve.blockDecision,
Ratpoints.Sieve.denPoints).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the loop of Ratpoints.Sieve.sieveRun over the blocks, whose state is the
correction, the delivery and the store of the tables of rows, from the delivery r0: the delivery
is that of the points of the blocks done (Ratpoints.Sieve.blockPoints), for every choice of the
words of the classes and the ranges of the numerators of Ratpoints.Sieve.RunWords; while the
callback has not stopped the search, the correction is that after the folds of the blocks done in
closed form (Ratpoints.Sieve.correctionAfter) and the store fits all the entries; and the callback
has not stopped the search before the loop is done.
Equations
- One or more equations did not get rendered due to their size.
Instances For
What the block at the cursor cur needs.
The block at the cursor cur after which the callback stops the search.
The block at the cursor cur after which the callback has not stopped the search.
At the end of the loop, the points of all the blocks.
The contract of the run over the blocks with the correction of the moduli, the block lemma: for
sieve entries with what the run needs of them (Ratpoints.Sieve.IsRunEntries), the word db whose
bits mark the classes cls with a pattern, a well-formed decision of the choice
(Ratpoints.Sieve.DecisionWF), forbidden divisors of the word shape that have what its loop needs,
pieces of at least one bit array, the denominators from bLow ≥ 1 to bHigh < 2 ^ 63 and the
height below 2 ^ 63, the run, with a delivery whose flag of the stop is clear and a store of the
tables of rows that fits all the entries, delivers the points of its blocks in order
(Ratpoints.Sieve.blockPoints), each a function of the block and of its decision
(Ratpoints.Sieve.blockDecision), which depends neither on the callback nor on the flags of the
output, for every choice of the words of the classes and the ranges of the numerators of
Ratpoints.Sieve.RunWords.
Ratpoints.Sieve.sieveRun_spec as a plain statement.
The contract of the run over the blocks with the correction of the moduli, per denominator: for
sieve entries with what the run needs of them (Ratpoints.Sieve.IsRunEntries), the word db whose
bits mark the classes cls with a pattern, a store of the tables of rows that fits all the entries,
a first decision of the parameters that is well-formed (Ratpoints.Sieve.DecisionWF), forbidden
divisors of the word shape that have what its loop needs (Ratpoints.Sieve.Shape.ForbFits), a
listing of the shape with no denominator twice, so that each lies in one block
(Ratpoints.Sieve.Shape.eq_of_mem_blockDens), pieces of at least one bit array, the denominators
from bLow ≥ 1 to bHigh < 2 ^ 63 and the height below 2 ^ 63, there is a number sp3At b of
the entries of the first three stages for each denominator b, the end of the third stage of the
decision of its block (Ratpoints.Sieve.blockDecision), which depends neither on the callback nor
on the flags of the output, such that the run, with any callback, flags and delivery whose flag of
the stop is clear, delivers for each denominator b of the listing of the shape that passes its
tests (Ratpoints.Sieve.Shape.dens, Ratpoints.Sieve.Shape.keep), in order, the points of the
check with the flags of the numerators -H, …, H in one of the ranges rs b that the bounds of the
search intervals give for b (Ratpoints.Sieve.RangesFor), that pass the class word nb[b mod 64]
for words nb that the classes pack, and survive the first sp3At b entries: the blocks in order
(Ratpoints.Sieve.sieveRun_spec) visit the denominators of the listing in its order
(Ratpoints.Sieve.Shape.flatMap_filter_blockDens).
The threads #
The calling thread of a run whose blocks are sifted by threads, which the model leaves out with
the threads: the slots slot i of the blocks i < n, the points that each block delivered to the
appending callback (Ratpoints.appendPoint), delivered to the callback process on the delivery
r in the order of the blocks, the loop ending when the callback has stopped the search.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the loop of Ratpoints.Sieve.deliverSlots, whose state is the delivery, from
the delivery r0: that of the points of the slots done, and the callback has not stopped the search
before the loop is done.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The slot at the cursor cur after which the callback stops the search.
The slot at the cursor cur after which the callback has not stopped the search.
The calling thread delivers the points of the slots in the order of the blocks.
Block i of the run, sifted with the decisions after the folds of the first k blocks, for
k ≥ i - Ratpoints.adaptLag, with a store of its own that fits all the entries, delivers to the
appending callback (Ratpoints.appendPoint) from an empty array the points of the block with its
decision (Ratpoints.Sieve.blockPoints): the contract of one block
(Ratpoints.Sieve.runBlock_spec) and the lag of the correction
(Ratpoints.Sieve.getElem!_findDecision_correctionAfter); the step of
Ratpoints.Sieve.run_deliverSlots_eq_fst_run_sieveRun.
The threads preserve the output of the run: the blocks of the run, each sifted with the
decisions after the folds of the first k i ≥ i - Ratpoints.adaptLag blocks and a store of its own
that fits all the entries, into a slot by the appending callback, their slots delivered in the order
of the blocks by the calling thread (Ratpoints.Sieve.deliverSlots), give what the run on the
calling thread gives (Ratpoints.Sieve.sieveRun), for the hypotheses of
Ratpoints.Sieve.sieveRun_spec and words of the classes and ranges of the numerators of
Ratpoints.Sieve.RunWords. The pool of threads of the C code meets these hypotheses: a thread
starts block i only once the blocks before block i - RP_ADAPT_LAG are folded
(find_points.c:4292-4296), and the tables of rows that the threads share only gain complete rows,
published once built (init.c:180, init.c:241, init.c:391, init.c:443), so that they fit all
the entries whenever a thread reads them (find_points.c:3160, find_points.c:3533-3535).