Locations and Heaps for Deep Embedding #
This file defines locations and heaps for the deep embedding of CatCrypt computations.
Main definitions #
Location- A location pairs an atom (name) with a typeDeepHeap- A heap mapping locations to valuesDeepHeap.empty- The empty heapDeepHeap.get- Get value from a locationDeepHeap.set- Set value at a location
Nominal Structure #
Locations are equipped with a nominal structure:
- Permutations act on the atom while preserving the type:
π • ℓ = ⟨π • ℓ.name, ℓ.ty⟩ - The support of a location is the singleton of its atom:
supp ℓ = {ℓ.name}
Design decision: Two locations with the same name but different types are considered different locations. This is the mathematically consistent approach: Location equality is structural equality of the pair (name, ty). The heap stores values indexed by the full location (including type), so there's no inconsistency.
This means you cannot have two locations with the same name but different types "collide" in a heap - they simply occupy different slots.
References #
- SSProve
theories/Crypt/rhl_semantics/free_prot/free_code.v - Larsen and Schürmann, Nominal State-Separating Proofs
A location pairs an atom (name) with a type. This represents a typed memory location in the deep embedding.
Two locations are equal iff both name AND ty are equal. This is standard structural equality - no axioms needed.
- name : Nominal.Atom
The name of the location
- ty : Type u_1
The type of values stored at this location
Instances For
Nominal Instances for Location #
Locations form a nominal set where:
- Permutations act on the atom, preserving the type
- The support is the singleton of the atom
Nominal action on locations: permute the atom, preserve the type
Equations
- CatCrypt.Deep.instMulActionFinPermLocation = { smul := CatCrypt.Deep.Location.perm, mul_smul := CatCrypt.Deep.Location.perm_mul, one_smul := CatCrypt.Deep.Location.perm_one }
Locations form a nominal set with singleton support
Equations
- One or more equations did not get rendered due to their size.
The atom of a location
Instances For
The support of a location is its atom
A finite set of locations
Instances For
Get the atoms from a finite set of locations. Note: We can't use Finset Location directly since Location contains types, so we work with atoms and store locations in a separate structure.
Equations
- CatCrypt.Deep.locsToAtoms locs = List.foldl (fun (s : CatCrypt.Deep.LocAtomSet) (ℓ : CatCrypt.Deep.Location) => s ∪ {ℓ.name}) ∅ locs
Instances For
A heap is a mapping from locations to optional values. Each location can either be uninitialized (None) or contain a value of the appropriate type.
The underlying data: for each location, an optional value of the right type
Instances For
The empty heap where all locations are uninitialized
Equations
- CatCrypt.Deep.DeepHeap.empty = { data := fun (x : CatCrypt.Deep.Location) => none }
Instances For
Set the value at a location.
This updates the heap so that location ℓ contains value v.
For any other location ℓ', the value is unchanged.
Two locations are considered the same iff both name AND type match.
If ℓ' has the same name but different type, it is a different location
and is not affected by this update.
This is noncomputable because we use classical decidability for type equality.
Equations
Instances For
Getting from a heap after setting a different location returns the original value. Note: This now requires that the locations are different (either by name or by type).