Skip to content
Open
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
144 changes: 130 additions & 14 deletions src/ConstructiveCryptography/Instances/Algebra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module
public import RandomSystems.Typed.Distinguisher
public import ConstructiveCryptography.CryptographicAlgebra.DistinguisherAction
public import RandomSystems.Distance.RevealedHCoefficient
public import RandomSystems.Typed.Context
public import RandomSystems.Typed.ParallelAttachment
public import RandomSystems.Typed.SystemCoherence
public import RandomSystems.Typed.Distance
Expand Down Expand Up @@ -70,6 +71,13 @@ domination law needed by statistical steps of a substitution chain.
* `Interface.cc_distance_eq`: the distance is the transcript distance of the random systems, by
definition
* `Interface.distance_le_of_hCoefficient`: an H-coefficient argument bounds the distance
* `Interface.projectLeft_eq`, `Interface.projectRight_eq`, `Interface.projectLeft_smul_parallel`,
`Interface.projectRight_smul_parallel`, `Interface.projectLeft_smul_sample_parallel`,
`Interface.projectRight_smul_sample_parallel`, `Interface.projectLeft_comp_tensor`,
`Interface.projectLeft_comp_whiskerRight`, `Interface.projectRight_comp_tensor`,
`Interface.projectRight_comp_whiskerLeft`, `Interface.projectLeft_smul_tensor_smul`,
`Interface.projectRight_smul_tensor_smul`: instance-level laws of `TypedConverter.projectLeft` and
`TypedConverter.projectRight`
-/

@[expose] public section
Expand Down Expand Up @@ -107,22 +115,12 @@ lemma parallel_assoc {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B)
simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id]

lemma parallel_dummy_left {A : Interface} (R : TypedSystem A) :
((leftUnitor A).inv • TypedSystem.parallel TypedSystem.dummy R : TypedSystem A) = R := by
apply Subtype.ext
apply RandomSystem.ext
intro h
simp only [leftUnitor, isoOf]
rw [TypedConverter.rename_mass, TypedSystem.parallel_unit_left_mass]
simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id]
((leftUnitor A).inv • TypedSystem.parallel TypedSystem.dummy R : TypedSystem A) = R :=
TypedConverter.leftUnitor_inv_attach R

lemma parallel_dummy_right {A : Interface} (R : TypedSystem A) :
((rightUnitor A).inv • TypedSystem.parallel R TypedSystem.dummy : TypedSystem A) = R := by
apply Subtype.ext
apply RandomSystem.ext
intro h
simp only [rightUnitor, isoOf]
rw [TypedConverter.rename_mass, TypedSystem.parallel_unit_right_mass]
simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id]
((rightUnitor A).inv • TypedSystem.parallel R TypedSystem.dummy : TypedSystem A) = R :=
TypedConverter.rightUnitor_inv_attach R

lemma parallel_swap {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) :
((swap A B).hom • TypedSystem.parallel S R : TypedSystem (tensor A B)) =
Expand Down Expand Up @@ -303,4 +301,122 @@ noncomputable instance distinguisherAdvantageDominated
rw [cc_distance_eq]
exact d.advantage_le_transcriptDistance R S

/-- In the monoidal category of interfaces, `projectLeft A B` is
`(ρ_ A).inv ≫ (𝟙 A ⊗ₘ discard B)`. -/
lemma projectLeft_eq
-- `A` is the retained outside interface; `B` is the hidden parallel component.
(A B : Interface) :
(TypedConverter.projectLeft A B : A ⟶ A ⊗ B) =
(ρ_ A).inv ≫ (𝟙 A ⊗ₘ TypedConverter.discard B) := rfl

/-- In the monoidal category of interfaces, `projectRight A B` is
`(λ_ B).inv ≫ (discard A ⊗ₘ 𝟙 B)`. -/
lemma projectRight_eq
-- `A` is the hidden parallel component; `B` is the retained outside interface.
(A B : Interface) :
(TypedConverter.projectRight A B : B ⟶ A ⊗ B) =
(λ_ B).inv ≫ (TypedConverter.discard A ⊗ₘ 𝟙 B) := rfl

/-- Projecting the left component of a parallel resource returns `R`. -/
lemma projectLeft_smul_parallel
-- `R` on `A` is retained; `S` on `B` is discarded.
{A B : Interface} (R : TypedSystem A) (S : TypedSystem B) :
TypedConverter.projectLeft A B •
ConstructiveCryptography.CryptographicAlgebra.parallel R S = R :=
TypedConverter.projectLeft_smul_parallel R S

/-- Projecting the right component of a parallel resource returns `S`. -/
lemma projectRight_smul_parallel
-- `R` on `A` is discarded; `S` on `B` is retained.
{A B : Interface} (R : TypedSystem A) (S : TypedSystem B) :
TypedConverter.projectRight A B •
ConstructiveCryptography.CryptographicAlgebra.parallel R S = S :=
TypedConverter.projectRight_smul_parallel R S

