Documentation

CatCryptCore.Category.PkgFam

Package Interfaces and Fam(KlSPComp) Morphisms #

A package interface specifies operation signatures via an index type ι with domain and codomain families in KlSPComp.

A package implementation (PkgImpl) is a morphism in Fam(KlSPComp) from the domain family to the codomain family. Fam composition is Kleisli sequencing (bind at each operation), NOT oracle substitution. See SemPkg.lean for the package category with substitution-style composition.

Linking vs composition: PkgImpl.link computes as SPComp.bind at each operation index — this is a data pipeline (first-order), not oracle resolution (second-order). Cryptographic package linking is oracle substitution, which is modeled by the Category PkgInterface in SemPkg.lean.

Parallel composition (PkgImpl.par) dispatches operations by Sum index. This IS the correct parallel composition and is shared with the package category.

Main definitions #

Semantic characterization #

SMC structure #

Since PkgInterface.tensor/unit correspond definitionally to FamObj.tensorObj/unitObj, the monoidal category laws apply directly to PkgImpl parallel composition. The full SMC structure on PkgInterface (with substitution-style composition) is in SemPkg.lean.

Package Interface #

A package interface specifies operation signatures. Each operation is indexed by ι with domain type doms i and codomain type codoms i, both living in KlSPComp (= Type, viewed as objects of the Kleisli category of SPComp).

Instances For

    The domain family as a FamObj KlSPComp.

    Equations
    Instances For

      The codomain family as a FamObj KlSPComp.

      Equations
      Instances For

        Tensor and Unit #

        Parallel combination of interfaces: index by Sum, families by Sum.elim.

        Equations
        Instances For

          The empty interface (no operations).

          Equations
          Instances For

            Correspondence with Fam's tensor and unit #

            These are all rfl because both sides expand to the same ⟨ι₁ ⊕ ι₂, Sum.elim ...⟩ (resp. ⟨Empty, Empty.elim⟩). This definitional equality is the key insight: packages inherit their SMC structure from Fam.lean with zero proof effort.

            Package Implementation #

            @[reducible, inline]

            A package implementation for interface I is a morphism in Fam(KlSPComp) from the domain family to the codomain family.

            Concretely, this consists of:

            • An equivalence σ : I.ι ≃ I.ι permuting operation indices
            • Implementations map i : I.doms i → SPComp (I.codoms (σ i)) for each operation

            When σ = id (the common case), each operation i has a direct implementation I.doms i → SPComp (I.codoms i).

            Equations
            Instances For

              Construction #

              def CatCrypt.Category.PkgImpl.ofImpls (I : PkgInterface) (impls : (i : I.ι) → I.doms iCore.SPComp (I.codoms i)) :

              Construct a package from componentwise implementations (with σ = id).

              Equations
              Instances For
                @[simp]
                theorem CatCrypt.Category.PkgImpl.ofImpls_σ (I : PkgInterface) (impls : (i : I.ι) → I.doms iCore.SPComp (I.codoms i)) :
                @[simp]
                theorem CatCrypt.Category.PkgImpl.ofImpls_map (I : PkgInterface) (impls : (i : I.ι) → I.doms iCore.SPComp (I.codoms i)) (i : I.ι) :
                (ofImpls I impls).map i = impls i

                Linking = Fam Composition (Kleisli Sequencing) #

                Note: This is Kleisli-bind composition (sequencing), not oracle substitution. At each operation i, link computes as SPComp.bind (p₁.map i x) (p₂.map (p₁.σ i)), i.e., run p₁, then feed the result into p₂. This models a data pipeline, not cryptographic package linking (which is oracle resolution — see SemPkg.lean).

                Parallel Composition = Fam Tensor #

                Parallel composition dispatches operations to the correct component:

                noncomputable def CatCrypt.Category.PkgImpl.par {I J : PkgInterface} (p₁ : PkgImpl I) (p₂ : PkgImpl J) :

                Parallel composition of packages: tensor in Fam(KlSPComp).

                Equations
                Instances For
                  @[simp]
                  theorem CatCrypt.Category.PkgImpl.par_σ_inl {I J : PkgInterface} (p₁ : PkgImpl I) (p₂ : PkgImpl J) (i : I.ι) :
                  (p₁.par p₂).σ (Sum.inl i) = Sum.inl (p₁.σ i)

                  Left operations are permuted by p₁'s permutation.

                  @[simp]
                  theorem CatCrypt.Category.PkgImpl.par_σ_inr {I J : PkgInterface} (p₁ : PkgImpl I) (p₂ : PkgImpl J) (j : J.ι) :
                  (p₁.par p₂).σ (Sum.inr j) = Sum.inr (p₂.σ j)

                  Right operations are permuted by p₂'s permutation.

                  @[simp]
                  theorem CatCrypt.Category.PkgImpl.par_map_inl {I J : PkgInterface} (p₁ : PkgImpl I) (p₂ : PkgImpl J) (i : I.ι) (x : I.doms i) :
                  (p₁.par p₂).map (Sum.inl i) x = p₁.map i x

                  At a left operation .inl i, parallel composition dispatches to p₁.

                  @[simp]
                  theorem CatCrypt.Category.PkgImpl.par_map_inr {I J : PkgInterface} (p₁ : PkgImpl I) (p₂ : PkgImpl J) (j : J.ι) (x : J.doms j) :
                  (p₁.par p₂).map (Sum.inr j) x = p₂.map j x

                  At a right operation .inr j, parallel composition dispatches to p₂.

                  SMC Laws for Parallel Composition #

                  The monoidal laws for parallel composition (tensor, associator, braiding) hold for PkgImpl via the definitional equality between PkgInterface.tensor/unit and FamObj.tensorObj/unitObj. These are inherited from Fam.lean.

                  The full symmetric monoidal category structure on PkgInterface — with substitution-style composition (oracle resolution) rather than Fam's Kleisli sequencing — is in SemPkg.lean.

                  Bridge: DeepInterface → PkgInterface #

                  Convert a DeepInterface (list-based, from the deep embedding) to a PkgInterface (family-based, for the categorical framework) via Fin indexing. Each position in the operation list becomes a Fin index.

                  Equations
                  Instances For

                    Append two deep interfaces (concatenate operation lists).

                    Equations
                    Instances For

                      The tensor of toPkgInterface corresponds to the append of DeepInterface: (I.append J).toPkgInterface and I.toPkgInterface.tensor J.toPkgInterface have the same operations, indexed by Fin (m + n) vs Fin m ⊕ Fin n respectively. The equivalence finSumFinEquiv from Mathlib connects these index types, with List.getElem_append_left/List.getElem_append_right showing the families match.