Linear arithmetic over the definitions of a word-RAM development #
A word-RAM development states its arithmetic through chains of definitions: addresses and sizes of
a memory layout, such as tableBase base = base + 20 and
keysBase base n = tableBase base + tableSize n, bounds on steps and cost, and numeric parameters.
omega reads each application of such a definition as an unknown number, so a proof that compares
addresses first names the definitions to unfold, and has to be revisited when the layout gains a
region.
wram_omega proves such a goal from the definitions themselves. They are tagged @[wram_arith]
where they are written (the attribute's docstring says which definitions are tagged), and the
tactic unfolds the tagged definitions that occur, also those in the bodies of tagged definitions,
before it runs omega. It unfolds them in the goal first, which is what
unfold tableBase keysBase; omega does by hand. When omega then fails, it also unfolds the local
definitions (set S := n + 1), and reads the arithmetic hypotheses unfolded in the same way, as
dsimp only [tableBase, keysBase, S] at *; omega does. The hypotheses in the context are not
changed.
A tagged definition that returns a proposition, such as the word-size bound
Cslib.WordRAM.Fits w v, is unfolded in the same way, each power of two 2 ^ e the tactic
meets is known to be positive, and when two powers 2 ^ e₁ and 2 ^ e₂ occur with e₁ ≤ e₂ or
e₁ < e₂ provable by omega, 2 ^ e₁ ≤ 2 ^ e₂ (respectively 2 * 2 ^ e₁ ≤ 2 ^ e₂) is added as
well. So a word-size bound on an address follows from the bound on the end of the layout, also at a
wider word size. The tactic fits of CslibFrontier.Tactic.Fits proves a word-size bound that
needs no tagged definition unfolded; wram_omega is for the other goals, a word-size bound through
tagged definitions among them.
Every tagged definition met is unfolded, and a call cannot keep one folded: where a bound holds
only with a definition folded, the proof stays unfold a b; omega.
Main definitions #
wram_omega: prove a linear arithmetic goal, unfolding the@[wram_arith]definitions that occur.wram_omega_silent,Cslib.Tactic.WramOmega.tryProve: silent, heartbeat-bounded helper used by tactic dischargers (wram_exec,wram_simp,wram_call,mem_frame,struct_frame).
Whether wram_omega warns when it unfolded nothing, so that omega alone proves the goal.
wram_omega proves a goal of linear arithmetic over ℕ and ℤ about a word-RAM
development: it unfolds the definitions tagged @[wram_arith] (addresses, sizes, cost bounds and
numeric parameters), also those in the bodies of tagged definitions, and runs omega. Tagged
predicates, such as the word-size bound Cslib.WordRAM.Fits, are unfolded in the same way, a field
read from a structure given by its constructor is replaced by its value, every power of two
2 ^ e met is known to be positive, and when omega proves e₁ ≤ e₂ or e₁ < e₂ between two
powers met, 2 ^ e₁ ≤ 2 ^ e₂ (respectively 2 * 2 ^ e₁ ≤ 2 ^ e₂) is supplied as well.
The tactic first unfolds the goal only, as unfold a b; omega does. When omega then fails, it
also unfolds the local definitions (set S := n + 1) and reads unfolded the arithmetic hypotheses
that mention a tagged or a local definition, as dsimp only [a, b, S] at *; omega does; the
hypotheses in the context are not changed.
wram_omega [h₁, h₂] also uses the statements of the terms h₁ and h₂, unfolded like the goal.
Use it for facts omega cannot derive, such as bounds on products, and to name the hypotheses
that the goal follows from: omega is then run once, on a smaller problem than the one with every
hypothesis unfolded.
Use fits for a word-size bound Fits w v that needs no tagged definition unfolded. wram_omega
is for the other goals: a word-size bound that follows through tagged definitions, as
Fits w (keysBase base n + i) from Fits w (base + space n), and a goal of another shape that
uses hypotheses Fits w v, which fits refuses.
The tactic unfolds every tagged definition it meets; a call cannot keep one folded, and an
untagged definition stays an unknown. Unfolding can lose a bound that holds only with the
definition folded, as when its body divides by a variable. The call then fails, and the proof is
unfold a b; omega with the names it needs, as in
Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.compactedEpochWords_mono. For the same
reason a new @[wram_arith] tag can make an existing call fail when its module is built; a call
never proves a different statement.
When omega fails, the error lists the definitions that were unfolded and the tagged definitions
whose bodies are not visible in the current module. When nothing was unfolded and omega proves
the goal, the linter linter.unnecessaryWramOmega asks for omega.
Try to prove g with wram_omega (plus optional extra fact expressions extra) without
emitting warnings or exceeding maxHeartbeats (in thousands). Returns true if g is closed; on
failure restores the state and returns false. Skips immediately when g is not an arithmetic
goal or mentions no @[wram_arith] definition, local definition, or power of two anywhere in the
goal, extra, or arithmetic hypotheses.
Silent, heartbeat-bounded wram_omega for use inside tactic dischargers.