The contracts of the scan of a piece #
The contracts of the components of the model on words from the walk through the set bits of a word
on, through the second stage and the extraction of one bit array, up to the scan of a piece, as
@[spec] theorems proved with vcgen, the program logic of Lean core, with loop invariants that
are named definitions. Each component hands the points it finds to the callback of the caller on a
delivery (Ratpoints.Delivery), whose flag of the stop is clear at the start, and returns as soon
as a call sets it; its contract says that the delivery it returns is the reference of the delivery
(Ratpoints.Delivery.deliver) of the list of the points it finds, which passes over the points
after the stop. The contracts speak of the bits j of the packing of a class cl
(Ratpoints.Sieve.NumClass), each standing for the numerator a₀ + 2 ^ k j
(Ratpoints.Sieve.NumClass.numerator), and of the words of the bit arrays and-ed with the rows of
the moduli of the second stage at their offsets (Ratpoints.Sieve.andWords); the points of a
numerator are those that the exact check delivers with the flags of the search
(Ratpoints.Sieve.acceptedPoints).
Main definitions #
Ratpoints.Sieve.WalkDeliveryInvariant,Ratpoints.Sieve.SiftBitArrayInvariant,Ratpoints.Sieve.ScanPieceInvariant: the deliveries of the walk through a word, of the loops of the extraction of one bit array and of the scan of a piece, before a stop.
Main statements #
Ratpoints.Sieve.walkWord_spec: the walk through the set bits of a word delivers the points of the numeratorsa0 + step tof its set bitst, in increasing order.Ratpoints.Sieve.siftBitArrayByWords_spec,Ratpoints.Sieve.siftBitArrayWhole_spec,Ratpoints.Sieve.siftBitArray_spec: in either arm of the second stage, one bit array delivers the points of the numerators of the set bits of its words and-ed with the rows of the moduli of the second stage, in increasing order.Ratpoints.Sieve.scanPiece_spec: if the bits of a piece and-ed with the rows of the second stage are a testkeepof the bits, the scan of the piece delivers the points of the numerators of its bits that passkeep, in increasing order.
Implementation notes #
The file uses Lean core and Std only, as Ratpoints.Proof.Stages, Ratpoints.Proof.Packing and
Ratpoints.Proof.Delivery do. The walk reads the test of a candidate as its value
(Ratpoints.Sieve.acceptedPoints), so that the contracts need nothing of the numerators and the
denominator. The loops return at a stop: their invariants hold the delivery of the points found so
far with the flag clear before a return, and the value returned after it, the delivery of all the
points, since the reference passes over the points after the first call that sets the flag
(Ratpoints.Delivery.deliver_eq_of_prefix); their verification conditions are closed by lemmas in
their shape. The contracts of the counters of these components are in Ratpoints.Proof.ScanCounts;
those of the pieces and of the bits of one interval are in Ratpoints.Proof.SiftBits, and that of
the sieve of one denominator in Ratpoints.Proof.Sift.
The walk through the set bits of a word #
The property of the delivery r of a walk through the set bits of the word x0, lowest first,
bit t standing for the numerator a0 + step t, that delivers the list g a of the numerator a
of each set bit from the delivery r0, after the set bits below k: the callback has not stopped
the search, and r is the delivery of the lists of the numerators of the set bits t < k of x0,
in increasing order. In Ratpoints.Sieve.walkWord, g a is the list of the points that
Ratpoints.Sieve.acceptedPoints gives for the numerator a.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the while loop of Ratpoints.Sieve.walkWord, whose state is the value of a
return, the word and the delivery: before a return, Ratpoints.Sieve.WalkWhileInvariant for
Ratpoints.Sieve.WalkDeliveryInvariant; after the return at a stop, the value returned is the
delivery of the lists of the numerators of all the set bits of x0, since those after the stop are
passed over.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The step of the walk at the lowest set bit of x, which has the bits of x0 below k
cleared.
A step of the walk at which the callback does not stop the search.
The step of the walk at which the callback stops the search: the delivery is that of the lists of the numerators of all the set bits, since the bits after the stop are passed over.
The exit of the walk, when the word is 0.
At the exit of the walk, the delivery is that of the lists of the numerators of all the set bits
of x0.
A step of the walk at a numerator that passes the test of a candidate and whose exact check does not stop the search.
A step of the walk at a numerator that does not pass the test of a candidate.
The step of the walk at a numerator that passes the test of a candidate and whose exact check stops the search.
The loop ends, since clearing the lowest set bit makes a word other than 0 smaller, or at a
stop; the test of a candidate is read as its value, Ratpoints.Sieve.acceptedPoints.
The second stage and the extraction of one bit array #
The invariant of the loops of the two arms of Ratpoints.Sieve.siftBitArray over the words of
the bit array with the word number i, after its first k words, for the words words κ that the
walks go through, the class cl and the points g a of a numerator a, from the delivery r0:
the callback has not stopped the search, and r is the delivery of the points of the numerators of
the bit numbers rbaLength i + 64 κ + t of the set bits t of the words κ < k
(Ratpoints.Sieve.bitNumbers) in the packing of cl (Ratpoints.Sieve.NumClass.numerator), in
increasing order. The invariant of the scan of a piece (Ratpoints.Sieve.ScanPieceInvariant) is
this one for the words of the piece from its first word number on.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ratpoints.Sieve.SiftBitArrayInvariant after the words 0, …, k, with the numerator a0 of
bit 0 of word k, a₀ + i (rbaLength 2 ^ cl.k) + k (64 2 ^ cl.k) as the program computes it,
for the stride 2 ^ cl.k of the class: the invariant of the loop over the words after the first in
the arm of the second stage on the whole bit array (Ratpoints.Sieve.siftBitArrayWhole), which
steps a0 from one word to the next before it walks through the word, as the C code does.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the loop of Ratpoints.Sieve.siftBitArrayByWords over [0:rbaPack], whose
state is the value of a return and the delivery: before a return,
Ratpoints.Sieve.SiftBitArrayInvariant after the words done; after the return at a stop, the value
returned is the delivery of the points of the numerators of the set bits of all the words of the
bit array.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the loop of Ratpoints.Sieve.siftBitArrayWhole over [1:rbaPack], whose state
is the value of a return, the delivery and the numerator of bit 0 of the word:
Ratpoints.Sieve.SiftBitArrayWalkInvariant after the words done before a return, and after the
return at a stop the delivery of the points of the numerators of the set bits of all the words of
the bit array as the value returned.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The points of the numerators of the bit numbers of the set bits of the words 0, …, k are
those of the words 0, …, k - 1 followed by those of word k, whose numerators the walk through
it computes from the numerator a₀ + i (rbaLength 2 ^ cl.k) + k (64 2 ^ cl.k) of its bit 0.
The delivery of the list D of the points that follow those of the bit numbers of the words
before k among those of the words before k', when the callback does not stop the search in
it.
The delivery of the list D of the points that follow those of the bit numbers of the words
before k among those of the words before k', when the callback stops the search in it: the
delivery is that of the points of the words before any m ≥ k', since the points after the stop
are passed over.
The walk through word k from its first numerator, when the callback does not stop the
search in it.
The walk through word cur of the loop over [0:rbaPack], when the callback does not stop the
search in it.
A word that is zero adds nothing.
The walk through word cur of the loop over [0:rbaPack], when the callback stops the search
in it: the delivery is that of all the words of the bit array.
At the end of the loop over [0:rbaPack], the delivery is that of all the words of the bit
array.
The walk through the first word, from the first numerator a₀ + i (rbaLength 2 ^ cl.k) of the
bit array, when the callback does not stop the search in it, starts the invariant of the loop over
the other words.
The step 64 2 ^ cl.k to the first numerator of word cur of the loop over [1:rbaPack], and
the walk through it from there, when the callback does not stop the search in it.
The walk through word cur of the loop over [1:rbaPack], when the callback stops the search
in it: the delivery is that of all the words of the bit array.
At the end of the loop over [1:rbaPack], the delivery is that of all the words of the bit
array.
The walk through the first word of words that agree with words', from the first numerator
a₀ + i (rbaLength 2 ^ cl.k) of the bit array, when the callback stops the search in it: the
delivery is that of all the words of words'.
The words of a bit array that the second stage leaves zero have no set bits: nothing is delivered.
The arm for one word at a time walks through the set bits of the words of nums and-ed with the
rows of the moduli of specs (Ratpoints.Sieve.secondStageWord_spec), each bit j standing for
the numerator a₀ + 2 ^ k j of the class cl, and skips a word that is zero, which loses nothing;
it returns at a stop.
The arm of the second stage on the whole bit array walks through the set bits of the words of
nums and-ed with the rows of the moduli of specs (Ratpoints.Sieve.secondStage_spec), each bit
j standing for the numerator a₀ + 2 ^ k j of the class cl, and skips the walks when the second
stage leaves the bit array zero, which loses nothing; it returns at a stop.
Both arms deliver the points of the numerators of the set bits of the same words, the words of
nums and-ed with the rows of the moduli of specs
(Ratpoints.Sieve.siftBitArrayByWords_spec, Ratpoints.Sieve.siftBitArrayWhole_spec).
The scan of a piece #
The invariant of the loop of Ratpoints.Sieve.scanPiece that writes the sentinel into bit
array n of surv: the words of the piece are those of surv, and the first k words of bit
array n are all ones.
Equations
Instances For
The invariant of the scan of Ratpoints.Sieve.scanPiece at bit array pos of the words sv,
for a piece of n bit arrays from the word number w0 on, the moduli specs of the second stage
with their rows and the points g a of the numerator a of a bit in the packing of the class cl
(in the scan, those of Ratpoints.Sieve.acceptedPoints), from the delivery r0: pos ≤ n, the
callback has not stopped the search, and r is the delivery of the points of the bits
rbaLength w0 + 64 y + t of the set bits t of the words y < rbaPack pos and-ed with the rows of
specs (Ratpoints.Sieve.andWords), in increasing order: the invariant of the extraction of one
bit array (Ratpoints.Sieve.SiftBitArrayInvariant) for the words of the piece from w0 on.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ratpoints.Sieve.ScanPieceInvariant as the invariant of the scan of
Ratpoints.Sieve.scanPiece, whose state is the value of a return, the position and the delivery,
with all n bit arrays done at the exit; after the return at a stop, the value returned is the
delivery of the points of all the bit arrays of the piece.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the loop of Ratpoints.Sieve.scanPiece that steps over the bit arrays that are
zero, from bit array pos0 on, with the delivery r of the bit arrays before pos0: the position
is at least pos0, and Ratpoints.Sieve.ScanPieceInvariant holds there with r, since a bit array
that is zero has no set bits.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A bit array that is zero is not the sentinel, whose words are all ones.
The bit numbers of the set bits of the words of a piece before the sentinel are those of the
words of surv, since the sentinel was written past them.
The bit arrays of a piece before the sentinel are those of surv, since the sentinel was
written past them.
The bit numbers of the set bits of the first pos + 1 bit arrays of a piece are those of the
first pos followed by those of bit array pos, copied and passed through
Ratpoints.Sieve.siftBitArray with its word number w0 + pos.
Bit array pos, copied and passed through Ratpoints.Sieve.siftBitArray with its word number
w0 + pos, when the callback does not stop the search in it.
Bit array pos, copied and passed through Ratpoints.Sieve.siftBitArray with its word number
w0 + pos, when the callback stops the search in it: the delivery is that of the whole piece.
A bit array that is zero adds nothing; it is not the sentinel, so that the measure n - pos of
the loop that steps over the bit arrays that are zero decreases.
The value returned at a stop in the scan, the delivery of the points of the bits of the words
before the sentinel, is the delivery of those of the words of surv.
At the end of the scan, the delivery is that of the points of the set bits of the words of the
piece and-ed with the rows, which are those of surv, since the sentinel was written past them.
The loop over the zero bit arrays ends at the sentinel at the latest, so that both loops of the
scan end by the measure n - pos; the test keep is quantified in the postcondition, since the
program does not mention it.