Documentation

GaudisCrypt.Logic.Judgment

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:

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

    J … s' … → J … s … from s.Equiv s', conditions unchanged (hoareStmt_of_equiv). Its arguments are found by unification: one of type _.Equiv _ (or EquivInLens), and the judgment about s' last.

  • transportLemma : Lean.Name

    J … s' … → J … s … from s.EquivInLens s' l, with one equation (fun τ => C (l.get τ)) = C' per condition C (hoareStmt_of_equivInLens). Arguments found as for equivLemma; each equation by its type.

  • condSimp : List Lean.Name

    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.

  • condSimprocs : List Lean.Name

    Simprocs run along with condSimp.

  • postArg : ℕ

    The position of the postcondition (the condition wp steps rewrite) among the head's arguments.

  • detLemma : Option Lean.Name

    J A s (fun σ => B (upd σ)) … → J A (s; d) B … from d.Det upd (Stmt.Det): the wp rule for deterministic code, the same in every judgment. Arguments by unification, the Det proof by its type, the judgment about s last.

  • sampleLemma : Option Lean.Name

    The judgment's rule for a trailing sampling x <$ e: J A s ‹post'› … → J A (s; x <$ e) B …. Judgment-specific (∀ a ∈ support for Hoare triples, an average for phoare).

  • callLemma : Option Lean.Name

    The judgment's rule for a trailing call without a specification, if it has one (phoare: the callee's expectation, symbolically).

  • ifLemma : Option Lean.Name

    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).

  • postSimp : List Lean.Name

    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.

  • postSimprocs : List Lean.Name
Instances For

    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
        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
          Instances For
            theorem GaudisCrypt.Stmt.Det.assign {α : Type} (x : Setter α ProgramState) (e : Getter α ProgramState) :
            Det (StmtWithHoles.assign x e) fun (σ : ProgramState) => x.set (e.get σ) σ
            theorem GaudisCrypt.Stmt.Det.seq {p q : Stmt} {up uq : ProgramState → ProgramState} (hp : p.Det up) (hq : q.Det uq) :
            Det (StmtWithHoles.seq p q) fun (σ : ProgramState) => uq (up σ)
            theorem GaudisCrypt.Stmt.Det.ite {c : Getter Bool ProgramState} {p q : Stmt} {up uq : ProgramState → ProgramState} (hp : p.Det up) (hq : q.Det uq) :
            Det (StmtWithHoles.ifThenElse c p q) fun (σ : ProgramState) => if c.get σ = true then up σ else uq σ
            theorem GaudisCrypt.Getter.get_ite {α : Type u_1} {m : Type u_2} (g : Getter α m) (c : Prop) [Decidable c] (a b : m) :
            g.get (if c then a else b) = if c then g.get a else g.get b

            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.

            The state update of a deterministic statement, and the proof of Stmt.Det, built from its syntax: assignments (resets included), skip, sequences and conditionals of those. none for anything else (sampling, calls, loops). lets on the statement are zeta-reduced.

            theorem GaudisCrypt.decide_congr_inst {p q : Prop} (h : p = q) (hp : Decidable p) (hq : Decidable q) :

            decide of equal propositions, whatever the instances.

            @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
                              def GaudisCrypt.Judgment.sideOf? (s? : Option (Lean.TSyntax `GaudisCrypt.Judgment.judgmentSide)) :

                              The side a judgmentSide selects.

                              Equations
                              Instances For