/-- Projecting the left component of a sampled parallel resource preserves the retained draw
`k ← P` and returns `TypedSystem.sample P R`. -/
lemma projectLeft_smul_sample_parallel
-- `A`, `B` are the ordered component interfaces; `K` carries the shared initial draw.
{A B : Interface} {K : Type}
-- `P` is the normalized law drawn once before interaction.
(P : Probability.Distribution K) [Probability.Distribution.IsProbability P]
-- `R k` is retained and `S k` is discarded for that draw `k`.
(R : K → TypedSystem A) (S : K → TypedSystem B) :
TypedConverter.projectLeft A B • TypedSystem.sample P (fun k =>
ConstructiveCryptography.CryptographicAlgebra.parallel (R k) (S k)) =
TypedSystem.sample P R :=
TypedConverter.projectLeft_smul_sample_parallel P R S

/-- Projecting the right component of a sampled parallel resource preserves the retained draw
`k ← P` and returns `TypedSystem.sample P S`. -/
lemma projectRight_smul_sample_parallel
-- `A`, `B` are the ordered component interfaces; `K` carries the shared initial draw.
{A B : Interface} {K : Type}
-- `P` is the normalized law drawn once before interaction.
(P : Probability.Distribution K) [Probability.Distribution.IsProbability P]
-- `R k` is discarded and `S k` is retained for that draw `k`.
(R : K → TypedSystem A) (S : K → TypedSystem B) :
TypedConverter.projectRight A B • TypedSystem.sample P (fun k =>
ConstructiveCryptography.CryptographicAlgebra.parallel (R k) (S k)) =
TypedSystem.sample P S :=
TypedConverter.projectRight_smul_sample_parallel P R S

