diff --git a/src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean b/src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean index 63bce3a..cb3344b 100644 --- a/src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean +++ b/src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean @@ -43,8 +43,10 @@ Jost, §2.2 (printed pp. 16–19). * `ResourceTheory.attach_serial`, `CryptographicAlgebra.attach_parallel`: attachment is functorial and local -* `CryptographicAlgebra.parallel_assoc`, `CryptographicAlgebra.parallel_dummy_left`, - `CryptographicAlgebra.parallel_dummy_right`: parallel composition of resources +* `CryptographicAlgebra.parallel_assoc`, `CryptographicAlgebra.associator_hom_attach`, + `CryptographicAlgebra.parallel_dummy_left`, `CryptographicAlgebra.leftUnitor_hom_attach`, + `CryptographicAlgebra.parallel_dummy_right`, `CryptographicAlgebra.rightUnitor_hom_attach`: + parallel composition of resources * `CryptographicAlgebra.Specification.Constructs.serial`, `CryptographicAlgebra.Specification.Constructs.parallel`: composition of constructions -/ @@ -280,6 +282,13 @@ lemma parallel_assoc [CryptographicAlgebra C Phi] {A B D : C} (Opposite.op A) (Opposite.op B) (Opposite.op D) exact types_congr_hom associativity ((left, middle), right) +/-- Attaching `(α_ A B D).hom` regroups `left ∥ (middle ∥ right)` to `(left ∥ middle) ∥ right`. -/ +lemma associator_hom_attach [CryptographicAlgebra C Phi] {A B D : C} + (left : Phi A) (middle : Phi B) (right : Phi D) : + attach (α_ A B D).hom (parallel left (parallel middle right)) = + parallel (parallel left middle) right := by + rw [← parallel_assoc left middle right, ← attach_serial, Iso.hom_inv_id, attach_identity] + /-- The dummy resource is a left unit for resource parallel. The left unitor `λ_ A : 𝟙_ C ⊗ A ≅ A` has inverse converter `(λ_ A).inv : A ⟶ 𝟙_ C ⊗ A`; attaching it to `parallel dummy resource : Phi (𝟙_ C ⊗ A)` returns `resource : Phi A`. This is left @@ -299,6 +308,14 @@ lemma parallel_dummy_left [CryptographicAlgebra C Phi] {A : C} (LaxMonoidal.ε (ResourceTheory.functor C Phi) PUnit.unit, resource)) = resource exact types_congr_hom unitality (PUnit.unit, resource) |>.symm +/-- Attaching the forward left unitor `(λ_ A).hom` adjoins `dummy` on the left. -/ +lemma leftUnitor_hom_attach [CryptographicAlgebra C Phi] {A : C} + (resource : Phi A) : + attach (λ_ A).hom resource = + parallel (dummy (C := C)) resource := by + have h := congrArg (attach (λ_ A).hom) (parallel_dummy_left resource) + simpa only [← attach_serial, Iso.hom_inv_id, attach_identity] using h.symm + /-- The dummy resource is a right unit for resource parallel: attaching the inverse right unitor `(ρ_ A).inv : A ⟶ A ⊗ 𝟙_ C` to `parallel resource dummy : Phi (A ⊗ 𝟙_ C)` returns `resource`. This is right unitality of `laxMonoidal`. -/ @@ -317,6 +334,14 @@ lemma parallel_dummy_right [CryptographicAlgebra C Phi] {A : C} (resource, LaxMonoidal.ε (ResourceTheory.functor C Phi) PUnit.unit)) = resource exact types_congr_hom unitality (resource, PUnit.unit) |>.symm +/-- Attaching the forward right unitor `(ρ_ A).hom` adjoins `dummy` on the right. -/ +lemma rightUnitor_hom_attach [CryptographicAlgebra C Phi] {A : C} + (resource : Phi A) : + attach (ρ_ A).hom resource = + parallel resource (dummy (C := C)) := by + have h := congrArg (attach (ρ_ A).hom) (parallel_dummy_right resource) + simpa only [← attach_serial, Iso.hom_inv_id, attach_identity] using h.symm + namespace Specification /-! ### Specifications and exact construction diff --git a/src/ConstructiveCryptography/Instances/Algebra.lean b/src/ConstructiveCryptography/Instances/Algebra.lean index 3b01fad..cf62fe9 100644 --- a/src/ConstructiveCryptography/Instances/Algebra.lean +++ b/src/ConstructiveCryptography/Instances/Algebra.lean @@ -60,6 +60,9 @@ domination law needed by statistical steps of a substitution chain. * `Interface.parallel_assoc`, `Interface.parallel_dummy_left`, `Interface.parallel_dummy_right`: the lax monoidal laws through the regrouping isomorphisms +* `Interface.associator_hom_attach`, `Interface.leftUnitor_hom_attach`, + `Interface.rightUnitor_hom_attach`: the forward associator and unitor attachment laws, + instantiated from the `CryptographicAlgebra` class laws * `Interface.parallel_swap`: parallel composition is commutative through the swap * `Interface.distinguishers_attach`, `Interface.distinguishers_parallel_left`, `Interface.distinguishers_parallel_right`: closure @@ -163,6 +166,26 @@ noncomputable instance cryptographicAlgebra : ConstructiveCryptography.CryptographicAlgebra Interface TypedSystem where laxMonoidal := resourcesLaxMonoidal +/-- Forward associator regroups three parallel typed systems, from the class law. -/ +lemma associator_hom_attach {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) + (T : TypedSystem C) : + ((associator A B C).hom • TypedSystem.parallel R (TypedSystem.parallel S T) : + TypedSystem (tensor (tensor A B) C)) = + TypedSystem.parallel (TypedSystem.parallel R S) T := + ConstructiveCryptography.CryptographicAlgebra.associator_hom_attach R S T + +/-- Forward left unitor adjoins `TypedSystem.dummy` on the left, from the class law. -/ +lemma leftUnitor_hom_attach {A : Interface} (R : TypedSystem A) : + ((leftUnitor A).hom • R : TypedSystem (tensor unit A)) = + TypedSystem.parallel TypedSystem.dummy R := + ConstructiveCryptography.CryptographicAlgebra.leftUnitor_hom_attach R + +/-- Forward right unitor adjoins `TypedSystem.dummy` on the right, from the class law. -/ +lemma rightUnitor_hom_attach {A : Interface} (R : TypedSystem A) : + ((rightUnitor A).hom • R : TypedSystem (tensor A unit)) = + TypedSystem.parallel R TypedSystem.dummy := + ConstructiveCryptography.CryptographicAlgebra.rightUnitor_hom_attach R + /-- Typed distinguishers evaluate by their output-1 behavior: `probability d R = d.1 R`, the probability that `d` connected to `R` outputs `1`. -/ noncomputable instance distinguisherEvaluations : diff --git a/src/ConstructiveCryptography/Notation.lean b/src/ConstructiveCryptography/Notation.lean index f871afd..2c8c4c0 100644 --- a/src/ConstructiveCryptography/Notation.lean +++ b/src/ConstructiveCryptography/Notation.lean @@ -325,7 +325,7 @@ meta def delabTypedCCAttachment : Delab := namespace Interface -attribute [cc_normalization] comp_smul identity_attach +attribute [cc_normalization] comp_smul identity_attach associator_hom_attach -- Definitional bridges, below the laws' default priority: the categorical action and the -- `resourceTheory` attachment field left by `cc_construct` are rewritten to `α • R` with @@ -407,6 +407,23 @@ lemma distance_parallel_le {A B : Interface} ConstructiveCryptography.CryptographicAlgebra.distance_parallel_le R S T U +open Lean Meta Simp in +/-- `associator_hom_attach` whatever the spelling of the associator or tensor: `(α_ A B C).hom • +(R ∥ (S ∥ T)) = (R ∥ S) ∥ T` when the interfaces use `⊗` or `Interface.tensor`. -/ +simproc [cc_normalization] associatorHomSmul (@HSMul.hSMul _ _ _ _ _ _) := fun e => do + let_expr HSMul.hSMul _ _ _ _ f x := e | return .continue + let_expr CategoryTheory.Iso.hom _ _ _ _ iso := f | return .continue + let (A, B, C) ← match_expr iso with + | CategoryTheory.MonoidalCategoryStruct.associator _ _ _ A B C => pure (A, B, C) + | Interface.associator A B C => pure (A, B, C) + | _ => return .continue + let_expr TypedSystem.parallel _ _ R ST := x | return .continue + let_expr TypedSystem.parallel _ _ S T := ST | return .continue + let proof := mkAppN (mkConst ``Interface.associator_hom_attach) #[A, B, C, R, S, T] + let_expr Eq _ lhs rhs := ← inferType proof | return .continue + unless ← withDefault (isDefEq e lhs) do return .continue + return .visit { expr := rhs, proof? := some (← mkExpectedTypeHint proof (← mkEq e rhs)) } + end Interface -- The compatibility laws, stated with the concrete parallel composition. diff --git a/src/ConstructiveCryptography/README.md b/src/ConstructiveCryptography/README.md index 5310549..8bc8861 100644 --- a/src/ConstructiveCryptography/README.md +++ b/src/ConstructiveCryptography/README.md @@ -46,8 +46,11 @@ R \parallel S \in \Phi(A \otimes B), \qquad \mathbf 1 \in \Phi(\mathbb I), \qqua (\alpha \otimes \beta)(R \parallel S) = \alpha R \parallel \beta S . ``` -Derived: [locality][CA.attach_parallel], [associativity][CA.parallel_assoc], and the -[left][CA.parallel_dummy_left] and [right][CA.parallel_dummy_right] unit laws. +Derived: [locality][CA.attach_parallel], [associativity][CA.parallel_assoc] (and its forward +form [`associator_hom_attach`][CA.associator_hom_attach]), and the [left][CA.parallel_dummy_left] +and [right][CA.parallel_dummy_right] unit laws (with forward forms +[`leftUnitor_hom_attach`][CA.leftUnitor_hom_attach] and +[`rightUnitor_hom_attach`][CA.rightUnitor_hom_attach]). ### `CompatiblePseudoMetric C Φ`: distance @@ -414,15 +417,18 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness -[ResourceTheory]: CryptographicAlgebra/Basic.lean#L68 -[ResourceTheory.functor]: CryptographicAlgebra/Basic.lean#L102 -[CryptographicAlgebra]: CryptographicAlgebra/Basic.lean#L143 -[CA.parallel]: CryptographicAlgebra/Basic.lean#L189 -[CA.dummy]: CryptographicAlgebra/Basic.lean#L200 -[CA.attach_parallel]: CryptographicAlgebra/Basic.lean#L238 -[CA.parallel_assoc]: CryptographicAlgebra/Basic.lean#L270 -[CA.parallel_dummy_left]: CryptographicAlgebra/Basic.lean#L288 -[CA.parallel_dummy_right]: CryptographicAlgebra/Basic.lean#L306 +[ResourceTheory]: CryptographicAlgebra/Basic.lean#L70 +[ResourceTheory.functor]: CryptographicAlgebra/Basic.lean#L104 +[CryptographicAlgebra]: CryptographicAlgebra/Basic.lean#L145 +[CA.parallel]: CryptographicAlgebra/Basic.lean#L191 +[CA.dummy]: CryptographicAlgebra/Basic.lean#L202 +[CA.attach_parallel]: CryptographicAlgebra/Basic.lean#L240 +[CA.parallel_assoc]: CryptographicAlgebra/Basic.lean#L272 +[CA.associator_hom_attach]: CryptographicAlgebra/Basic.lean#L286 +[CA.parallel_dummy_left]: CryptographicAlgebra/Basic.lean#L297 +[CA.leftUnitor_hom_attach]: CryptographicAlgebra/Basic.lean#L312 +[CA.parallel_dummy_right]: CryptographicAlgebra/Basic.lean#L323 +[CA.rightUnitor_hom_attach]: CryptographicAlgebra/Basic.lean#L338 [CompatiblePseudoMetric]: CryptographicAlgebra/PseudoMetric.lean#L63 [CA.distance]: CryptographicAlgebra/PseudoMetric.lean#L99 [distance_attach_le]: CryptographicAlgebra/PseudoMetric.lean#L131 @@ -443,13 +449,13 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness [Interface.identity_attach]: Instances/Category.lean#L56 [Interface.comp_smul]: Instances/Category.lean#L61 [Interface.monoidal]: Instances/Monoidal.lean#L166 -[Interface.resourceTheory]: Instances/Algebra.lean#L83 -[Interface.cryptographicAlgebra]: Instances/Algebra.lean#L162 -[Interface.transcriptDistance_eq_advantageDistance]: Instances/Algebra.lean#L220 -[Interface.compatibleDistinguisherClass]: Instances/Algebra.lean#L242 -[Interface.cc_parallel_eq]: Instances/Algebra.lean#L269 -[Interface.cc_dummy_eq]: Instances/Algebra.lean#L273 -[Interface.cc_distance_eq]: Instances/Algebra.lean#L278 +[Interface.resourceTheory]: Instances/Algebra.lean#L86 +[Interface.cryptographicAlgebra]: Instances/Algebra.lean#L165 +[Interface.transcriptDistance_eq_advantageDistance]: Instances/Algebra.lean#L243 +[Interface.compatibleDistinguisherClass]: Instances/Algebra.lean#L265 +[Interface.cc_parallel_eq]: Instances/Algebra.lean#L292 +[Interface.cc_dummy_eq]: Instances/Algebra.lean#L296 +[Interface.cc_distance_eq]: Instances/Algebra.lean#L301 [TypedSystem.transcriptPseudoEMetricSpace]: ../RandomSystems/Typed/Distance.lean#L26 [RandomSystem.transcriptDistance_eq_iSup_behavior]: ../RandomSystems/Distance/Distinguisher.lean#L250 [Interface.games]: Instances/Game.lean#L54 @@ -471,11 +477,11 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness [Specification]: Specification/Defs.lean#L30 [Specification.Constructs]: Specification/Basic.lean#L45 [Specification.ConstructsWithin]: Specification/Metric.lean#L49 -[CA.Specification.Constructs]: CryptographicAlgebra/Basic.lean#L493 +[CA.Specification.Constructs]: CryptographicAlgebra/Basic.lean#L518 [CA.Specification.ConstructsWithin]: CryptographicAlgebra/PseudoMetric.lean#L265 -[Constructs.serial]: CryptographicAlgebra/Basic.lean#L583 +[Constructs.serial]: CryptographicAlgebra/Basic.lean#L608 [ConstructsWithin.serial]: CryptographicAlgebra/PseudoMetric.lean#L335 -[Constructs.parallel]: CryptographicAlgebra/Basic.lean#L682 +[Constructs.parallel]: CryptographicAlgebra/Basic.lean#L707 [ConstructsWithin.parallel]: CryptographicAlgebra/PseudoMetric.lean#L363 [Relaxation]: Specification/Relaxation/Defs.lean#L46 [Relaxation.Compatible]: CryptographicAlgebra/Relaxation.lean#L69 @@ -520,9 +526,9 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness [Domain.DistinguisherBehavior]: ../RandomSystems/Distance/Distinguisher.lean#L211 [DistinguisherBehavior.advantage_le_transcriptDistance]: ../RandomSystems/Distance/Distinguisher.lean#L242 [DistinguisherBehavior.absorb]: ../RandomSystems/Distance/Distinguisher.lean#L295 -[Interface.distinguisherEvaluations]: Instances/Algebra.lean#L168 -[Interface.distinguisherAction]: Instances/Algebra.lean#L174 -[Interface.distinguisherAdvantageDominated]: Instances/Algebra.lean#L296 +[Interface.distinguisherEvaluations]: Instances/Algebra.lean#L191 +[Interface.distinguisherAction]: Instances/Algebra.lean#L197 +[Interface.distinguisherAdvantageDominated]: Instances/Algebra.lean#L319 [DistinguisherAdvantage]: Distinguisher.lean#L58 [Distinguishers]: Distinguisher.lean#L93 [AdmissibleDistinguishers]: Distinguisher.lean#L104 @@ -555,21 +561,21 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness [Interface]: ../RandomSystems/Typed/Interface.lean#L41 [Interface.associator]: Instances/Monoidal.lean#L56 [Interface.associator_naturality]: Instances/Monoidal.lean#L96 -[Interface.distinguishers]: Instances/Algebra.lean#L183 -[Interface.distinguishers_attach]: Instances/Algebra.lean#L188 -[Interface.distinguishers_parallel_left]: Instances/Algebra.lean#L194 -[Interface.distinguishers_parallel_right]: Instances/Algebra.lean#L211 +[Interface.distinguishers]: Instances/Algebra.lean#L206 +[Interface.distinguishers_attach]: Instances/Algebra.lean#L211 +[Interface.distinguishers_parallel_left]: Instances/Algebra.lean#L217 +[Interface.distinguishers_parallel_right]: Instances/Algebra.lean#L234 [Interface.id_tensor_id]: Instances/Monoidal.lean#L88 [Interface.isoOf]: Instances/Monoidal.lean#L37 [Interface.leftUnitor]: Instances/Monoidal.lean#L61 [Interface.leftUnitor_naturality]: Instances/Monoidal.lean#L101 [Interface.monoidalStruct]: Instances/Monoidal.lean#L75 -[Interface.parallel_assoc]: Instances/Algebra.lean#L97 -[Interface.parallel_dummy_left]: Instances/Algebra.lean#L109 -[Interface.parallel_dummy_right]: Instances/Algebra.lean#L118 -[Interface.parallel_swap]: Instances/Algebra.lean#L127 +[Interface.parallel_assoc]: Instances/Algebra.lean#L100 +[Interface.parallel_dummy_left]: Instances/Algebra.lean#L112 +[Interface.parallel_dummy_right]: Instances/Algebra.lean#L121 +[Interface.parallel_swap]: Instances/Algebra.lean#L130 [Interface.pentagon]: Instances/Monoidal.lean#L109 -[Interface.resourcesLaxMonoidal]: Instances/Algebra.lean#L136 +[Interface.resourcesLaxMonoidal]: Instances/Algebra.lean#L139 [Interface.rightUnitor]: Instances/Monoidal.lean#L65 [Interface.rightUnitor_naturality]: Instances/Monoidal.lean#L105 [Interface.solvers]: Instances/Game.lean#L48 diff --git a/src/ConstructiveCryptography/Tactics/Categorical.lean b/src/ConstructiveCryptography/Tactics/Categorical.lean index 26f857d..915e455 100644 --- a/src/ConstructiveCryptography/Tactics/Categorical.lean +++ b/src/ConstructiveCryptography/Tactics/Categorical.lean @@ -21,6 +21,15 @@ typed attachment and ordered context laws provide the heterogeneous theorem heads used here; no symmetry or implicit interface rearrangement is assumed. -/ +open CategoryTheory MonoidalCategory ConstructiveCryptography in +/-- The associator regroups three resources. This spelling lets `cc_normalize` match `•` +directly when the resource carrier is abstract. -/ +@[cc_normalization] public lemma ConstructiveCryptography.CryptographicAlgebra.associator_hom_smul + {C : Type*} [Category* C] [MonoidalCategory C] {Φ : C → Type*} + [ResourceTheory C Φ] [CryptographicAlgebra C Φ] {A B D : C} (L : Φ A) (M : Φ B) (R : Φ D) : + (α_ A B D).hom • parallel L (parallel M R) = parallel (parallel L M) R := + associator_hom_attach L M R + @[expose] public meta section namespace ConstructiveCryptography @@ -31,6 +40,7 @@ attribute [cc_normalization] CryptographicAlgebra.converter_parallel_identity CryptographicAlgebra.converter_parallel_serial CryptographicAlgebra.attach_parallel + CryptographicAlgebra.associator_hom_attach CryptographicAlgebra.Specification.parallel_singleton CryptographicAlgebra.Specification.star_idem CategoryTheory.Category.id_comp diff --git a/src/Tests.lean b/src/Tests.lean index 2aa0e7e..74f628c 100644 --- a/src/Tests.lean +++ b/src/Tests.lean @@ -91,6 +91,7 @@ public import Tests.RandomFunctionCollision public import Tests.RatioCost public import Tests.FilteredRatio public import Tests.CompositeNotation +public import Tests.ParallelCoherenceHom /-! Axiom audits per layer and of the Commons library, the checks of the authenticated-encryption example, diff --git a/src/Tests/Axioms/CC.lean b/src/Tests/Axioms/CC.lean index c62f447..8db4aa8 100644 --- a/src/Tests/Axioms/CC.lean +++ b/src/Tests/Axioms/CC.lean @@ -14,8 +14,11 @@ on interfaces, depend only on `propext`, `Classical.choice` and `Quot.sound`. -- ConstructiveCryptography.CryptographicAlgebra.Basic #print axioms ConstructiveCryptography.CryptographicAlgebra.attach_parallel #print axioms ConstructiveCryptography.CryptographicAlgebra.parallel_assoc +#print axioms ConstructiveCryptography.CryptographicAlgebra.associator_hom_attach #print axioms ConstructiveCryptography.CryptographicAlgebra.parallel_dummy_left +#print axioms ConstructiveCryptography.CryptographicAlgebra.leftUnitor_hom_attach #print axioms ConstructiveCryptography.CryptographicAlgebra.parallel_dummy_right +#print axioms ConstructiveCryptography.CryptographicAlgebra.rightUnitor_hom_attach #print axioms ConstructiveCryptography.CryptographicAlgebra.Specification.Constructs.serial #print axioms ConstructiveCryptography.CryptographicAlgebra.Specification.Constructs.parallel @@ -62,8 +65,11 @@ on interfaces, depend only on `propext`, `Classical.choice` and `Quot.sound`. -- ConstructiveCryptography.Instances.Algebra, continued #print axioms SystemAlgebra.Interface.distinguisherAdvantageDominated #print axioms SystemAlgebra.Interface.parallel_assoc +#print axioms SystemAlgebra.Interface.associator_hom_attach #print axioms SystemAlgebra.Interface.parallel_dummy_left +#print axioms SystemAlgebra.Interface.leftUnitor_hom_attach #print axioms SystemAlgebra.Interface.parallel_dummy_right +#print axioms SystemAlgebra.Interface.rightUnitor_hom_attach #print axioms SystemAlgebra.Interface.parallel_swap -- ConstructiveCryptography.Instances.Category diff --git a/src/Tests/ParallelCoherenceHom.lean b/src/Tests/ParallelCoherenceHom.lean new file mode 100644 index 0000000..b0cd7c4 --- /dev/null +++ b/src/Tests/ParallelCoherenceHom.lean @@ -0,0 +1,120 @@ +module + +public import ConstructiveCryptography.Notation +public import RandomSystems.Typed.Functional + +/-! +# Forward associator and unitor attachment laws + +Consumer tests for `CryptographicAlgebra.{associator_hom_attach, leftUnitor_hom_attach, +rightUnitor_hom_attach}` in an arbitrary cryptographic algebra, and for their one-line +interface instances `Interface.{associator_hom_attach, leftUnitor_hom_attach, +rightUnitor_hom_attach}` regrouping three typed systems side by side through the associator. +-/ + +@[expose] public section + +set_option autoImplicit false + +namespace Tests.ParallelCoherenceHom + +open CategoryTheory MonoidalCategory +open ConstructiveCryptography ConstructiveCryptography.CryptographicAlgebra + +section Abstract + +open scoped SystemAlgebra + +universe u v w + +variable {C : Type u} [Category.{v} C] [MonoidalCategory C] +variable {Phi : C → Type w} [ResourceTheory C Phi] [CryptographicAlgebra C Phi] + +/-- Forward associator regroups three resources in any cryptographic algebra. -/ +example {A B D : C} (L : Phi A) (M : Phi B) (R : Phi D) : + (α_ A B D).hom • parallel L (parallel M R) = parallel (parallel L M) R := + associator_hom_attach L M R + +/-- `cc_normalize` regroups three resources through `(α_ A B D).hom` in any algebra. -/ +example {A B D : C} (L : Phi A) (M : Phi B) (R : Phi D) : + attach (α_ A B D).hom (parallel L (parallel M R)) = parallel (parallel L M) R := by + cc_normalize + +/-- The same regrouping is automatic in the public attachment and parallel notation. -/ +example {A B D : C} (L : Phi A) (M : Phi B) (R : Phi D) : + (α_ A B D).hom • (L ∥ (M ∥ R)) = (L ∥ M) ∥ R := by + cc_normalize + +/-- A converter `f` with the same source and target needs its own regrouping law. -/ +example {A B D : C} (f : (A ⊗ B) ⊗ D ⟶ A ⊗ (B ⊗ D)) (L : Phi A) (M : Phi B) (R : Phi D) + (h : f • (L ∥ (M ∥ R)) = (L ∥ M) ∥ R) : + f • (L ∥ (M ∥ R)) = (α_ A B D).hom • (L ∥ (M ∥ R)) := by + cc_normalize + guard_target =ₛ f • (L ∥ (M ∥ R)) = (L ∥ M) ∥ R + exact h + +/-- Forward left unitor places `dummy` on the left in any cryptographic algebra. -/ +example {A : C} (R : Phi A) : + (λ_ A).hom • R = parallel (dummy (C := C)) R := + leftUnitor_hom_attach R + +/-- Forward right unitor places `dummy` on the right in any cryptographic algebra. -/ +example {A : C} (R : Phi A) : + (ρ_ A).hom • R = parallel R (dummy (C := C)) := + rightUnitor_hom_attach R + +end Abstract + +section Interfaces + +open SystemAlgebra +open scoped SystemAlgebra + +/-- Forward left unitor on interfaces places `TypedSystem.dummy` on the left. -/ +example {A : Interface} (R : TypedSystem A) : + (Interface.leftUnitor A).hom • R = TypedSystem.dummy ∥ R := + Interface.leftUnitor_hom_attach R + +/-- Forward right unitor on interfaces places `TypedSystem.dummy` on the right. -/ +example {A : Interface} (R : TypedSystem A) : + (Interface.rightUnitor A).hom • R = R ∥ TypedSystem.dummy := + Interface.rightUnitor_hom_attach R + +/-- Forward associator regroups three typed systems side by side on arbitrary interfaces. -/ +example {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) (T : TypedSystem C) : + (Interface.associator A B C).hom • (R ∥ (S ∥ T)) = (R ∥ S) ∥ T := + Interface.associator_hom_attach R S T + +/-- `cc_normalize` regroups three typed systems through `Interface.associator`. -/ +example {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) (T : TypedSystem C) : + (Interface.associator A B C).hom • (R ∥ (S ∥ T)) = (R ∥ S) ∥ T := by + cc_normalize + +/-- `cc_normalize` regroups three typed systems through `(α_ A B C).hom`. -/ +example {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) (T : TypedSystem C) : + (α_ A B C).hom • (R ∥ (S ∥ T)) = (R ∥ S) ∥ T := by + cc_normalize + +/-- Three concrete one-query deterministic systems regrouped side by side through `(α_ A B C).hom` +(negation on `Bool`, constant `()` on `Unit`, and identity on `Bool`). -/ +example : + let A := Interface.queryBudget Unit (fun _ => Bool) (fun _ => Bool) 1 + let B := Interface.queryBudget Unit (fun _ => Unit) (fun _ => Unit) 1 + let C := Interface.queryBudget Unit (fun _ => Bool) (fun _ => Bool) 1 + let R : TypedSystem A := TypedSystem.ofFunction fun _ b => !b + let S : TypedSystem B := TypedSystem.ofFunction fun _ u => u + let T : TypedSystem C := TypedSystem.ofFunction fun _ b => b + (α_ A B C).hom • (R ∥ (S ∥ T)) = (R ∥ S) ∥ T := by + intro A B C R S T + exact Interface.associator_hom_attach R S T + +end Interfaces + +#print axioms ConstructiveCryptography.CryptographicAlgebra.associator_hom_attach +#print axioms ConstructiveCryptography.CryptographicAlgebra.leftUnitor_hom_attach +#print axioms ConstructiveCryptography.CryptographicAlgebra.rightUnitor_hom_attach +#print axioms SystemAlgebra.Interface.associator_hom_attach +#print axioms SystemAlgebra.Interface.leftUnitor_hom_attach +#print axioms SystemAlgebra.Interface.rightUnitor_hom_attach + +end Tests.ParallelCoherenceHom