Judgments about statements, generically #
Many proof steps change only the statement of a judgment — regrouping a sequence, inlining a
call — and prove the old statement equivalent to the new one, possibly along a renaming lens
(StmtWithHoles.Equiv, StmtWithHoles.EquivInLens). What differs between hoareStmt,
phoareStmt (and later the two sides of a relational judgment) is only how the judgment is
transported along that equivalence. A JudgmentDesc records exactly that, and the steps are
implemented once, for every registered judgment:
Judgment.onStmt— rewrite the statement with aStmt.Equivproof (hoare_split, …);Judgment.inline(Logic/Inline.lean) — rewrite alongEquivInLens, reading the conditions through the renaming.
A judgment registers itself (registerJudgment) in a file that imports this one — the registry
is an environment extension, which exists only downstream of its declaring file; Hoare triples
register in Logic/TacticMisc.lean. The generic steps find the descriptor from the goal's head
constant.
How a judgment about one statement is transported along an equivalence of statements. A
relational judgment registers one descriptor per side (side 1 and 2): what a step does to one
side's statement, its transport lemmas and wp rules.
- head : Lean.Name
The head constant of the judgment (
hoareStmt). - side : ℕ
The side of a relational judgment this descriptor is about (1 or 2); 0 for a judgment about one statement.
- stmtArg : ℕ
The position of the statement among the head's arguments.
- equivLemma : Lean.Name
- transportLemma : Lean.Name
J … s' … → J … s …froms.EquivInLens s' l, with one equation(fun τ => C (l.get τ)) = C'per conditionC(hoareStmt_of_equivInLens). Arguments found as forequivLemma; each equation by its type. Simp lemmas (theorems rewritten with, definitions unfolded) run on a condition after the inliner's own cleaning, e.g. to put an expectation in the form the judgment's tactics expect.
Simprocs run along with
condSimp.- postArg : ℕ
The position of the postcondition (the condition wp steps rewrite) among the head's arguments.
The judgment's rule for a trailing sampling
x <$ e:J A s ‹post'› … → J A (s; x <$ e) B …. Judgment-specific (∀ a ∈ supportfor Hoare triples, an average forphoare).The judgment's rule for a trailing call without a specification, if it has one (
phoare: the callee's expectation, symbolically).The judgment's rule for a trailing conditional that is not deterministic code (a call or a sampling in a branch), if it has one (
phoare: the branches' expectations, by cases on the condition).Simp lemmas (theorems rewritten with, definitions unfolded) and simprocs for the postcondition after each wp step: reads through writes, and whatever the judgment's conditions need.
Instances For
Equations
Add a descriptor to the registry: it replaces the one for the same head and side.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The registered judgments, by head constant: one descriptor, or one per side.
Register a judgment, or one side of a relational one (in the file that proves its transport lemmas).
Equations
Instances For
The descriptors of a goal's judgment (one per side), if its head is registered.
Equations
- GaudisCrypt.judgmentOf? ty = match ty.getAppFn.constName? with | some c => do let __do_lift ← Lean.getEnv pure ((GaudisCrypt.judgmentExt.getState __do_lift).find? c) | x => pure none
Instances For
Deterministic statements #
A statement is deterministic if it maps the state by a function upd and always terminates:
then its weakest precondition, for a postcondition of any kind, is the postcondition after
upd. Stmt.Det d upd says this of the wp, which is all the rules use.
d runs as the state update upd: its wp of any postcondition is that postcondition after
upd.
Equations
- d.Det upd = ∀ (f : Unit × GaudisCrypt.ProgramState → ENNReal) (σ : GaudisCrypt.ProgramState), (GaudisCrypt.programDenotation d).wp f σ = f ((), upd σ)
Instances For
A read of a conditional state is the conditional of the reads — what a deterministic if
leaves in a postcondition (Stmt.Det.ite updates the state conditionally).
A statement with the lets on its spine substituted and metadata dropped.
@decide p inst ↦ @decide p' inst', where p' is p simplified and inst' an instance
synthesized for it, or Classical.propDecidable p' if there is none. Used by the inliner's
cleaning and by every tactic's simpWithNames. Not left to simp's
congruence: that re-synthesizes the instance too, and when it cannot (a condition decided
classically, as open Classical in decides an equality on a type without DecidableEq) it leaves
p alone, the reads in it keeping their wrappers.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The descriptors of the goal g's judgment (one, or one per side of a relational judgment),
or an error naming the registered ones; with side? = some i, only side i's.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The descriptor of the goal g's judgment, of side side? for a relational one (which then
has to be given).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run step on each side side? selects (all of them for none), in order, each time on the
goal the previous one left.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simplify e with simp only over the declarations decls (theorems rewritten with,
definitions unfolded) and the simprocs procs along with the default ones.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Is t (up to instantiation) the type of a statement equivalence?
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the transport lemma lem of d to the goal g (of type ty) with the equivalence
proof p: unify the lemma's conclusion with the goal, the equivalence argument with p, and run
solveEq on each remaining equation argument; the judgment about the new statement is returned
as the new goal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
On a goal about a registered judgment: rewrite its statement with f, which returns the new
statement s' and a proof of s.Equiv s' (as flattenSeq and HoareSplit.splitSeq do), and
continue with the judgment about s', conditions unchanged. On a relational judgment, the
statement of side side?, or of each side in turn for none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A side selector in a tactic, {1} or {2}: the side of a relational judgment the tactic works
on (EasyCrypt's wp{1}, inline{2}). Without it, a tactic works on every side.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The side a judgmentSide selects.
Equations
- GaudisCrypt.Judgment.sideOf? s? = s?.bind fun (s : Lean.TSyntax `GaudisCrypt.Judgment.judgmentSide) => s.raw[1].isNatLit?