/-- Naturality of `projectLeft` under tensor of arrows:
`projectLeft A B ≫ (α ⊗ₘ β) = α ≫ projectLeft A' B'`. -/
lemma projectLeft_comp_tensor
-- `A`, `A'` are the retained interfaces of `α`; `B`, `B'` are the hidden interfaces of `β`.
{A A' B B' : Interface} (α : A ⟶ A') (β : B ⟶ B') :
(TypedConverter.projectLeft A B : A ⟶ A ⊗ B) ≫ (α ⊗ₘ β) =
α ≫ (TypedConverter.projectLeft A' B' : A' ⟶ A' ⊗ B') :=
TypedConverter.projectLeft_comp_parallel α β

/-- Left projection commutes with a converter `α` on the retained component:
`projectLeft A B ≫ (α ⊗ₘ 𝟙 B) = α ≫ projectLeft A' B`. -/
lemma projectLeft_comp_whiskerRight
-- `A`, `A'` are the outside and inside interfaces of `α`; `B` is the hidden component.
{A A' B : Interface} (α : A ⟶ A') :
(TypedConverter.projectLeft A B : A ⟶ A ⊗ B) ≫ (α ⊗ₘ 𝟙 B) =
α ≫ (TypedConverter.projectLeft A' B : A' ⟶ A' ⊗ B) :=
TypedConverter.projectLeft_comp_parallel_id α

/-- Naturality of `projectRight` under tensor of arrows:
`projectRight A B ≫ (α ⊗ₘ β) = β ≫ projectRight A' B'`. -/
lemma projectRight_comp_tensor
-- `A`, `A'` are the hidden interfaces of `α`; `B`, `B'` are the retained interfaces of `β`.
{A A' B B' : Interface} (α : A ⟶ A') (β : B ⟶ B') :
(TypedConverter.projectRight A B : B ⟶ A ⊗ B) ≫ (α ⊗ₘ β) =
β ≫ (TypedConverter.projectRight A' B' : B' ⟶ A' ⊗ B') :=
TypedConverter.projectRight_comp_parallel α β

/-- Right projection commutes with a converter `β` on the retained component:
`projectRight A B ≫ (𝟙 A ⊗ₘ β) = β ≫ projectRight A B'`. -/
lemma projectRight_comp_whiskerLeft
-- `A` is the hidden component; `B`, `B'` are the outside and inside interfaces of `β`.
{A B B' : Interface} (β : B ⟶ B') :
(TypedConverter.projectRight A B : B ⟶ A ⊗ B) ≫ (𝟙 A ⊗ₘ β) =
β ≫ (TypedConverter.projectRight A B' : B' ⟶ A ⊗ B') :=
TypedConverter.projectRight_comp_parallel_id β

/-- Attaching `α ⊗ₘ β` before `projectLeft A B` equals attaching `α` after `projectLeft A' B'`,
for any (possibly correlated) typed system `T` on `A' ⊗ B'`. -/
lemma projectLeft_smul_tensor_smul
-- `A`, `A'` are the retained interfaces and `B`, `B'` the hidden interfaces.
{A A' B B' : Interface}
-- `α` acts on the retained side, `β` on the hidden side, and `T` is any joint system.
(α : A ⟶ A') (β : B ⟶ B') (T : TypedSystem (A' ⊗ B')) :
TypedConverter.projectLeft A B • ((α ⊗ₘ β) • T) =
α • (TypedConverter.projectLeft A' B' • T) :=
TypedConverter.projectLeft_smul_parallel_smul α β T

/-- Attaching `α ⊗ₘ β` before `projectRight A B` equals attaching `β` after `projectRight A' B'`,
for any (possibly correlated) typed system `T` on `A' ⊗ B'`. -/
lemma projectRight_smul_tensor_smul
-- `A`, `A'` are the hidden interfaces and `B`, `B'` the retained interfaces.
{A A' B B' : Interface}
-- `α` acts on the hidden side, `β` on the retained side, and `T` is any joint system.
(α : A ⟶ A') (β : B ⟶ B') (T : TypedSystem (A' ⊗ B')) :
TypedConverter.projectRight A B • ((α ⊗ₘ β) • T) =
β • (TypedConverter.projectRight A' B' • T) :=
TypedConverter.projectRight_smul_parallel_smul α β T

end SystemAlgebra.Interface
32 changes: 31 additions & 1 deletion src/ConstructiveCryptography/Notation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ instances. This frontend also accepts direct typed systems and converters in `Δ
metric or composition. Direct typed operations print in the same notation when the selected
instances agree.

`cc_normalize` applies the serial, parallel and sampling laws:
`cc_normalize` applies the serial, parallel, projection and sampling laws:

* `(α ⊗ₘ β) • (R ∥ S) = α • R ∥ β • S`;
* `TypedConverter.projectLeft A B • (R ∥ S) = R` and
`TypedConverter.projectRight A B • (R ∥ S) = S`;
* `α • sample P R = sample P (fun s => α • R s)` for normalized `P`;
* `(⨂ₘ k, α k) • (∥ k, R k) = ∥ k, α k • R k`.

Expand Down Expand Up @@ -342,6 +344,8 @@ attribute [cc_normalization]
TypedConverter.parallel_attach
TypedConverter.parallelAll_attach
TypedConverter.parallelAllContext_smul
TypedConverter.projectLeft_smul_parallel
TypedConverter.projectRight_smul_parallel

-- Hoist samples after structural attachment, so serial composition exposes a component's owner.
attribute [cc_normalization 900] TypedConverter.smul_sample
Expand All @@ -366,6 +370,32 @@ simproc [cc_normalization] tensorSmul (@HSMul.hSMul _ _ _ _ _ _) := fun e => do
unless ← withDefault (isDefEq e lhs) do return .continue
return .visit { expr := rhs, proof? := some (← mkExpectedTypeHint proof (← mkEq e rhs)) }

open Lean Meta Simp in
/-- `projectLeft_smul_parallel` whatever the spelling of the interfaces: the action of
`TypedConverter.projectLeft A B` on `R ∥ S`, with types written through `⊗` or `Interface.tensor`,
returns `R`. -/
simproc [cc_normalization] projectLeftSmul (@HSMul.hSMul _ _ _ _ _ _) := fun e => do
let_expr HSMul.hSMul _ _ _ _ f x := e | return .continue
let_expr TypedConverter.projectLeft A B := f | return .continue
let_expr TypedSystem.parallel _ _ R S := x | return .continue
let proof := mkAppN (mkConst ``TypedConverter.projectLeft_smul_parallel) #[A, B, R, S]
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)) }

open Lean Meta Simp in
/-- `projectRight_smul_parallel` whatever the spelling of the interfaces: the action of
`TypedConverter.projectRight A B` on `R ∥ S`, with types written through `⊗` or `Interface.tensor`,
returns `S`. -/
simproc [cc_normalization] projectRightSmul (@HSMul.hSMul _ _ _ _ _ _) := fun e => do
let_expr HSMul.hSMul _ _ _ _ f x := e | return .continue
let_expr TypedConverter.projectRight A B := f | return .continue
let_expr TypedSystem.parallel _ _ R S := x | return .continue
let proof := mkAppN (mkConst ``TypedConverter.projectRight_smul_parallel) #[A, B, R, S]
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)) }

lemma distance_smul_le {A B : Interface} (α : A ⟶ B) (R S : TypedSystem B) :
Δ (α • R) (α • S) ≤ Δ R S :=
ConstructiveCryptography.CryptographicAlgebra.distance_attach_le
Expand Down
Loading