Sparse memory with an explicit default #
A sparse memory is Mathlib's association list with a constant value type. Its keys are unique; writing a cell replaces its old binding. Storing the default value still records a binding, so cardinality measures stored addresses rather than the support of the denoted function.
Main definitions #
SparseMemory: an association list of distinct addresses and values.SparseMemory.read: total memory semantics, with an explicit default value.SparseMemory.entries: the ordinary pair representation used for binary encoding.
Main results #
SparseMemory.read_insert: a write denotes functional update.SparseMemory.length_insert_le: a write adds at most one stored address.SparseMemory.length_insert_of_mem: overwriting an address does not grow the store.
References #
The representation and lookup/update correctness reuse Mathlib's AList implementation.
The finite bindings, viewed as ordinary pairs for encoding.
Instances For
Read a stored address, or return the supplied default.
Instances For
The ordinary entries determine the association list.
Default-valued memory requires no stored cells.
The pair representation has the same number of bindings.
Writing denotes functional update, including when the value equals the default.
A write adds at most one distinct stored address.
Replacing an existing address preserves the number of stored addresses.
A write is a filter followed by one cons, on the encoded pair representation.
Lookup is a first-match scan of the encoded pair representation.
Each binding after a write is either the new binding or a surviving old binding.