Memory/Remember Tactics #
This file provides tactics and rules for remembering values read from memory locations during relational proofs. This is useful when the same location is read multiple times and you want to avoid re-reading it.
Main definitions #
Rules #
r_get_remember_lhs- One-sided get on LHS that adds rem_lhs to preconditionr_get_remember_rhs- One-sided get on RHS that adds rem_rhs to preconditionr_get_remind_lhs- One-sided get on LHS that uses existing rem_lhs from preconditionr_get_remind_rhs- One-sided get on RHS that uses existing rem_rhs from preconditionr_forget_lhs- Weaken precondition by dropping rem_lhsr_forget_rhs- Weaken precondition by dropping rem_rhs
Tactics #
ssprove_forget- Discard most recent remembered value from preconditionssprove_forget_all- Discard all remembered values from preconditionssprove_remember_lhs- Apply r_get_remember_lhs rulessprove_remember_rhs- Apply r_get_remember_rhs rulessprove_remind_lhs- Apply r_get_remind_lhs rulessprove_remind_rhs- Apply r_get_remind_rhs rule
Usage #
When reading from a location, you can "remember" the value for later use.
This adds a rem_lhs l v or rem_rhs l v conjunct to the precondition.
Later, remind rules let you use the remembered value instead of reading again.
-- When we have a goal with `x <- get l` on the left
-- Apply r_get_remember_lhs to add rem_lhs l x to precondition
ssprove_remember_lhs
-- Later, when we read from the same location again
-- Apply r_get_remind_lhs to use the remembered value
ssprove_remind_lhs
References #
- SSProve: theories/Crypt/package/pkg_rhl.v (r_get_remember_lhs, etc.)
- SSProve: theories/Crypt/package/pkg_user_util.v (ssprove_forget)
Remember Rules #
One-sided get on the left that remembers the value.
After reading a value v from location l on the left side,
the precondition is extended with rem_lhs l v, remembering that
the left heap has value v at location l.
This is useful when the same location is read multiple times
and you want to use r_get_remind_lhs for subsequent reads.
One-sided get on the right that remembers the value.
After reading a value v from location l on the right side,
the precondition is extended with rem_rhs l v, remembering that
the right heap has value v at location l.
Remind Rules #
One-sided get on the left that uses a remembered value.
If the precondition contains rem_lhs l v, then reading from location l
on the left side can be replaced by using the known value v directly.
The [ProvenBy (rem_lhs l v) Φ] constraint ensures that the precondition
contains the remembered value. This is automatically inferred using the
ProvenBy instances.
One-sided get on the right that uses a remembered value.
If the precondition contains rem_rhs l v, then reading from location l
on the right side can be replaced by using the known value v directly.
Forget Rules #
Weaken precondition by dropping rem_lhs.
This rule drops a remembered value once it is irrelevant to the goal. It projects out the rem_lhs conjunct from the precondition.
Weaken precondition by dropping rem_rhs.
This rule drops a remembered value once it is irrelevant to the goal.
Synchronized Remember Rules #
Synchronized get that remembers on the left.
When both sides read from synchronized locations (same value on both sides), and we want to remember the value on the left side.
Synchronized get that remembers on the right.
When both sides read from synchronized locations, and we want to remember the value on the right side.
Remembers Syncs #
If we remember a value on one side and locations are synced, we can derive the remembered value on the other side.
Forget Tactics #
ssprove_forget discards the most recent remembered value from the precondition.
This tactic looks for a precondition of the form (Φ ⋊ rem_lhs l v) or (Φ ⋊ rem_rhs l v)
and applies the corresponding forget rule to drop the remembered value.
Example:
-- Goal: rHoare (Φ ⋊ rem_lhs l v) c₁ c₂ Ψ
ssprove_forget
-- New goal: rHoare Φ c₁ c₂ Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_forget = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_forget 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_forget" false)
Instances For
ssprove_forget_all discards all remembered values from the precondition.
This repeatedly applies ssprove_forget until no more remembered values remain.
Example:
-- Goal: rHoare (Φ ⋊ rem_lhs l₁ v₁ ⋊ rem_rhs l₂ v₂ ⋊ rem_lhs l₃ v₃) c₁ c₂ Ψ
ssprove_forget_all
-- New goal: rHoare Φ c₁ c₂ Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_forget_all = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_forget_all 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_forget_all" false)
Instances For
Remember Tactics #
ssprove_remember_lhs applies the r_get_remember_lhs rule.
This is used when you have a get l on the left side and want to
remember the value for later use. The precondition is extended with
rem_lhs l v.
Example:
-- Goal: rHoare Φ (SPComp.get l >>= f) c₂ Ψ
ssprove_remember_lhs
-- New goal: ∀ v, rHoare (Φ ⋊ rem_lhs l v) (f v) c₂ Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_remember_lhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_remember_lhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_remember_lhs" false)
Instances For
ssprove_remember_rhs applies the r_get_remember_rhs rule.
This is used when you have a get l on the right side and want to
remember the value for later use.
Example:
-- Goal: rHoare Φ c₁ (SPComp.get l >>= f) Ψ
ssprove_remember_rhs
-- New goal: ∀ v, rHoare (Φ ⋊ rem_rhs l v) c₁ (f v) Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_remember_rhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_remember_rhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_remember_rhs" false)
Instances For
Remind Tactics #
ssprove_remind_lhs applies the r_get_remind_lhs rule.
This is used when you have a get l on the left side and the precondition
already contains rem_lhs l v. The get is replaced by using the known value.
Example:
-- Goal: rHoare (Φ ⋊ rem_lhs l v) (SPComp.get l >>= f) c₂ Ψ
ssprove_remind_lhs
-- New goal: rHoare (Φ ⋊ rem_lhs l v) (f v) c₂ Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_remind_lhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_remind_lhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_remind_lhs" false)
Instances For
ssprove_remind_rhs applies the r_get_remind_rhs rule.
This is used when you have a get l on the right side and the precondition
already contains rem_rhs l v.
Example:
-- Goal: rHoare (Φ ⋊ rem_rhs l v) c₁ (SPComp.get l >>= f) Ψ
ssprove_remind_rhs
-- New goal: rHoare (Φ ⋊ rem_rhs l v) c₁ (f v) Ψ
Equations
- CatCrypt.Tactics.tacticSsprove_remind_rhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_remind_rhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_remind_rhs" false)
Instances For
Combined Remember/Remind Tactics #
ssprove_get_lhs handles a get on the left side by either remembering or reminding.
If the precondition already contains rem_lhs l v, it uses the remembered value.
Otherwise, it remembers the new value.
Equations
- CatCrypt.Tactics.tacticSsprove_get_lhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_get_lhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_get_lhs" false)
Instances For
ssprove_get_rhs handles a get on the right side by either remembering or reminding.
If the precondition already contains rem_rhs l v, it uses the remembered value.
Otherwise, it remembers the new value.
Equations
- CatCrypt.Tactics.tacticSsprove_get_rhs = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_get_rhs 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_get_rhs" false)