The counters of the scan of a piece #
The counts that 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, add to
the counters of the sieving thread (Ratpoints.Sieve.Counters), as contracts proved with vcgen,
the program logic of Lean core, with loop invariants that are named definitions. When the callback
does not stop the search, each component adds closed forms that depend neither on the callback nor
on the delivery: the counts of the tests of a candidate (Ratpoints.Sieve.testedCounts) of the
numerators that the contracts of Ratpoints.Proof.Scan deliver the points of, and, for the scan of
a piece, the number of its bit arrays that are not zero; so the counters, from which the search of
ratpoints corrects its moduli between the blocks, do not depend on the callback, the flags of the
output or the store of the tables of rows.
Main definitions #
Ratpoints.Sieve.WalkCountsInvariant,Ratpoints.Sieve.SiftBitArrayCounts,Ratpoints.Sieve.ScanPieceCounts: the counters of the walk through a word, of the loops of the extraction of one bit array and of the scan of a piece.
Main statements #
Ratpoints.Sieve.walkWord_counters_spec: the walk through the set bits of a word adds the counts of the tests of the numerators of its set bits.Ratpoints.Sieve.siftBitArrayByWords_counters_spec,Ratpoints.Sieve.siftBitArrayWhole_counters_spec,Ratpoints.Sieve.siftBitArray_counters_spec: in either arm of the second stage, one bit array adds the counts of the tests of the numerators of the set bits of its words and-ed with the rows of the moduli of the second stage.Ratpoints.Sieve.scanPiece_counters_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 adds the number of its bit arrays that are not zero and the counts of the tests of the numerators of its bits that passkeep.Ratpoints.Sieve.isZeroAt_eq_not_any: a bit array whose bits are a test of the bits is zero exactly when none of its bits passes the test.
Implementation notes #
The file uses Lean core and Std only, as Ratpoints.Proof.Scan does. The contracts of the
counters are apart from those of the delivery, which vcgen uses for the calls of the components:
the proofs of the counters name the contracts of the counters of the components they call. Their
loop invariants hold the counters before a return, which comes only at a stop; the counts of the
tests of a candidate are irreducible, so that the verification conditions are closed by the lemmas
of their lists. The contracts of the counters of the pieces, of the bits of one interval and of the
sieve of one denominator are in Ratpoints.Proof.SiftBits and Ratpoints.Proof.Sift.
The counters of the walk #
The property of the counters c of a walk through the set bits of the word x0, lowest first,
bit t standing for the numerator a0 + step t, from the counters cnt0, after the set bits below
k: they are cnt0 plus the counts of the tests of a candidate of the numerators of the set bits
t < k of x0, over the denominator b with the thunk checks of the third stage
(Ratpoints.Sieve.testedCounts).
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 for its counters, whose state is
the value of a return, the word, the delivery and the counters: before a return,
Ratpoints.Sieve.WalkWhileInvariant for Ratpoints.Sieve.WalkCountsInvariant; the return comes at
a stop, with the flag of the delivery returned set.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A step of the walk, at the lowest set bit of x, whose numerator the test of a candidate counts
after the count in bits.
At the exit of the walk, the counters are those of the tests of the numerators of all the set
bits of x0.
When the callback does not stop the search, the walk through the set bits of a word adds to the
counters the counts of the tests of a candidate of the numerators a0 + step t of its set bits t
(Ratpoints.Sieve.testedCounts); the test of a candidate is read as its value.
The counters of one bit array #
The property of the counters c of the loops of the two arms of Ratpoints.Sieve.siftBitArray
over the words words κ of the bit array with the word number i, in the packing of the class
cl, from the counters cnt0, after its first k words: they are cnt0 plus the counts of the
tests of a candidate (Ratpoints.Sieve.testedCounts) of the numerators of the bit numbers
rbaLength i + 64 κ + t of the set bits t of the words κ < k (Ratpoints.Sieve.bitNumbers),
over the denominator b with the thunk checks of the third stage.
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] for its
counters, whose state is the value of a return, the delivery and the counters:
Ratpoints.Sieve.SiftBitArrayCounts after the words done before a return; the return comes at a
stop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ratpoints.Sieve.flatMap_numerator_bitNumbers_succ for the numerators themselves: 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, as the walk through it computes them.
The walk through word k from its first numerator adds the counts of its numerators.
The walk through word cur of the loop over [0:rbaPack], when the callback does not stop the
search in it, in the shape of the verification condition.
A word that is zero adds nothing.
The counters of the numerators of the set bits of words that agree.
After all the words of the bit array, the counters are those of their numerators.
At the end of the loop over [0:rbaPack], the counters are those of the numerators of all the
words of the bit array.
When the callback does not stop the search, the arm for one word at a time adds to the counters
the counts of the tests of a candidate of the numerators of the set bits of the words of nums
and-ed with the rows of the moduli of specs.
Ratpoints.Sieve.SiftBitArrayCounts 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: the
invariant of the counters of the loop over the words after the first in
Ratpoints.Sieve.siftBitArrayWhole.
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] for its
counters, whose state is the value of a return, the delivery, the counters and the numerator of bit
0 of the word: Ratpoints.Sieve.SiftBitArrayWalkCounts after the words done before a return; the
return comes at a stop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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 counters
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.
At the end of the loop over [1:rbaPack], the counters are those of the numerators of all the
words of the bit array.
When the second stage leaves the bit array zero, the words walked through have no set bits, and nothing is counted.
When the callback does not stop the search, the arm of the second stage on the whole bit array
adds to the counters the counts of the tests of a candidate of the numerators of the set bits of the
words of nums and-ed with the rows of the moduli of specs, nothing when the second stage leaves
the bit array zero.
Both arms add to the counters the counts of the tests of a candidate 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_counters_spec,
Ratpoints.Sieve.siftBitArrayWhole_counters_spec), when the callback does not stop the search.
The counters of the scan of a piece #
The property of the counters c 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 and the moduli specs
of the second stage with their rows, from the counters cnt0: pos ≤ n, and c is cnt0 plus the
number of the bit arrays before pos that are not zero, in arrays, plus the counts of the tests
of a candidate (Ratpoints.Sieve.testedCounts), over the denominator b with the thunk checks of
the third stage, of the numerators in the packing of the class cl 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).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ratpoints.Sieve.ScanPieceCounts as the invariant of the counters of the scan of
Ratpoints.Sieve.scanPiece, whose state is the value of a return, the position, the delivery and
the counters, with all n bit arrays done at the exit; the return comes at a stop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the counters of the loop of Ratpoints.Sieve.scanPiece that steps over the bit
arrays that are zero, from bit array pos0 on, with the counters c of the bit arrays before
pos0: the position is at least pos0, and Ratpoints.Sieve.ScanPieceCounts holds there with
c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Bit array pos, which is not zero, copied and passed through
Ratpoints.Sieve.siftBitArray with its word number w0 + pos after the count arrays one up, when
the callback does not stop the search in it.
At the end of the scan, the counters are those of the bit arrays of the piece that are not zero
and of the numerators of the set bits of its words 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 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. When the callback does not stop the search, the scan adds to the counters the
number of the bit arrays of the piece that are not zero, in arrays, and the counts of the tests
of a candidate (Ratpoints.Sieve.testedCounts) of the numerators of its bits that pass keep, the
bits of the piece and-ed with the rows of the second stage.
A bit array of the words v, among the first n, whose bits are a test keep of the bits
rbaLength w0 + 64 y + t of the set bits t < 64 of the words y, for the number rbaLength of
bits of a bit array (Ratpoints.rbaLength), is zero exactly when none of its bits passes keep.