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
Heap: partial finite map from location ids to encoded values.
Values are encoded using their Fintype encoding as natural numbers.
Unaccessed locations are absent from the map; get returns default
for absent locations.
Partial map from location id to encoded value (natural number)
Instances For
Equations
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
Get a value from the heap at a location.
Returns default if the location has never been written.
Equations
- h.get l = match Finmap.lookup l.id h.data with | some n => CatCrypt.Core.Heap.decode l.ty n | none => 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
Heap equality is not decidable in general, but we can use classical logic