Documentation

CatCryptCore.Bridge.MonoidalBridge

Monoidal Bridge: DeepPackage ↔ PkgInterface SMC #

This file connects the concrete package operations (DeepPackage.par, link) to the symmetric monoidal category on PkgInterface (from SemPkg.lean).

Main Results #

Architecture #

The PkgInterface SMC (from SemPkg.lean) uses Sum-indexed families with definitional coherence (funext + cases + rfl). The concrete DeepInterface uses List-indexed families with diAppend = List.append as tensor.

The key difficulty: Fin (m + n) vs Fin m ⊕ Fin n. The tensorAppendIso bridges this gap using castKl' (proof-irrelevant transport on Kleisli arrows) with the roundtrip proofs handled by castKl'_castKl'_symm and castKl'_dep_fn (dependent function transport).

Family Correspondence #

Type-level cast for operation families #

noncomputable def CatCrypt.Bridge.MonoidalBridge.castKl' {t₁ t₂ : ℕ × Type × Type} (h : t₁ = t₂) (f : t₁.2.1 → Core.SPComp t₁.2.2) :
t₂.2.1 → Core.SPComp t₂.2.2

Transport a Kleisli arrow along an equality of operation triples. Defined via ▸ (Eq.mpr), so the transport is proof-irrelevant in h.

Equations
Instances For
    @[simp]
    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_rfl {t : ℕ × Type × Type} (f : t.2.1 → Core.SPComp t.2.2) :
    castKl' ⋯ f = f
    @[simp]
    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_castKl'_symm {t₁ t₂ : ℕ × Type × Type} (h₁ : t₁ = t₂) (h₂ : t₂ = t₁) (f : t₁.2.1 → Core.SPComp t₁.2.2) :
    castKl' h₂ (castKl' h₁ f) = f
    @[simp]
    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_trans {t₁ t₂ t₃ : ℕ × Type × Type} (h₁ : t₁ = t₂) (h₂ : t₂ = t₃) (f : t₁.2.1 → Core.SPComp t₁.2.2) :
    castKl' h₂ (castKl' h₁ f) = castKl' ⋯ f
    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_dep_fn {ι : Type} {F : ι → ℕ × Type × Type} {a b : ι} (hab : a = b) (f : (i : ι) → (F i).2.1 → Core.SPComp (F i).2.2) (eq : F a = F b) :
    castKl' eq (f a) = f b

    A dependent function application transports correctly along castKl'. If a = b as indices and eq is the induced operation equality, then castKl' eq (f a) = f b.

    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_dep_fn_congr {ι : Type} {F : ι → ℕ × Type × Type} {t : ℕ × Type × Type} {a b : ι} (hab : a = b) (f : (i : ι) → (F i).2.1 → Core.SPComp (F i).2.2) (eq_a : F a = t) (eq_b : F b = t) :
    castKl' eq_a (f a) = castKl' eq_b (f b)

    Two castKl' applications to the same target agree when the indices are equal.

    theorem CatCrypt.Bridge.MonoidalBridge.castKl'_dep_fn_sum {ιL ιR : Type} {F : ιL ⊕ ιR → ℕ × Type × Type} {a b : ιL ⊕ ιR} (hab : a = b) (f : (k : ιL ⊕ ιR) → (F k).2.1 → Core.SPComp (F k).2.2) (eq : F a = F b) :
    castKl' eq (f a) = f b

    Sum-indexed variant of castKl'_dep_fn.

    Tensor-Append Isomorphism #

    Inverse: handler for toPI I ⊗ toPI J → handler for diAppend I J.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      The tensor-append isomorphism in the PkgInterface category.

      This is the fundamental bridge between DeepInterface.append (list concat, Fin-indexed) and PkgInterface.tensor (Sum-indexed).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Unit Correspondence #

        The empty deep interface maps to the monoidal unit.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Structural Properties of diAppend #

          diAppend is associative: (I ++ J) ++ K = I ++ (J ++ K) as DeepInterfaces.

          The PkgInterface iso induced by associativity of diAppend.

          Equations
          Instances For

            Coherence #

            The associator pentagon: the two paths from toPI((I++J)++K) to toPI I ⊗ (toPI J ⊗ toPI K) commute.

            Note: The proof requires unfolding eqToHom (from appendAssocIso) into explicit castKl' form. The approach is:

            1. Define appendAssocIso explicitly via castKl' (like tensorAppendIso)
            2. Use castKl'_trans + castKl'_dep_fn + proof irrelevance Both paths compute castKl' at the same Fin.val index with propositionally equal operation triples, so the casts agree by proof irrelevance.
            theorem CatCrypt.Bridge.MonoidalBridge.eqToHom_handler {I J : Deep.DeepInterface} (h_eq : I = J) (handler : Category.TypedHandler (toPI I)) :
            CategoryTheory.eqToHom ⋯ handler = h_eq ▸ handler

            eqToHom on PkgInterface acts as ▸ (transport) on handlers.

            theorem CatCrypt.Bridge.MonoidalBridge.handler_transport_apply {I J : Deep.DeepInterface} (h_eq : I = J) (handler : Category.TypedHandler (toPI I)) (k : (toPI J).ι) :
            (h_eq ▸ handler) k = castKl' ⋯ (handler ⟨↑k, ⋯⟩)

            Transport of a handler along a DeepInterface equality is pointwise identity up to castKl' at the same Fin.val.

            Linking = Categorical Composition #

            toSemPkg maps DeepPackage.link to composition in Category DeepInterface. This is the fundamental functoriality theorem connecting the concrete package operation to the categorical structure.

            Note: toSemPkg is NOT a strict functor — it does not preserve identity exactly. toSemPkg(DeepPackage.id I) returns fail on non-interface operations, while 𝟙 I = SemPkg.id I passes them through. Identity is only preserved on interface operations (see toSemPkg_id_mem and evalImpl_link_id_left/right).

            theorem CatCrypt.Bridge.MonoidalBridge.SemPkg.resolve_transport {I₁ I₂ : Deep.DeepInterface} {I_exp : Deep.DeepInterface} (h : I₁ = I₂) (s : SemPkg I₁ I_exp) :

            Transport of a SemPkg along an import equality preserves resolve.

            eqToHom in Category DeepInterface preserves resolve.

            Unitor Coherence #

            The unitor bridges: the two paths from toPI(I ++ ⟨[]⟩) to toPI(I) via (1) the append-empty iso, or (2) tensor-append iso + unitIso + monoidal unitor, are equal. Similarly for the left unitor.

            Right unitor coherence: the two paths from toPI(I ++ ⟨[]⟩) to toPI(I) agree. Path 1: toPI(I++⟨[]⟩) → toPI(I) ⊗ toPI(⟨[]⟩) → toPI(I) ⊗ 𝟙_ → toPI(I) Path 2: toPI(I++⟨[]⟩) → toPI(I) directly via appendEmptyRightIso.

            Left unitor coherence: the two paths from toPI(⟨[]⟩ ++ I) to toPI(I) agree. Path 1: toPI(⟨[]⟩++I) → toPI(⟨[]⟩) ⊗ toPI(I) → 𝟙_ ⊗ toPI(I) → toPI(I) Path 2: toPI(⟨[]⟩++I) → toPI(I) directly via appendEmptyLeftIso.

            Braiding Bridge #

            Braiding bridge: composing the tensor-append iso with braiding and the inverse tensor-append iso gives the concrete swap.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For