The rows built into the tables of a run #
The tables of rows of a run (Ratpoints.Sieve.RowStore) as the builders change them: the table of
an entry after a row is stored into it (Ratpoints.Sieve.RowStore.getD_publish), which keeps the
size of every table (Ratpoints.Sieve.RowStore.size_getD_publish), and the rows of the store after
it, the row at its place and the others as they were (Ratpoints.Sieve.RowStore.row?_publish); a
store that grows by rows satisfying a predicate, keeping its tables of rows with their sizes and its
rows (Ratpoints.Sieve.RowStore.Grows); and the contracts of the calls of the builders through the
tables of rows, as @[spec] theorems: the call through the function pointer of the entry of a
factor (Ratpoints.Sieve.initFactorRow_spec), the rows of the factors of a product read from the
tables of rows of their entries or built into them (Ratpoints.Sieve.factorRows_spec), the rows of
a product (Ratpoints.Sieve.sieveInitProduct_spec), the row of a sieve entry built by its builder
(Ratpoints.Sieve.SieveEntry.initRow_spec) and read from its table of rows or built into it
(Ratpoints.Sieve.SieveEntry.fetchRow_spec). Every row that they return or store is a closed form
(Ratpoints.Sieve.closedRow), and no row is replaced.
The invariant of the store of a run: its rows are those of a function R of the reference and the
residue (Ratpoints.Sieve.RowStore.Holds), and the table of rows of every prime factor of the sieve
entries has its row of 0 (Ratpoints.Sieve.StoreHolds), at which the builders of a prime are
wrong; the entries fit R at their positions when their references and the kinds of their builders
are those that Ratpoints.makeModulus sets and the closed forms of the rows of the entries and
their factors are the rows of their references (Ratpoints.Sieve.SieveEntry.RowsFit), and the store
fits the entries when it holds rows that they fit (Ratpoints.Sieve.RowStore.Fits). Every row
fetched keeps the invariant (Ratpoints.Sieve.StoreHolds.of_fetchRow), and the sieve specs that
Ratpoints.Sieve.setRows makes and Ratpoints.Sieve.buildRows completes have the closed forms of
the rows of their entries (Ratpoints.Sieve.buildRows_setRows_map_spec), so that below the set-up
of a denominator nothing reads the store; the store still holds the rows for every list of entries
that contains those whose rows are built. The tables of rows made by the loop of the tables and with
the sieve entries (Ratpoints.Sieve.primeRows, Ratpoints.Sieve.SieveEntry.addTables) keep the
invariant (Ratpoints.Sieve.RowStore.Holds.addTables) and the rows of 0 of the primes
(Ratpoints.Sieve.RowStore.PrimeZeroRows.row?_addTables_ne_none). For a run, R is the function of
the closed forms of the rows of the table of each prime and the tables of each prime power as
Ratpoints.Sieve.examinePrime and Ratpoints.Sieve.examinePower compute them, and of the entries
of the products at their positions (Ratpoints.Sieve.runRows), which every sieve entry made by
Ratpoints.makeModulus fits (Ratpoints.Sieve.SieveEntry.rowsFit_runRows), and which the store
that the loop over the moduli of Ratpoints.sievingInfo makes holds
(Ratpoints.Sieve.RowStore.MadeFor).
Main definitions #
Ratpoints.Sieve.RowStore.Grows: a store grown from another by rows satisfying a predicate.Ratpoints.Sieve.Factor.Buildable,Ratpoints.Sieve.Factor.Builds: what the builder of the rows of a factor needs of its tables, and the residues at which it is called.Ratpoints.Sieve.FactorRow,Ratpoints.Sieve.FactorRowsPre,Ratpoints.Sieve.ProductRowsPre,Ratpoints.Sieve.InitRowPre: the rows that building the rows of the factors of a product adds, and what building the rows of the factors, of a product and of an entry needs.Ratpoints.Sieve.RowStore.Holds,Ratpoints.Sieve.StoreHolds,Ratpoints.Sieve.RowStore.PrimeZeroRows: the rows of a store are those of a function of the reference and the residue, the invariant of the store of a run, and the rows of0of the tables of rows of the primes.Ratpoints.Sieve.SieveEntry.RefFits,Ratpoints.Sieve.SieveEntry.RowsFit: the reference and the kind of the builder of a sieve entry at its position, and what building its rows needs of it.Ratpoints.Sieve.BuildRowsPre,Ratpoints.Sieve.BuildRowsInvariant: what the loop ofRatpoints.Sieve.buildRowsneeds, and its invariant.Ratpoints.Sieve.runRows,Ratpoints.Sieve.RowStore.MadeFor: the rows of the references of a run, and the store as the loop of the tables and the tables of rows of the first entries of a run make it.Ratpoints.Sieve.RowStore.Fits: the store fits the sieve entries, holding rows that they fit at their positions, as the store of a run fits the entries of its first two stages before and after each denominator.
Main statements #
Ratpoints.Sieve.RowStore.getD_publish,Ratpoints.Sieve.RowStore.size_getD_publish: the table of an entry after a row is stored, and its size.Ratpoints.Sieve.RowStore.row?_publish: the rows of the store after a row is stored.Ratpoints.Sieve.initFactorRow_spec,Ratpoints.Sieve.factorRows_spec,Ratpoints.Sieve.sieveInitProduct_spec,Ratpoints.Sieve.SieveEntry.initRow_spec,Ratpoints.Sieve.SieveEntry.fetchRow_spec: the rows built through the tables of rows are closed forms.Ratpoints.Sieve.StoreHolds.fetchRow_pre,Ratpoints.Sieve.StoreHolds.of_fetchRow: a row of an entry that fits can be fetched, and the store still holds after it.Ratpoints.Sieve.buildRows_spec,Ratpoints.Sieve.buildRows_setRows_map_spec: the sieve specs of a denominator have the closed forms of the rows of their entries, and the store still holds the rows for every list of entries that contains them.Ratpoints.Sieve.RowStore.Holds.addTables,Ratpoints.Sieve.RowStore.PrimeZeroRows.addTables: the tables of rows of a sieve entry keep the invariant of the store.Ratpoints.Sieve.SieveEntry.rowsFit_runRows: a sieve entry asRatpoints.makeModulusmakes it fits the rows of the references of the run.Ratpoints.Sieve.RowStore.madeFor_nil,Ratpoints.Sieve.RowStore.MadeFor.addTables,Ratpoints.Sieve.RowStore.MadeFor.foldl_addTables,Ratpoints.Sieve.RowStore.MadeFor.storeHolds: the store of the loop over the moduli ofRatpoints.sievingInfoholds the rows of the references of the run.Ratpoints.Sieve.StoreHolds.of_factors,Ratpoints.Sieve.SieveEntry.RowsFit.of_eq,Ratpoints.Sieve.rowsFit_take,Ratpoints.Sieve.RowStore.Fits.take,Ratpoints.Sieve.RowStore.Fits.map_dinv: the invariant and the fit carry over to the first entries, those of the first two stages, and to the entries with the inverses of the strides.Ratpoints.Sieve.RowStore.Fits.buildRows_setRows: the sieve specs of a denominator have the closed forms of the rows of their entries, and the store after them still fits the entries.Ratpoints.Sieve.StoreHolds.buildRows_setRows_take: a store that holds the rows for all the entries of a run still holds them after the rows of the first entries are built.
Implementation notes #
The file uses Lean core and Std only, as the contracts of the sieve do.
The tables of rows #
The store s' keeps the tables of rows of s with their sizes and their rows, and its other
rows, the row row at the residue r of the table of rows ref, satisfy P ref r row: what
building rows into the tables of rows does to the store.
The tables of rows keep their sizes.
- row?_of_row? (ref : EntryRef) (r : Nat) (row : Array UInt64) : s.row? ref r = some row → s'.row? ref r = some row
The rows are kept.
- row?_or (ref : EntryRef) (r : Nat) (row : Array UInt64) : s'.row? ref r = some row → s.row? ref r = some row ∨ P ref r row
The other rows satisfy
P.
Instances For
The builder of the entry of a factor #
What the builder of the rows of a factor needs of its tables: a positive modulus; for a prime
p the inverses of its residues below p, and p mod 64 ≠ 0 for a prime of at least 64, whose
builder CODE_INIT_SIEVE2 shifts by p mod 64; for a prime power m at most
64 Ratpoints.modWords and its inverses below m.
Equations
Instances For
The residues at which the builder of the rows of a factor is called: below the modulus, and
other than 0 for a prime, whose row of 0 is in its table of rows from the start
(Ratpoints.Sieve.primeRows), the builders of a prime being wrong at 0.
Equations
Instances For
The row of the residue b built by the builder of the kind of the factor f, the call through
the function pointer of the entry of the factor, is the closed form of the row of b of the factor,
for the residues at which it is called (Ratpoints.Sieve.Factor.Builds), and the builder stores it
into the table of rows ref.
The rows of the factors of a product #
A row that building the rows of the factors of e adds to the store: at the residue r of the
table of rows ref, the closed form of the row of r of a factor of e whose entry is ref.
Equations
Instances For
What building the rows of the factors of e needs of them and of the store: their builders have
what they need, the rows in the tables of rows of their entries are closed forms, a row that is
absent below the modulus is one at which the builder of the factor may be called (for a prime, its
row of 0 is in its table of rows), and two factors with one entry have the same closed forms of
their rows.
The builders of the factors have what they need.
- rows (f : Factor) : f ∈ e.factors → ∀ (r : Nat) (row : Array UInt64), store.row? f.ref r = some row → row = closedRow f.admits f.modulus r
The rows in the tables of rows of the entries of the factors are closed forms.
- builds (f : Factor) : f ∈ e.factors → ∀ (r : Nat), r < f.modulus → store.row? f.ref r = none → f.Builds r
A row absent below the modulus is one that the builder of the factor may build.
- coherent (f : Factor) : f ∈ e.factors → ∀ (f' : Factor), f' ∈ e.factors → f.ref = f'.ref → closedRow f.admits f.modulus = closedRow f'.admits f'.modulus
Two factors with one entry have the same closed forms of their rows.
Instances For
The invariant of the loop of Ratpoints.Sieve.factorRows over the factors pref done, on the
store and the rows: the rows of those factors in closed form at the residues of b, and the store
grown by rows of factors.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A row of a factor of e present in a store grown from one where they were closed forms is the
closed form of the factor: rows are never replaced, and two factors with one entry have the same
closed forms of their rows.
A factor whose row is in the store.
A factor whose row the builder of its entry builds into the store.
The builder of the entry of a factor is called at a residue at which it may be.
The rows of the factors of e at the residues of b modulo their moduli, read from the tables
of rows of their entries or built into them, are their closed forms, and the store grows by rows of
factors (Ratpoints.Sieve.FactorRow), never replacing one.
The rows of a product #
What building the row of a product e needs: what building the rows of its factors needs
(Ratpoints.Sieve.FactorRowsPre), a positive modulus, at least one factor, and the moduli of the
factors dividing the modulus.
- factorRows : FactorRowsPre e store
What building the rows of the factors needs.
The modulus is positive.
The product has a factor.
The moduli of the factors divide the modulus.
Instances For
A copy of bit array cur of the row of a product after its first m bit arrays.
The row of the product built from the closed forms of the rows of its factors is the closed form of its row, and so is what the builder stores, into the store grown by the rows of the factors.
The row of the residue b of the product e, of a modulus m > 0 that the positive moduli of
its factors divide, as _ratpoints_sieve_init_product builds it, is the closed form of the row of
b of the product, and the builder stores it into the table of rows of the entry of the product,
in the store grown by the rows of the factors that it builds into their tables of rows first
(Ratpoints.Sieve.factorRows_spec).
The rows of the entries of a run #
What building the row of the residue b of the sieve entry e by its builder needs: for a
product, what building its row needs (Ratpoints.Sieve.ProductRowsPre); for a prime or a prime
power, its one factor f, whose modulus, entry and kind are those of e, with a builder that has
what it needs, called at a residue at which it may be.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The row of the residue b of the sieve entry e built by its builder is the closed form of the
row of b of the entry, stored into the table of rows of the entry, in the store grown by the rows
of the factors of a product.
The row of the residue b of the sieve entry e from the table of rows of its entry, read
there when it is present, a closed form, or built by the builder of the entry: the closed form of
the row of b of the entry, and the store as it was or grown by the rows of the factors of a
product with the row stored into the table of rows of the entry.
The tables of rows of a run #
The rows of the store s are those of R, a row for each reference and residue: every row
present at the residue r of the table of rows of ref is R ref r.
Equations
- Ratpoints.Sieve.RowStore.Holds R s = ∀ (ref : Ratpoints.Sieve.EntryRef) (r : Nat) (row : Array UInt64), s.row? ref r = some row → row = R ref r
Instances For
The store s of a run holds the rows R of the references (Ratpoints.Sieve.RowStore.Holds),
and the table of rows of every prime factor of the sieve entries es has its row of 0
(Ratpoints.Sieve.primeRows), at which the builders of a prime are wrong: what building the rows
of the entries needs of the store, beside what it needs of each entry
(Ratpoints.Sieve.SieveEntry.RowsFit).
- holds : RowStore.Holds R s
The rows of the store are those of
R. - zero (e : SieveEntry) : e ∈ es → ∀ (t : Entry), Factor.prime t ∈ e.factors → s.row? (EntryRef.prime t.p) 0 ≠ none
The table of rows of every prime factor has its row of
0.
Instances For
The sieve entry e at the position n of the moduli holds the reference to its table of rows
and the kind of its builder as Ratpoints.makeModulus sets them
(Ratpoints.Sieve.SieveEntry.refInit): for one factor, the modulus, the reference and the kind of
the factor; otherwise the product's own table of rows, by its position, and the builder of the rows
of a product.
Equations
Instances For
A sieve entry whose reference and kind of builder are those that
Ratpoints.Sieve.SieveEntry.refInit gives at the position n, as Ratpoints.makeModulus sets
them, and whose modulus is that of its factor when it has one, fits them.
What building the rows of the sieve entry e at the position n of the moduli needs of it, for
the rows R of the references (Ratpoints.Sieve.RowStore.Holds): its reference and kind
(Ratpoints.Sieve.SieveEntry.RefFits), a positive modulus, at least one factor, the moduli of the
factors dividing the modulus, builders of the factors that have what they need
(Ratpoints.Sieve.Factor.Buildable), and the rows of its reference and of the references of its
factors the closed forms of their rows (Ratpoints.Sieve.closedRow).
- refFits : e.RefFits n
The reference and the kind of the builder are those that
Ratpoints.makeModulussets. The modulus is positive.
The entry has a factor.
The moduli of the factors divide the modulus.
The builders of the factors have what they need.
The rows of the reference are the closed forms of the rows of the entry.
The rows of the reference of each factor are the closed forms of the rows of the factor.
Instances For
A row absent below the modulus of a factor of an entry is one at which the builder of the factor
may be called (Ratpoints.Sieve.Factor.Builds): for a prime, its row of 0 is present.
What building the rows of the factors of an entry needs (Ratpoints.Sieve.FactorRowsPre).
What building the row of the residue b < p of an entry needs (Ratpoints.Sieve.InitRowPre),
when the row is absent: for a prime, b ≠ 0, since its row of 0 is present.
The precondition of Ratpoints.Sieve.SieveEntry.fetchRow_spec for the residue b < p of an
entry.
The store after a row of an entry is fetched (Ratpoints.Sieve.SieveEntry.fetchRow_spec) still
holds.
The making of the tables of rows #
Every table of rows of a prime in the store has its row of 0, as the loop of the tables and
the sieve entries make the tables of rows of the primes (Ratpoints.Sieve.primeRows).
Equations
- s.PrimeZeroRows = ∀ (p : Nat), Ratpoints.Sieve.EntryRef.prime p ∈ s → s.row? (Ratpoints.Sieve.EntryRef.prime p) 0 ≠ none
Instances For
The table of rows of the prime p with its row of 0 (Ratpoints.Sieve.primeRows) keeps the
rows of the store those of R when the row of 0 of p is that of R.
A sieve entry whose builder is that of a product has the product's own table of rows.
The store with the tables of rows of a sieve entry holds the rows R of the references when the
store does and the rows of 0 of the primes of the entry are those of R.
The table of rows of a prime factor of a sieve entry has its row of 0 once the tables of rows
of the entry are made, when every table of rows of a prime has it.
The rows of the sieve specs of a denominator #
What building the rows of the sieve specs specs of the entries es at the residues bp
(Ratpoints.Sieve.buildRows) needs: the store holds the rows R for a list L of entries that
contains es, the entries fit them at their positions, the residues are below the moduli, and each
spec has the end p and its row, or none yet, all rows when missing says none is missing.
- holds : StoreHolds R L store
The store holds the rows
Rfor the entriesL. The entries are among
L.The entries fit the rows
Rat their positions.The residues are below the moduli.
A spec for each entry.
The specs have the end
p.- row_eq (n : Nat) : n < specs.length → specs[n]!.row = #[] ∨ specs[n]!.row = closedRow es[n]!.admits es[n]!.p bp[n]!
The specs have their rows or none yet.
- row_eq_of_missing : missing = false → ∀ (n : Nat), n < specs.length → specs[n]!.row = closedRow es[n]!.admits es[n]!.p bp[n]!
The specs have their rows when none is missing.
Instances For
The invariant of the loop of Ratpoints.Sieve.buildRows after the specs below k, on the specs
and the store: the store holds the rows R for the entries L, and each spec has its row and the
end p, or for k ≤ i none yet.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The rows that Ratpoints.Sieve.buildRows builds into the sieve specs of the entries es at the
residues bp, read from the tables of rows or built into them, are the closed forms of the rows of
the entries (Ratpoints.Sieve.closedRow), each with the end p, and the store still holds the rows
R for every list L of entries that contains es and for which it held them.
What building the rows of the sieve specs that Ratpoints.Sieve.setRows makes needs
(Ratpoints.Sieve.BuildRowsPre), for a store that holds the rows R for a list of entries that
contains es, entries that fit them at their positions and residues below the moduli: a row present
in the store is the closed form of the row of its entry.
The sieve specs of the first two stages that Ratpoints.Sieve.setRows makes and
Ratpoints.Sieve.buildRows completes for the residues g e < p of the entries, as the run computes
them (Ratpoints.Sieve.fillBpList_eq_map), have the closed forms of the rows of their entries at
their residues (Ratpoints.Sieve.closedRow), the offsets of the class, the start 0 and the end
p, and the store still holds the rows R for the entries L, for a store that holds them,
entries among L that fit them at their positions and residues below the moduli.
The rows of the references of a run #
The rows of a prime power do not depend on the flag pinf, which only the density reads.
The rows of the references of a run for the polynomial of degree d with the coefficient list
c and the sieve entries es of the moduli in their order: for a prime p, the closed forms of
the rows of its table (Ratpoints.Sieve.examinePrime); for a prime power p ^ e, those of its
tables (Ratpoints.Sieve.examinePower); for a product, those of the entry at its position.
Equations
- Ratpoints.Sieve.runRows c d es (Ratpoints.Sieve.EntryRef.prime p) = Ratpoints.Sieve.closedRow (Ratpoints.Sieve.examinePrime c d p).admits p
- Ratpoints.Sieve.runRows c d es (Ratpoints.Sieve.EntryRef.power p e) = Ratpoints.Sieve.closedRow (Ratpoints.Sieve.examinePower c d p e false false).run.admits (p ^ e)
- Ratpoints.Sieve.runRows c d es (Ratpoints.Sieve.EntryRef.product n) = Ratpoints.Sieve.closedRow es[n]!.admits es[n]!.p
Instances For
The rows of the reference of a factor of a run whose table or tables are those that
Ratpoints.Sieve.examinePrime and Ratpoints.Sieve.examinePower compute are the closed forms of
the rows of the factor.
A sieve entry at the position n of the entries es of a run, with the reference and the kind
that Ratpoints.makeModulus sets, a positive modulus, at least one factor, the moduli of the
factors dividing the modulus, builders that have what they need and the tables that
Ratpoints.Sieve.examinePrime and Ratpoints.Sieve.examinePower compute, fits the rows of the
references of the run (Ratpoints.Sieve.runRows).
The store of a run and its entries #
The store s as the loop of the tables and the tables of the sieve entries es of the first
moduli of a run make it (Ratpoints.choiceEnd): it holds the rows of the references of every run
whose entries begin with es (Ratpoints.Sieve.runRows), every table of rows of a prime in it has
its row of 0, and so has the table of rows of every prime factor of es.
- holds (es' : List SieveEntry) : es <+: es' → Holds (runRows c d es') s
The store holds the rows of the references of every run whose entries begin with
es. - primeZeroRows : s.PrimeZeroRows
Every table of rows of a prime has its row of
0. - zero (e : SieveEntry) : e ∈ es → ∀ (t : Entry), Factor.prime t ∈ e.factors → s.row? (EntryRef.prime t.p) 0 ≠ none
The table of rows of every prime factor of
eshas its row of0.
Instances For
The store of the loop of the tables, which holds the rows of 0 of the primes and no others
(Ratpoints.Sieve.PrimeStore), is made for no entries.
The tables of rows of the next sieve entry e, with the reference and the kind of builder of
its position and positive primes: the store is made for the entries with e.
The tables of rows of the sieve entries l added in turn, each with the reference and the kind
of builder of its position after es and positive primes: the store is made for es ++ l.
The store made for the entries es of a run holds the rows of the references of the run for
them (Ratpoints.Sieve.StoreHolds).
The invariant of the store holds for entries with the factors of those for which it holds, such
as the entries with the inverses of the strides (Ratpoints.Sieve.classOffsets) and those of the
first two stages.
An entry with the modulus, the factors, the reference and the kind of builder of an entry that
fits the rows R at its position fits them too, such as the entry with the inverses of the strides
(Ratpoints.Sieve.classOffsets).
A store that fits the sieve entries #
The store s fits the sieve entries es: it holds rows R of the references
(Ratpoints.Sieve.StoreHolds) that every entry fits at its position
(Ratpoints.Sieve.SieveEntry.RowsFit), which is what building the rows of the entries needs.
Equations
Instances For
The store of the sieve entries of a run fits their first k, those of the first two stages.
The store of the sieve entries of a run fits them with the inverses of the strides that
Ratpoints.Sieve.classOffsets sets.
The sieve specs of a denominator that Ratpoints.Sieve.setRows makes and
Ratpoints.Sieve.buildRows completes for the residues g e < p of the entries, as the run
computes them (Ratpoints.Sieve.buildRows_setRows_map_spec): the closed forms of the rows of the
entries at their residues, with the offsets of the class, the start 0 and the end p; and the
store after them still fits the entries.
The sieve specs of the first k sieve entries of L that Ratpoints.Sieve.setRows makes and
Ratpoints.Sieve.buildRows completes for their residues g e < p, from a store that holds the
rows R for all of L (Ratpoints.Sieve.StoreHolds), whose entries fit them: the store after
them still holds the rows for all of L (Ratpoints.Sieve.buildRows_setRows_map_spec).