Deep/Shallow Bridge Library #
This file provides systematic support for moving between the deep embedding (RawCode, DeepPackage) and the shallow embedding (SPComp).
Main definitions #
DeepPackage.evalOp- Evaluate a single operation from a deep packagerHoare_of_code_eq- Derive rHoare from code equality in deep embeddingrHoare_of_eval_eq- Derive rHoare from evaluation equality
Tactics #
ssprove_deep_to_shallow- Unfold DeepRHoare and simplify evalssprove_eval- Simplify eval expressions using the ssprove_eval simp set
Simp set #
ssprove_eval- Named simp set collecting all eval lemmas
Design rationale #
The bridge serves multiple purposes:
Move to shallow for distribution reasoning: After defining games in the deep embedding, use eval to move to SPComp for coupling proofs.
Structural equality → rHoare: When two deep programs are syntactically equal, this immediately gives an rHoare judgment after evaluation.
Package-level evaluation: Evaluate all implementations in a deep package to SPComp functions, enabling reasoning about whole packages.
References #
Eval Simp Set #
The ssprove_eval simp set collects all lemmas for evaluating
deep embedding code into the shallow embedding.
Package-Level Evaluation #
Evaluate a single operation from a deep package to an SPComp function.
Given a package p with an exported operation (op, dom, codom),
this evaluates the implementation code to a shallow SPComp computation.
Instances For
Code Equality → rHoare #
Code equality gives eqPost from eqPre.
This is the key bridge lemma: if two RawCode programs are syntactically equal, their evaluations produce equal results from equal heaps.
For custom pre/post conditions, use rHoare_conseq after this lemma.
Package Operation Evaluation Lemmas #
Bridge Lemmas for Common Patterns #
DeepRHoare from code equality (the most common bridge pattern).
DeepRHoare unfolds to rHoare on eval.
Bridge Tactics #
ssprove_deep_to_shallow unfolds DeepRHoare to rHoare and simplifies eval.
This is the main entry point for moving from deep to shallow embedding. After applying this tactic, the goal will be a standard rHoare judgment on SPComp terms.
Example:
theorem example : DeepRHoare eqPre code₁ code₂ eqPost := by
ssprove_deep_to_shallow
-- Goal is now: rHoare eqPre (eval₁) (eval₂) eqPost
-- where eval₁, eval₂ are simplified SPComp terms
Equations
- CatCrypt.Deep.tacticSsprove_deep_to_shallow = Lean.ParserDescr.node `CatCrypt.Deep.tacticSsprove_deep_to_shallow 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_deep_to_shallow" false)
Instances For
ssprove_eval simplifies eval expressions in the goal.
This applies all evaluation lemmas to normalize deep embedding terms that have been evaluated into the shallow embedding.
Equations
- CatCrypt.Deep.tacticSsprove_eval = Lean.ParserDescr.node `CatCrypt.Deep.tacticSsprove_eval 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_eval" false)