Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
-/
Expand Down Expand Up @@ -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
Expand All @@ -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`. -/
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/ConstructiveCryptography/Instances/Algebra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down
19 changes: 18 additions & 1 deletion src/ConstructiveCryptography/Notation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
72 changes: 39 additions & 33 deletions src/ConstructiveCryptography/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -414,15 +417,18 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness

<!-- Declarations: the classes -->

[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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/ConstructiveCryptography/Tactics/Categorical.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Tests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/Tests/Axioms/CC.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading