Documentation

CatCryptCore.Deep.Location

Locations and Heaps for Deep Embedding #

This file defines locations and heaps for the deep embedding of CatCrypt computations.

Main definitions #

Nominal Structure #

Locations are equipped with a nominal structure:

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 #

structure CatCrypt.Deep.Location :
Type (u_1 + 1)

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.

  • The name of the location

  • ty : Type u_1

    The type of values stored at this location

Instances For

    Decidable equality on the name component only. Note: This is weaker than structural equality since it ignores types.

    Equations
    Instances For
      theorem CatCrypt.Deep.Location.ext_iff {ℓ₁ ℓ₂ : Location} :
      ℓ₁ = ℓ₂ ℓ₁.name = ℓ₂.name ℓ₁.ty = ℓ₂.ty

      Two locations are equal iff they have the same name and type. This follows from the structure definition.

      theorem CatCrypt.Deep.Location.ext {ℓ₁ ℓ₂ : Location} (hn : ℓ₁.name = ℓ₂.name) (ht : ℓ₁.ty = ℓ₂.ty) :
      ℓ₁ = ℓ₂
      theorem CatCrypt.Deep.Location.name_eq_of_eq {ℓ₁ ℓ₂ : Location} (h : ℓ₁ = ℓ₂) :
      ℓ₁.name = ℓ₂.name
      theorem CatCrypt.Deep.Location.ty_eq_of_eq {ℓ₁ ℓ₂ : Location} (h : ℓ₁ = ℓ₂) :
      ℓ₁.ty = ℓ₂.ty

      Apply a permutation to a location by permuting its atom name. The type is preserved: (π • ℓ).ty = ℓ.ty.

      Equations
      Instances For
        @[simp]
        @[simp]
        theorem CatCrypt.Deep.Location.perm_ty (π : Nominal.FinPerm) ( : Location) :
        (perm π ).ty = .ty
        @[simp]
        theorem CatCrypt.Deep.Location.perm_one ( : Location) :
        perm 1 =
        theorem CatCrypt.Deep.Location.perm_mul (π₁ π₂ : Nominal.FinPerm) ( : Location) :
        perm (π₁ * π₂) = perm π₁ (perm π₂ )

        Nominal Instances for Location #

        Locations form a nominal set where:

        @[implicit_reducible]

        Nominal action on locations: permute the atom, preserve the type

        Equations
        @[implicit_reducible]

        Locations form a nominal set with singleton support

        Equations
        • One or more equations did not get rendered due to their size.
        @[reducible, inline]

        The atom of a location

        Equations
        Instances For
          @[simp]

          The support of a location is its atom

          Two locations are disjoint if they have different atoms

          Equations
          Instances For
            theorem CatCrypt.Deep.Location.disj_comm (ℓ₁ : Location) (ℓ₂ : Location) :
            ℓ₁.disj ℓ₂ ℓ₂.disj ℓ₁
            theorem CatCrypt.Deep.Location.disj_of_ne_name {ℓ₁ : Location} {ℓ₂ : Location} (h : ℓ₁.name ℓ₂.name) :
            ℓ₁.disj ℓ₂
            @[reducible, inline]

            A finite set of locations

            Equations
            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
              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.

                • data ( : Location) : Option .ty

                  The underlying data: for each location, an optional value of the right type

                Instances For

                  The empty heap where all locations are uninitialized

                  Equations
                  Instances For

                    Get the value at a location

                    Equations
                    Instances For
                      noncomputable def CatCrypt.Deep.DeepHeap.set (h : DeepHeap) ( : Location) (v : .ty) :

                      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
                        @[simp]

                        Getting from the empty heap returns None

                        theorem CatCrypt.Deep.DeepHeap.get_set_same (h : DeepHeap) ( : Location) (v : .ty) :
                        (h.set v).get = some v

                        Getting from a heap after setting the same location returns the value

                        theorem CatCrypt.Deep.DeepHeap.get_set_other (h : DeepHeap) (ℓ₁ ℓ₂ : Location) (v : ℓ₁.ty) (hne : ℓ₁ ℓ₂) :
                        (h.set ℓ₁ v).get ℓ₂ = h.get ℓ₂

                        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).

                        theorem CatCrypt.Deep.DeepHeap.get_set_other_name (h : DeepHeap) (ℓ₁ ℓ₂ : Location) (v : ℓ₁.ty) (hne : ℓ₁.name ℓ₂.name) :
                        (h.set ℓ₁ v).get ℓ₂ = h.get ℓ₂

                        Getting from a heap after setting a location with different name returns the original value. This is a convenience lemma when we know the names differ.

                        theorem CatCrypt.Deep.DeepHeap.ext {h₁ h₂ : DeepHeap} (hext : ∀ ( : Location), h₁.get = h₂.get ) :
                        h₁ = h₂

                        Extensionality for heaps: heaps are equal if they agree on all locations

                        theorem CatCrypt.Deep.DeepHeap.ext_iff {h₁ h₂ : DeepHeap} :
                        h₁ = h₂ ∀ ( : Location), h₁.get = h₂.get
                        theorem CatCrypt.Deep.DeepHeap.set_set_same (h : DeepHeap) ( : Location) (v₁ v₂ : .ty) :
                        (h.set v₁).set v₂ = h.set v₂

                        Setting the same location twice keeps only the last value

                        theorem CatCrypt.Deep.DeepHeap.set_set_comm (h : DeepHeap) (ℓ₁ ℓ₂ : Location) (v₁ : ℓ₁.ty) (v₂ : ℓ₂.ty) (hne : ℓ₁ ℓ₂) :
                        (h.set ℓ₁ v₁).set ℓ₂ v₂ = (h.set ℓ₂ v₂).set ℓ₁ v₁

                        Setting different locations commutes. Note: Now requires that the locations are different (either by name or type).

                        theorem CatCrypt.Deep.DeepHeap.set_set_comm_name (h : DeepHeap) (ℓ₁ ℓ₂ : Location) (v₁ : ℓ₁.ty) (v₂ : ℓ₂.ty) (hne : ℓ₁.name ℓ₂.name) :
                        (h.set ℓ₁ v₁).set ℓ₂ v₂ = (h.set ℓ₂ v₂).set ℓ₁ v₁

                        Setting different locations (by name) commutes. This is a convenience lemma when we know the names differ.