Heap Model #
This file defines the heap model for stateful computations.
Design #
Following the Rocq SSProve design, values are stored using their Fintype encoding
as natural numbers in a partial finite map (Finmap) from location ids to
encoded values. Unaccessed locations map to none; get returns default for
such locations.
This is the Lean 4 analogue of Rocq SSProve's {fmap nat → nat}.
Key Properties #
get_set_same: Getting after setting returns the stored valueget_set_other: Setting at one location doesn't affect other locationsset_set_same: Double write contracts to a single writeset_set_comm: Writes to different locations commute
@[implicit_reducible]
Equations
Equations
Instances For
theorem
CatCrypt.Core.Heap.ext_lookup
{h₁ h₂ : Heap}
(hlookup : ∀ (id : ℕ), Finmap.lookup id h₁.data = Finmap.lookup id h₂.data)
:
Extensionality for heaps via lookup
Empty heap: no locations are initialized
Equations
- CatCrypt.Core.Heap.empty = { data := ∅ }
Instances For
Encode a value using its Fintype equivalence
Equations
- CatCrypt.Core.Heap.encode v = ↑((Fintype.equivFin α) v)
Instances For
Decode a natural number to a value. If the number is out of range, returns default.
Equations
- CatCrypt.Core.Heap.decode α n = if h : n < Fintype.card α then (Fintype.equivFin α).symm ⟨n, h⟩ else default
Instances For
Set a value in the heap at a location
Equations
- h.set l v = { data := Finmap.insert l.id (CatCrypt.Core.Heap.encode v) h.data }
Instances For
Two heaps agree on a set of location ids
Equations
- h1.agreeOn h2 locs = ∀ id ∈ locs, Finmap.lookup id h1.data = Finmap.lookup id h2.data
Instances For
@[implicit_reducible]
Heap equality is not decidable in general, but we can use classical logic