Tactics for relational judgments (pRHL) #
prhlStmt registers one descriptor per side with the judgment registry (Logic/Judgment.lean),
so the generic statement steps work on it, on both sides or on one ({1}, {2}):
stmt_inline n,stmt_inline{i} n— inline call siten(EC'sinline);stmt_split k,stmt_split{i} k— regroup the lastkstatements;stmt_wp,stmt_wp k,stmt_wp{i} k— wp over deterministic code (EC'swp); over a sampling on one side,rnd{i}(the distribution must be lossless).
And the relational steps proper:
equiv_proc_to_stmt— fromequiv[ M₁ ~ M₂ : P ==> Q ]to the judgment about the two call statements (inlined bystmt_inline 0; EC'sproc, to the bodies, isequiv_proc,Logic/ECProc.lean);equiv_rnd,equiv_rnd f— the two last statements are samplings, coupled alongf(default: the identity) (EC'srnd);equiv_rnd_run k— a sampling on the left against the lastkstatements on the right, which sample the same;equiv_while_raw I— synchronized loops with the invariantI(four goals; EC'swhile Iisequiv_while,Logic/ECWhileRel.lean);equiv_call h— the last statements are calls, related by the procedure judgmenth(EC'scall;prhlProc_glob hAfor an abstract procedure, EC'scall (_ : ={glob A}));equiv_callalone for calls of the same procedure from equal arguments and globals;equiv_seq_last k₁ k₂ : M— cut after all but the lastk₁/k₂statements (EC'sseqcounts from the start:equiv_seq,Logic/ECSeq.lean);equiv_case P— case analysis on a relation of the initial states (EC'scase);equiv_if,equiv_if{i}— conditionals on both sides, or on one (EC'sif,if{i});equiv_sym— swap the sides;equiv_rcondf{i}— a trailing loop on sideiwhose guard is false (EC'srcondf{i});equiv_skip— atskip ~ skip, the implication, with the reads of both states generalized (x₁,x₂; EC'sskip).
Relations written in tactics (I, M, P, the coupling f) are relational conditions as in
equiv[ … ]: §x{1}, §x{2}, ={x}, over the program variables of the goal.
The simp set for relational conditions: the reads through writes of simpReads, and the
trivial coupling conditions equiv_rnd leaves (the identity and negation push a uniform
distribution to itself, and its support is everything).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The names of the binders of ty's leading ∀s.
Apply the lemma lem to g by unifying its conclusion with the goal (no unfolding of the
judgment, which MVarId.apply would do to count arguments): pre sets the lemma's arguments by
binder name first. The arguments left open are returned, in order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generalizing the reads of two states #
Does σ.globals occur in e other than as the state of a read x.get σ.globals?
Does the state σ occur in e only as read (collectReadsOf) or as its globals?
Equations
- One or more equations did not get rendered due to their size.
Instances For
On a goal ∀ σ₁ σ₂ : ProgramState, P σ₁ σ₂: generalizeReads for both states — every read
of σ₁ becomes a value x₁, every read of σ₂ a value x₂ (named after the variable), and the
states are dropped if nothing else mentions them; a state that occurs other than read is left
alone (onlyRead), its reads with it. Where the globals themselves occur
(§allGlobals, the globals a call leaves), they become a value globals₁/globals₂ first, and the reads of
global variables stay reads of it (x.get globals₁), so nothing is lost. Atomic, as
generalizeReads.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Relational conditions in tactics #
Elaborate the relational term t (§x{1}, §x{2}, ={x} over the program variables of the
goal goalTy) at type T, as a function ProgramState → ProgramState → T.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A relational condition (Prop-valued).
Equations
- GaudisCrypt.PRHLWp.elabRelCond goalTy t = GaudisCrypt.PRHLWp.elabRelTerm goalTy t (Lean.mkSort 0)
Instances For
generalizeReadsRel, for the tactic tac: if it fails, the goal stays about the two states,
and tac says so (ECReport.fallback).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The goal's type, checked to be a prhlStmt judgment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
From procedures to statements #
On a goal prhlProc A p₁ p₂ B: the judgment about the two call statements
res <- call pᵢ (x₁, …, xₙ), one local variable per parameter (prhlProc_of_prhlStmt), the
conditions with the reads simplified.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_proc_to_stmt: from equiv[ M₁ ~ M₂ : P ==> Q ] to the judgment about the call
statements res <- call Mᵢ (x₁, …, xₙ) (equivProcToStmt); inline them with stmt_inline 0.
EC's proc, to the bodies, is equiv_proc (Logic/ECProc.lean).
Equations
- GaudisCrypt.PRHLWp.tacticEquiv_proc_to_stmt = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticEquiv_proc_to_stmt 1024 (Lean.ParserDescr.nonReservedSymbol "equiv_proc_to_stmt" false)
Instances For
Relational steps #
skip ~ skip: the implication, reads generalized (generalizeReadsRel).
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_skip: at skip ~ skip (what stmt_wp leaves when the code is all deterministic),
the implication from the precondition to the postcondition, the reads of the two states as
plain values x₁, x₂.
Equations
- GaudisCrypt.PRHLWp.tacticEquiv_skip = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticEquiv_skip 1024 (Lean.ParserDescr.nonReservedSymbol "equiv_skip" false)
Instances For
equiv_skip, the decide instances normalized first (TacticMisc.normDecide), so that every
read is generalized (EC's auto uses it).
Equations
- GaudisCrypt.PRHLWp.tacticEquiv_skip_ec = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticEquiv_skip_ec 1024 (Lean.ParserDescr.nonReservedSymbol "equiv_skip_ec" false)
Instances For
EC's rnd{i}: the last statement of side i is a sampling x <$ d, which goes by
itself (prhlStmt_seq_sample_left/_right): the postcondition before it asks d lossless and
the postcondition for every value in its support.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_rnd f: the last statements of both sides are samplings x₁ <$ d₁, x₂ <$ d₂,
coupled along f (prhlStmt_seq_sample): the postcondition before them asks that f push d₁
to d₂, and the postcondition for every a in the support of d₁ paired with f a. f is a
relational term (it may read both states, §x{1}, §x{2}); without it, the identity.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_rnd_run k: the last statement of the left side is a sampling x₁ <$ d, and the last
k statements of the right side sample from d into the same variable
(prhlStmt_seq_sample_run_right). The
postcondition before them asks for that run, as an equation of the right side's run with the
sampling, and the postcondition for every draw.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_while_raw I (the older form of EC's while I, which is equiv_while,
Logic/ECWhileRel.lean): the last statements of both sides are loops, synchronized by the invariant
I (prhlStmt_seq_while). Goals: body (the bodies keep I, from I and the guard), guard
(under I the guards agree), exit (I and a false guard give the postcondition), then the
code before the loops, with postcondition I.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_while_noframe{i} I V (the older form of EC's while{i} I V, which is
equiv_while{i}, Logic/ECWhileRel.lean): the last statement of side i is a loop, run on that
side only, with
the invariant I and the variant V : ℕ (both relational, EC's while{i} I V;
prhlStmt_seq_while_left/_right). Goals: lossless (the body terminates under I and the
guard), variant (the body keeps I and decreases V, a Hoare triple for each state of the
other side and each value of V), exit (I and a false guard give the postcondition), then
the code before the loop, with postcondition I.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_seq_last k₁ k₂ : M: cut both statements, the last k₁ (left) and k₂ (right)
statements after the cut, with the relation M in between (prhlStmt_seq). Goals: the code
before the cut (to M), then the code after it (from M).
Equations
- One or more equations did not get rendered due to their size.
Instances For
A procedure judgment h with the procedure aliases of modules in its type (proc f = c;,
@[gaudiModuleAlias]) rewritten to their callees by their X.f.apply_simp lemmas: EC's
call (RO_LRO_D (D2(D))) names the alias, the program calls the callee. A module made of
aliases only is opened too (X.apply_simp, and the accessors' mk_simp on the record it gives):
D2(D) applied, a single-procedure module, is its alias. h itself when its type mentions no
alias.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The call rule without a frame (prhlStmt_seq_call, prhlStmt_seq_call_refl): what
equiv_call h and equiv_call do when no framed rule applies (Logic/ECCallEquiv.lean), and
equiv_call_frameless by name.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_call h: the last statements of both sides are calls x₁ <- call p₁ (e₁),
x₂ <- call p₂ (e₂), and h a procedure judgment equiv[ p₁ ~ p₂ : P ==> Q ] about the callees
(prhlStmt_seq_call; for an abstract procedure, prhlProc_glob hA: EC's
call (_ : ={glob A})). The postcondition before the calls: P at the arguments and globals,
and the postcondition after them for all results and globals Q relates.
equiv_call alone: both calls are of the same procedure (EC's call (_ : true) on the same
code, prhlStmt_seq_call_refl): the postcondition before them asks for equal arguments and equal
globals, and the postcondition after them for every result and globals, the same on both
sides.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_call_frameless h / equiv_call_frameless: the call rule without a frame, by name
(what equiv_call h falls back to, with a warning, when the framed rule does not apply).
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_call_frame X: equiv_call (same procedure on both sides) where the postcondition may
also assume that the variable X kept its value through the call
(prhlStmt_seq_call_refl_frame). X must lie outside the callee's footprint: the module's own
(Module.Proc.inFootprint_fvP, or a hypothesis), the disjointness shown by fp_disjoint from the
restriction hypotheses in context. EC proves such a step with swap or sim, from its memory
restrictions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
simp_reads: simplify the goal with the read-through-write lemmas the judgment tactics use
(relSimpDecls: a variable read after writes to other variables, resets, the globals written by a
call), for goals left after unfolding expectations or judgments by hand.
Equations
- GaudisCrypt.PRHLWp.tacticSimp_reads = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticSimp_reads 1024 (Lean.ParserDescr.nonReservedSymbol "simp_reads" false)
Instances For
phoare_ewp: on a goal phoareStmt A s g ρ r about loop-free code, introduce the state and the
precondition and spell the expectation s.ewp g σ out (Stmt.ewp_seq, _ifThenElse, _assign,
_sample, _skip): samplings become expected, conditionals ifs (also those with a sampling
inside, which phoare_wp does not take), calls stay the callee's expectation. Then
simp_reads, and the tests back to propositions. What is left is about the initial state only.
Equations
- GaudisCrypt.PRHLWp.tacticPhoare_ewp = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticPhoare_ewp 1024 (Lean.ParserDescr.nonReservedSymbol "phoare_ewp" false)
Instances For
if c t e; s (through the lets of the locals) as if c (t; s) (e; s), and the
equivalence (Stmt.Equiv.seq_ite); fails on anything else.
equiv_if: both statements are conditionals (prhlStmt_if): goals then, else (with the
test true, resp. false, on both sides) and guard (the tests agree under the precondition).
equiv_if{i}: side i's statement is a conditional (prhlStmt_if_left/_right, EC's
if{i}): goals then, else, each against the other side. To reach a conditional inside a
sequence, cut first (equiv_seq, equiv_seq_last).
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_rcondf{i}: the last statement of side i is a loop that does not run — its guard
is false where it starts (EC's rcondf{i}, for a trailing loop;
prhlStmt_seq_while_false_left/_right). The postcondition before it adds the false guard.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_sym: swap the two sides (prhlStmt.symm, on a procedure judgment prhlProc.symm;
EC's symmetry).
Equations
- GaudisCrypt.PRHLWp.tacticEquiv_sym = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticEquiv_sym 1024 (Lean.ParserDescr.nonReservedSymbol "equiv_sym" false)
Instances For
equiv_case P: case analysis on the relation P of the initial states
(prhlStmt_case): goals with A ∧ P and with A ∧ ¬P as preconditions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv_sim: EC's sim on straight-line code. Backwards over both statements, as long as one
of these applies: stmt_wp (trailing deterministic code, both sides), equiv_call (calls of the
same procedure, or of procedures spelled differently, their equality tried by rfl and left as
a callee goal otherwise). When both statements are used up, equiv_skip, and the implication
it leaves closed by simp_all if it can. It stops at anything else (a conditional, a loop, a
sampling, calls of different procedures), leaving that goal: cut there with equiv_seq … : M.
Equations
- GaudisCrypt.PRHLWp.tacticEquiv_sim = Lean.ParserDescr.node `GaudisCrypt.PRHLWp.tacticEquiv_sim 1024 (Lean.ParserDescr.nonReservedSymbol "equiv_sim" false)