Package Category #
This file proves that CatCrypt's deep packages form a category.
Main definitions #
PkgHom I E- Semantic package morphism from interface I to interface ECategory DeepInterface- Category instance (all laws hold byrfl)DeepPackage.toPkgHom- Embedding of concrete packages into semantic morphisms
Main results #
- All three category laws (id_comp, comp_id, assoc) hold by
rfl DeepPackage.toPkgHom_id- Identity package maps to identity morphism- Tensor product of interfaces via list append
Design #
The key insight is that semantic package morphisms (PkgHom) abstract away
from concrete code representations and work purely with oracle handlers.
This gives all category laws definitionally (by rfl), following the
Kleisli category construction for the State+Prob monad.
Semantic Package Morphisms #
Semantic package morphism from interface I to interface E.
A PkgHom I E represents a package that exports operations in E and
imports operations from I. For each exported operation, given a domain
value and an oracle handler for I's operations, it produces an SPComp
computation.
This abstracts over concrete code representations (RawCode, ValidCode) and works purely at the semantic level, giving clean categorical properties.
In the Kleisli category interpretation:
- Objects are interfaces (types of operations)
- Morphisms are semantic oracle-transforming functions
- Composition is oracle handler chaining (= package linking)
- Identity forwards all operations to the handler
Equations
- One or more equations did not get rendered due to their size.
Instances For
Identity morphism: forwards each operation call to the oracle handler.
Equations
- CatCrypt.Deep.PkgHom.id I op dom codom h x handler = handler op dom codom h x
Instances For
Left identity: id ≫ f = f. Holds by eta-reduction.
Right identity: f ≫ id = f. Holds by beta-reduction.
Category Instance #
Category of deep interfaces and semantic package morphisms.
Objects are DeepInterfaces (specifying operation signatures).
Morphisms are PkgHoms (semantic oracle-transforming functions).
All three category laws (id_comp, comp_id, assoc) hold definitionally.
Equations
- One or more equations did not get rendered due to their size.
Connection to DeepPackage #
Every concrete `DeepPackage` gives rise to a semantic `PkgHom` via
evaluation. This embedding preserves the identity package structure.
Embed a concrete DeepPackage into a semantic PkgHom.
Given a package p with imports I and exports E, we get a PkgHom by
evaluating each operation's code with the provided oracle handler
via evalWith.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The identity package maps to the identity PkgHom.
The identity package implements each operation as an oracle call,
and evalWith maps oracle calls to the handler, giving identity.
Tensor Product of Interfaces #
Tensor product of interfaces: concatenation of operation lists.
Instances For
The tensor unit: empty interface with no operations.
Instances For
Tensor product is associative.
Empty interface is a left unit for tensor.
Empty interface is a right unit for tensor.
Tensor Product of Morphisms #
The tensor product of two morphisms dispatches exported operations
to the appropriate morphism and restricts oracle handlers accordingly.
This requires classical decidability since `Type u` membership in
lists is not computably decidable.
Tensor product of morphisms: parallel composition.
Given f : PkgHom I₁ E₁ and g : PkgHom I₂ E₂, produces
PkgHom (tensorObj I₁ I₂) (tensorObj E₁ E₂) by dispatching:
- Operations in E₁: handled by f (with handler restricted to I₁)
- Operations in E₂: handled by g (with handler restricted to I₂)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Left whiskering: tensor identity on the left with a morphism.
whiskerLeft X f : (X ⊗ Y₁) ⟶ (X ⊗ Y₂) for f : Y₁ ⟶ Y₂.
Operations in X are forwarded to the handler (identity);
operations in Y₂ are handled by f.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Right whiskering: tensor a morphism on the left with identity on the right.
whiskerRight f Y : (X₁ ⊗ Y) ⟶ (X₂ ⊗ Y) for f : X₁ ⟶ X₂.
Operations in X₂ are handled by f;
operations in Y are forwarded to the handler (identity).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pass-through Morphisms #
A "pass-through" morphism is one that just forwards all operations to
the oracle handler, converting membership proofs via a list equality.
This is the key building block for structural morphisms (associator,
unitors, braiding).
The crucial property: any two pass-through morphisms between the same
types are equal, by proof irrelevance on the membership proofs.
A pass-through morphism that forwards to the handler, converting membership proofs via a list equality.
Equations
- CatCrypt.Deep.PkgHom.ofOpsEq h op dom codom hE x handler = handler op dom codom ⋯ x
Instances For
Any two pass-throughs between the same types are equal.
Whisker Laws #
Whiskering on the left with the identity is the identity.
Whiskering on the right with the identity is the identity.
Monoidal Category Instance #
`DeepInterface` forms a (strict) monoidal category with:
- Tensor product = list append of operations
- Unit = empty interface
- Associator/unitors defined directly as pass-through morphisms
- All coherence axioms follow from proof irrelevance
Associator: pass-through using List.append_assoc.
Equations
- CatCrypt.Deep.assocIso X Y Z = { hom := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, inv := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, hom_inv_id := ⋯, inv_hom_id := ⋯ }
Instances For
Left unitor: pass-through using List.nil_append.
Equations
- CatCrypt.Deep.leftUnitorIso X = { hom := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, inv := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, hom_inv_id := ⋯, inv_hom_id := ⋯ }
Instances For
Right unitor: pass-through using List.append_nil.
Equations
- CatCrypt.Deep.rightUnitorIso X = { hom := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, inv := CatCrypt.Deep.PkgHom.ofOpsEq ⋯, hom_inv_id := ⋯, inv_hom_id := ⋯ }
Instances For
Monoidal Category Structure #
We provide `MonoidalCategoryStruct` (the tensor product data) and prove
the coherence axioms (pentagon, triangle) that hold unconditionally.
**Important**: The naturality axioms (`tensorHom_comp_tensorHom`,
`associator_naturality`, `braiding_naturality`) require that tensor
components have **disjoint** operation lists. This matches Rocq SSProve,
which enforces disjointness via `:|:` (disjoint union of finite maps).
With overlapping operations, `dite`-based dispatch becomes inconsistent
between left-whiskered and right-whiskered morphisms.
The coherence axioms (pentagon, triangle, hexagons, symmetry) hold
unconditionally because they involve only structural morphisms
(pass-throughs and braiding), not arbitrary morphisms `f`, `g`.
Equations
- One or more equations did not get rendered due to their size.
Unconditionally valid monoidal axioms #
Tensor of identities is identity.
Right unitor is natural.
Pentagon coherence for associators.
Triangle coherence for associator and unitors.
Braided and Symmetric Structure #
The braiding swaps the two halves of a tensor product.
Since our tensor is list append, braiding reindexes operations
via commutativity of `∨` in list membership.
Coherence axioms (hexagons, symmetry) hold unconditionally.
Naturality requires disjoint interfaces (see above).
Braiding morphism: swap the two halves of a tensor product.
Equations
- CatCrypt.Deep.PkgHom.braiding X Y op dom codom h_exp x handler = handler op dom codom ⋯ x
Instances For
Braiding composed with itself is identity (by proof irrelevance).
Braiding isomorphism: X ⊗ Y ≅ Y ⊗ X.
Equations
- CatCrypt.Deep.braidingIso X Y = { hom := CatCrypt.Deep.PkgHom.braiding X Y, inv := CatCrypt.Deep.PkgHom.braiding Y X, hom_inv_id := ⋯, inv_hom_id := ⋯ }
Instances For
Braiding is a symmetric involution.