diff --git a/AGENTS.md b/AGENTS.md index e6d7b31..6019316 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,26 +12,31 @@ systems with declared domains. Its libraries, under `src/`, form strict layers: ```text Probability - -> RandomSystems (systems, converters, distances, games) - -> ConstructiveCryptography (interfaces, arrows, resources, action, - distance; the classes of cryptographic - algebras and their instance on interfaces; + -> RandomSystems (systems, converters, distances, games; + typed systems and typed converters on + interfaces; the programs of the DSL) + -> ConstructiveCryptography (the classes of cryptographic algebras and + their instances on interfaces; specifications, constructions, substitution; - the DSL and the proof commands) + the notation, the proof commands and the + DSL front end) -> Commons (ideal systems, security definitions, schemes and their known-answer tests) -> Examples Tests (audits of every layer) ``` -No module imports a higher layer. `RandomSystems` knows systems and -converters, not interfaces or resources. `ConstructiveCryptography` proves the -laws of resources and converters on the concrete objects, with the transcript -distance. The abstract theory (`ConstructiveCryptography.CryptographicAlgebra`, +No module imports a higher layer. `RandomSystems` holds the concrete objects and their laws: +random systems, converters, distances and games, and, in `RandomSystems.Typed`, interfaces with +their typed systems, typed converters and typed games, with the transcript distance. It knows +nothing of the classes. The abstract theory (`ConstructiveCryptography.CryptographicAlgebra`, `ConstructiveCryptography.Specification` and `ConstructiveCryptography.Construction`) -uses only Mathlib: its classes are assumptions, and `ConstructiveCryptography.InterfaceAlgebra` -instantiates them on interfaces with the concrete objects. The notation and the proof commands -are built on laws already proved below them, and nothing below them imports them. The downstream +uses only Mathlib: its classes are assumptions, and "resource" names only their carrier `Φ A`. +The instance files (`ConstructiveCryptography.InterfaceCategory`, `InterfaceMonoidal`, +`InterfaceAlgebra`, `InterfaceGame`) instantiate them on interfaces: each field is a systems-level +object and each axiom is discharged by a systems-level theorem; no concrete object is defined +there. The notation, the proof commands and the DSL front end are built on laws already proved +below them, and nothing below them imports them. The downstream ChaCha20-Poly1305 development (`chachapoly-cc`) imports modules of this repository; changes to public declarations it uses must keep it building. @@ -57,8 +62,8 @@ are secondary evidence. ## Modeling rules -- A resource is its cumulative behavior on its interface's domain. Equality of - resources is equality of all cumulative probabilities; observers +- A typed system is its cumulative behavior on its interface's domain. Equality of + typed systems is equality of all cumulative probabilities; observers characterize this relation, they do not define it. Do not introduce a second quotient. - On normalized PDSs, equivalence is equivalently equality of the partial diff --git a/README.md b/README.md index ef0d60c..4ae165c 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@ This repository formalizes Constructive Cryptography [1, 2] in Lean 4. The framework is instantiated on a theory of random systems [3, 4] in which a -resource answers exactly on a declared domain of input histories, and a -converter may stop at random. The algebra of resources and converters is also -stated in category-theoretic terms; a categorical model of composable security -is given in [7]. +system answers exactly on a declared domain of input histories, and a +converter may stop at random. The classes of the framework are assumptions; their +instances on interfaces take every field from the typed systems and typed +converters of the random-systems library. The algebra of typed systems and +converters is also stated in category-theoretic terms; a categorical model of +composable security is given in [7]. ## Libraries @@ -15,12 +17,12 @@ summarizes the theory layer by layer, with links to the Lean declarations. | Library | Content | |---|---| | `Probability` | finitely supported distributions, kernels, statistical distance, couplings, expectation, counting | -| `RandomSystems` | systems and automata; deterministic converters and programs; distributions over deterministic systems; random systems given by their cumulative probabilities; probabilistic automata and memoryless systems; probabilistic converters, attachment and parallel composition; transcript distance and distinguishers; games | +| `RandomSystems` | systems and automata; deterministic converters and programs; distributions over deterministic systems; random systems given by their cumulative probabilities; probabilistic automata and memoryless systems; probabilistic converters, attachment and parallel composition; transcript distance and distinguishers; games; typed systems, typed converters and typed games on interfaces, with filters, contexts, sources, automata, memoryless and functional systems, and games presented by discrete games; the programs and program converters of the DSL | | `ConstructiveCryptography.Specification`, `.Construction` | specifications, constructions and relaxations over any carrier | | `ConstructiveCryptography.CryptographicAlgebra` | the classes of cryptographic algebras: resource theories, parallel composition, compatible pseudo-metrics and distinguisher classes, relaxations | -| `ConstructiveCryptography` (top level) | interfaces, resources and converters on random systems, and their instances of the classes; filters, contexts, sources, automata, memoryless systems, functional resources, games presented by discrete games; notation | +| `ConstructiveCryptography` (top level) | the instances of the classes on interfaces (category, monoidal category, cryptographic algebra, distinguisher class, games), each field a systems-level object; notation | | `ConstructiveCryptography.Substitution` | the substitution calculus for constructions [6] | -| `ConstructiveCryptography.DSL` | a compiler from component declarations to resources and converters | +| `ConstructiveCryptography.DSL` | a compiler from component declarations to typed systems and typed converters | | `ConstructiveCryptography.Tactics` | proof commands, including the substitution calculations `cc_calc` | | `Commons` | common ideal systems (URF, URP and their strong and tweakable forms, memoryless sources), the CDH assumption as a pair of systems, the security notions as pairs of systems [6]: symmetric encryption (real-or-random and left-or-right CPA) and authenticated encryption (ind-cca, int-ptxt, int-ctxt, ae), public-key encryption and KEMs (IND-CPA, IND-CCA), MACs and signatures (EUF-CMA, SUF-CMA), PRGs, universal hashing (UHF, DUF) and collision resistance, and the schemes SHA-256, SHA-3, SHAKE, Keccak-256, ML-KEM [9] and ML-DSA [10] (the last two adapted from VCVio [11]) with known-answer tests, in the order of [8] | | `Examples` | authenticated encryption, AES, AEAD, PRG length extension, substitutions on interfaces, the proof commands | diff --git a/THEORY.md b/THEORY.md index 03244f4..f827246 100644 --- a/THEORY.md +++ b/THEORY.md @@ -1,18 +1,20 @@ # The theory, layer by layer -This is a cheat-sheet of what the library formalizes. It starts with **random systems** and their -properties, then packages them: first into **interfaces, resources and converters**, then into the -**abstract layers** (classes of assumptions, up to categories), each shown with the instance that -connects it to the systems. It ends with what the layers are used for: **constructions**, the -**substitution calculus**, the **DSL** and the **examples**. Every notion and result is linked, in -the text, to its Lean declaration; citations refer to the [references](#references) at the end. +This is a cheat-sheet of what the library formalizes. It starts at the systems level: **random +systems** and their properties, and **typed systems**, the random systems and converters on the +alphabets and domain of an interface. Then come the **abstract layers** (classes of assumptions, +up to categories), each shown with the instance that connects it to the systems: every field of +the instance is a systems-level object and every axiom a systems-level theorem. It ends with what +the layers are used for: **constructions**, the **substitution calculus**, the **DSL** and the +**examples**. Every notion and result is linked, in the text, to its Lean declaration; citations +refer to the [references](#references) at the end. ``` -Probability ─▶ Random systems ─▶ Interfaces, resources, converters ══ instance ══▶ Classes - (App. A) (§1) (§2) (§3) - ▲ │ - DSL (§6) ▼ - Constructions (§4) ─▶ Substitution (§5) +Probability ─▶ Random systems, typed systems ══ instance ══▶ Classes + (App. A) (§1, §2) (§3) + ▲ │ + DSL (§6) ▼ + Constructions (§4) ─▶ Substitution (§5) ``` --- @@ -332,12 +334,13 @@ the ideal answers. --- -## 2. Interfaces, resources and converters +## 2. Typed systems -*The systems of §1, typed by interfaces [3, Definitions 3.8, 3.9, 3.17], [6, §3], -[7, Definitions 2.2.1–2.2.2].* +*The random systems and converters of §1, typed by interfaces [3, Definitions 3.8, 3.9, 3.17], +[6, §3], [7, Definitions 2.2.1–2.2.2]. Every object of this section is a systems-level object; §3 +uses them as the fields of the instances.* -### 2.1 The objects +### 2.1 Interfaces, typed systems and typed converters An [**interface**][Interface] $`A = (I, X, Y, D)`$ has finitely many labels, finite alphabets $`X_i, Y_i`$, and a domain $`D`$ of input histories, prefix-closed, without the empty history, of @@ -347,72 +350,74 @@ $`D = \lbrace h \ne \varepsilon \mid \lvert h \rvert \le q \rbrace`$ and the $`D = \lbrace h \ne \varepsilon \mid \forall i.\ \lvert h \restriction i \rvert \le q_i \rbrace`$, where $`h \restriction i`$ [keeps the inputs at the label][restrict] $`i`$. -A [**resource**][Interface.Resource] on $`A`$ is a random system on +A [**typed system**][TypedSystem] on $`A`$ is a random system on $`(\Sigma_i X_i, \Sigma_i Y_i)`$ over $`D`$, [replying at the queried label][RandomSystem.RepliesAtQueriedInterface]. A -[**converter**][Interface.Converter] $`A \to B`$ is a PDC behavior from $`B`$'s domain (inside) to -$`A`$'s domain (outside), and a DDC between the two domains [is one][Interface.ofDDC]. -[**Attachment**][Interface.attach] $`\alpha R`$ is the attachment of the PDC behavior. +[**typed converter**][TypedConverter] from $`A`$ to $`B`$ is a PDC behavior from $`B`$'s domain +(inside) to $`A`$'s domain (outside), and a DDC between the two domains +[is one][TypedConverter.ofDDC]. Typed converters compose by the [serial composition][TypedConverter.comp] +of PDC behaviors, with the [identity][TypedConverter.id] PDC behavior. +[**Attachment**][TypedConverter.attach] $`\alpha R`$ is the attachment of the PDC behavior: +[the identity leaves a typed system unchanged][TypedConverter.identity_attach], and +[a serial composition attaches its inner converter first][TypedConverter.comp_smul]. + [**Parallel interfaces**][Interface.tensor] put the label sets side by side, and -[parallel resources][Interface.parallel] and [parallel converters][Interface.parallelConverter] -are the independent parallel compositions. - -### 2.2 Concrete resources and converters - -The [**filter**][Interface.filter] admitting $`D`$ forwards the queries of admitted histories; it is -a converter $`(A \restriction D) \to A`$ from the [restricted interface][Interface.restrict]. -[Attached to a resource][Interface.filter_smul], it is the [restriction][RandomSystem.restrict] of the -resource's random system to the restricted domain, and -[two filters in series][Interface.filter_comp_filter_smul] act as the filter of both conditions. A -[**constant**][Interface.constant] converter ignores its inside resource and exposes a fixed one, -and the fixed [right][Interface.rightContext] and [left][Interface.leftContext] **contexts** run a -resource beside: [attaching][Interface.attach_rightContext] $`\mathrm{rightContext}\ A\ S`$ to $`R`$ -gives $`R \parallel S`$, and so does [attaching][Interface.attach_leftContext] +[parallel typed systems][TypedSystem.parallel] and [parallel typed converters][TypedConverter.parallel] +are the independent parallel compositions; attachment [is local][TypedConverter.parallel_attach], +$`(\alpha \otimes \beta)(R \parallel S) = \alpha R \parallel \beta S`$. A label-preserving +bijection of interfaces gives a [**renaming**][TypedConverter.rename], which +[relabels the transcripts][TypedConverter.rename_mass] of the typed system it is attached to; +renamings [compose][TypedConverter.rename_comp], and the renaming by the identity +[is the identity][TypedConverter.rename_refl]. Regrouping three parallel typed systems +[keeps the probabilities][TypedSystem.parallel_assoc_mass] of the regrouped transcripts, the +[dummy system][TypedSystem.dummy] on the [interface without labels][Interface.unit] beside a typed +system keeps its probabilities, on the [left][TypedSystem.parallel_unit_left_mass] and on the +[right][TypedSystem.parallel_unit_right_mass], and [exchanging the two components][TypedSystem.parallel_swap_mass] +of a parallel composition exchanges the labels of its transcripts. The regrouping renamings are +natural for typed converters: [associativity][TypedConverter.comp_associator] and the +[left][TypedConverter.comp_leftUnitor] and [right][TypedConverter.comp_rightUnitor] unit +regroupings commute with parallel typed converters. + +### 2.2 Filters, contexts, sources and functional systems + +The [**filter**][TypedConverter.filter] admitting $`D`$ forwards the queries of admitted histories; +it is a typed converter $`(A \restriction D) \to A`$ from the [restricted interface][Interface.restrict]. +[Attached to a typed system][TypedConverter.filter_smul], it is the +[restriction][RandomSystem.restrict] of the system's random system to the restricted domain, and +[two filters in series][TypedConverter.filter_comp_filter_smul] act as the filter of both +conditions. A [**constant**][TypedConverter.constant] converter ignores its inside system and +exposes a fixed one, and the fixed [right][TypedConverter.rightContext] and +[left][TypedConverter.leftContext] **contexts** run a typed system beside: +[attaching][TypedConverter.attach_rightContext] $`\mathrm{rightContext}\ A\ S`$ to $`R`$ +gives $`R \parallel S`$, and so does [attaching][TypedConverter.attach_leftContext] $`\mathrm{leftContext}\ R\ B`$ to $`S`$. -A [**source**][Interface.Resource.source] answers with fresh independent samples of a law: a -memoryless source [3, Definition 3.1] (the sources of [4, Definition 1] may have memory). An [**automaton**][Interface.Resource.ofAutomaton] is a transition function with -a sampled initial state [4, Definition 2], and [parallel automata][Interface.parallel_ofAutomaton] -are the automaton running both side by side. A source [is memoryless][Interface.source_eq_memoryless], -memoryless systems [side by side are memoryless][Interface.parallel_eq_memoryless], and the +A [**source**][TypedSystem.source] answers with fresh independent samples of a law: a +memoryless source [3, Definition 3.1] (the sources of [4, Definition 1] may have memory). An +[**automaton**][TypedSystem.ofAutomaton] is a transition function with a sampled initial state +[4, Definition 2], and [parallel automata][TypedSystem.parallel_ofAutomaton] are the automaton +running both side by side. A source [is memoryless][TypedSystem.source_eq_memoryless], +memoryless systems [side by side are memoryless][TypedSystem.parallel_eq_memoryless], and the converter of a program [maps a memoryless system to the memoryless system of its reply -law][Interface.Converter.ofProgram_smul_memoryless], also -[for port-preserving programs][Interface.Converter.ofPreservingProgram_smul_memoryless] and -[with its own sources beside its inside interface][Interface.Converter.ofPreservingProgram_comp_rightContext_smul_memoryless]: -the composition law of §1.3 on their random systems. -**Functional resources** are given by -[reply functions][Interface.Resource.ofFunction], by -[conditional reply laws][Interface.Resource.ofConditional], or by -[sampling once][Interface.Resource.sample] and keeping the sample. - -A [**game**][Interface.Game] on $`A`$ is a resource on the -[interface][Interface.withMBO] of $`A`$ with the MBO whose MBO, once set, stays set, a game in the -sense of §1.5. A converter attaches to it through its [lift][Interface.liftMBO], and its -[visible resource][Interface.Game.visible] is its visible system. A game conditionally -equivalent to a resource $`T`$, $`G \mathrel{|\!\equiv} T`$ (the conditional equivalence of §3.6), -whose MBO stays unset with probability at least $`1 - \varepsilon`$ on fixed queries, -[has its visible resource within][Interface.dist_visible_le] $`\varepsilon`$ of $`T`$, -$`\Delta(G^-, T) \le \varepsilon`$ [3, Theorem 4.17]. - -A discrete game whose visible systems present a resource $`R`$ -[presents a game][Interface.Game.ofPDG] on the interface of $`R`$, with -[visible resource][Interface.Game.visible_ofPDG] $`R`$; it is conditionally equivalent to a -resource [exactly when][Interface.Game.conditionallyEquivalent_ofPDG_iff] the game it presents on -random systems is. If that game is conditionally equivalent to $`S`$ and the condition holds with -probability at most $`\varepsilon`$ on the empty and every admitted query sequence, -[the distance is at most][Interface.game_dist_le] $`\varepsilon`$, $`\Delta(R, S) \le \varepsilon`$. -A single-label sampled function with a hidden condition -[presents a game][Interface.Game.ofSingleFunction], -[conditionally equivalent][Interface.ofSingleFunction_conditionallyEquivalent] to the resource -sampling the ideal function under the fixed-query factorization. Parallel composition is commutative: $`R \parallel S`$ and -$`S \parallel R`$ [agree][Interface.parallel_swap] through the [swap][Interface.swap] of the two -interfaces. - -**Notation** (`open scoped SystemAlgebra`): [`Δ R S`][notation-distance], -[`R ∥ S`][notation-parallel], [`𝓡 —[π]→ 𝒮`][notation-constructs] for -$`\mathcal R \xrightarrow{\pi} \mathcal S`$ and [`𝓡 —[π; ε]→ 𝒮`][notation-constructsWithin] for -$`\mathcal R \xrightarrow{\pi,\ \varepsilon} \mathcal S`$, and -[`G |≡ T`][notation-conditionallyEquivalent] for $`G \mathrel{|\!\equiv} T`$. +law][TypedConverter.ofProgram_smul_memoryless], also +[for port-preserving programs][TypedConverter.ofPreservingProgram_smul_memoryless] and +[with its own sources beside its inside interface][TypedConverter.ofPreservingProgram_comp_rightContext_smul_memoryless]: +the composition law of §1.3 on their random systems. **Functional systems** are given by +[reply functions][TypedSystem.ofFunction], by +[conditional reply laws][TypedSystem.ofConditional], or by +[sampling once][TypedSystem.sample] and keeping the sample. + +### 2.3 Typed games + +A [**typed game**][TypedGame] on $`A`$ is a typed system on the [interface][Interface.withMBO] of +$`A`$ with the MBO whose MBO, once set, stays set: a game in the sense of §1.5. A typed converter +[attaches][TypedConverter.attachGame] to it through its [MBO-forwarding lift][PDCBehavior.liftMBO], +and its [visible typed system][TypedGame.visible] is its visible system. A discrete game whose +visible systems present a typed system $`R`$ [presents a typed game][TypedGame.ofPDG] on the +interface of $`R`$, with [visible typed system][TypedGame.visible_ofPDG] $`R`$. A single-label +sampled function with a hidden condition [presents a typed game][TypedGame.ofSingleFunction] +whose random system is [conditionally equivalent][TypedGame.ofSingleFunction_conditionallyEquivalent] +to that of the typed system sampling the ideal function, under the fixed-query factorization. --- @@ -420,9 +425,10 @@ $`\mathcal R \xrightarrow{\pi,\ \varepsilon} \mathcal S`$, and *Each layer is a class of assumptions: it introduces its notions (attachment, parallel composition, distance, distinguishers, games, winners, solvers) only as fields and axioms, and -knows nothing about systems [3, §§4.4.3, 4.5.1, 4.7.2, 4.10–4.11], [6, §3], [7, §2.2], [8]. Interfaces are an -instance of each class: every field is a systems-level object of §1–2, and every axiom is a -theorem about it.* +knows nothing about systems [3, §§4.4.3, 4.5.1, 4.7.2, 4.10–4.11], [6, §3], [7, §2.2], [8]. Interfaces +are an instance of each class: the carrier $`\Phi A`$ is the typed systems on $`A`$, every field is +a systems-level object of §1–2, and every axiom is discharged by a systems-level theorem. Only the +classes say "resource", for an element of $`\Phi A`$.* ``` Category ─▶ MonoidalCategory @@ -436,31 +442,36 @@ Games ─▶ DistinctionGames ### 3.1 The category of interfaces -Interfaces and converters form a category under serial composition, and a monoidal category under -parallel composition. +Interfaces and typed converters form a category under serial composition, and a monoidal +category under parallel composition. -Interfaces are an instance of Mathlib's `Category` ([`Interface.category`][Interface.category]): -its field `Hom` is the [PDC behavior][PDCBehavior], `id` is the [identity][PDCBehavior.id] and -`comp` is [serial composition][PDCBehavior.comp]; the axioms `id_comp`, `comp_id` and `assoc` are -discharged by the [left identity][PDCBehavior.id_comp], [right identity][PDCBehavior.comp_id] and +Interfaces are an instance of Mathlib's `Category` ([`Interface.category`][Interface.category]) +with the interfaces as objects: its field `Hom A B` is [`TypedConverter A B`][TypedConverter], +`id` is [`TypedConverter.id`][TypedConverter.id] and `comp` is +[`TypedConverter.comp`][TypedConverter.comp], the identity and the serial composition of PDC +behaviors; the axioms `id_comp`, `comp_id` and `assoc` are discharged by the +[left identity][PDCBehavior.id_comp], [right identity][PDCBehavior.comp_id] and [associativity][PDCBehavior.comp_assoc] laws of PDC behaviors. -They are an instance of `MonoidalCategory` ([`Interface.monoidal`][Interface.monoidal], on the -structure [`Interface.monoidalStruct`][Interface.monoidalStruct]): `tensorObj` is the -[parallel interface][Interface.tensor], `tensorHom` is the -[parallel composition][PDCBehavior.tensor] of PDC behaviors, the unit is the -[interface without labels][Interface.unit], and the [associator][Interface.associator] and the -[left][Interface.leftUnitor] and [right][Interface.rightUnitor] unitors are the regrouping -renamings. The axioms are discharged by [interchange][Interface.tensor_comp], from the +Interfaces are an instance of `MonoidalCategory` ([`Interface.monoidal`][Interface.monoidal], +on the structure [`Interface.monoidalStruct`][Interface.monoidalStruct]): `tensorObj` is the +[parallel interface][Interface.tensor], `tensorHom` is +[`TypedConverter.parallel`][TypedConverter.parallel], the parallel composition of PDC behaviors, +the unit is the [interface without labels][Interface.unit], and the +[associator][Interface.associator] and the [left][Interface.leftUnitor] and +[right][Interface.rightUnitor] unitors are the [isomorphisms][Interface.isoOf] of the regrouping +[renamings][TypedConverter.rename], with inverses by [`TypedConverter.rename_comp`][TypedConverter.rename_comp] +and [`TypedConverter.rename_refl`][TypedConverter.rename_refl]. The axioms are discharged by +[interchange][Interface.tensor_comp], from the [interchange of PDC behaviors][PDCBehavior.comp_tensor]; the [tensor of identities][Interface.id_tensor_id], from the [same law for PDC behaviors][PDCBehavior.tensor_id]; the -[naturality of the associator][Interface.associator_naturality], from -[regrouping arbitrary converters][Interface.comp_associator]; the naturality of the +[naturality of the associator][Interface.associator_naturality], from the systems-level +[naturality of the associativity renaming][TypedConverter.comp_associator]; the naturality of the [left][Interface.leftUnitor_naturality] and [right][Interface.rightUnitor_naturality] unitors, -from the [left][Interface.comp_leftUnitor] and [right][Interface.comp_rightUnitor] unit -regroupings of arbitrary converters; and the [pentagon][Interface.pentagon] and -[triangle][Interface.triangle] identities. +from the [left][TypedConverter.comp_leftUnitor] and [right][TypedConverter.comp_rightUnitor] unit +renamings; and the [pentagon][Interface.pentagon] and [triangle][Interface.triangle] identities, +from [parallel renamings][TypedConverter.parallel_rename] and their composition. ### 3.2 `ResourceTheory C Φ`: attachment @@ -475,12 +486,15 @@ Attachment is the [contravariant functor][ResourceTheory.functor] $`\Phi : C^{\mathrm{op}} \to \mathrm{Type}`$. Interfaces are an instance of `ResourceTheory` -([`Interface.resourceTheory`][Interface.resourceTheory]): its field `attach` is the -[attachment of converters to resources][Interface.attach], the systems-level +([`Interface.resourceTheory`][Interface.resourceTheory]) with carrier +$`\Phi A :=`$ [`TypedSystem A`][TypedSystem]: its field `attach` is +[`TypedConverter.attach`][TypedConverter.attach], the systems-level [attachment of PDC behaviors][PDCBehavior.attach]; its axioms `attach_identity` and -`attach_serial` are discharged by [attaching the identity][Interface.identity_attach] and -[attaching a serial composition][Interface.comp_smul], from the systems-level -[identity][PDCBehavior.attach_id] and [serial][PDCBehavior.attach_comp] attachment laws. +`attach_serial` are discharged by [`TypedConverter.identity_attach`][TypedConverter.identity_attach] +and [`TypedConverter.comp_smul`][TypedConverter.comp_smul], from the +[identity][PDCBehavior.attach_id] and [serial][PDCBehavior.attach_comp] attachment laws of PDC +behaviors. In the notation of the category they read [`Interface.identity_attach`][Interface.identity_attach] +and [`Interface.comp_smul`][Interface.comp_smul]. ### 3.3 `CryptographicAlgebra C Φ`: parallel composition @@ -496,15 +510,20 @@ Derived: [locality][CA.attach_parallel], [associativity][CA.parallel_assoc], and [left][CA.parallel_dummy_left] and [right][CA.parallel_dummy_right] unit laws. Interfaces are an instance of `CryptographicAlgebra` -([`Interface.cryptographicAlgebra`][Interface.cryptographicAlgebra]): its field `laxMonoidal` is -[`Interface.resourcesLaxMonoidal`][Interface.resourcesLaxMonoidal], whose product is the -[parallel composition of resources][Interface.parallel], the systems-level +([`Interface.cryptographicAlgebra`][Interface.cryptographicAlgebra]) with carrier +$`\Phi A :=`$ `TypedSystem A`: its field `laxMonoidal` is +[`Interface.resourcesLaxMonoidal`][Interface.resourcesLaxMonoidal], whose product is +[`TypedSystem.parallel`][TypedSystem.parallel], the systems-level [independent parallel composition][RandomSystem.parallel], and whose unit is the -[dummy resource][Interface.dummy]; naturality, associativity and unitality are discharged by -[locality][Interface.parallel_attach], [associativity][Interface.parallel_assoc] and the -[left][Interface.parallel_dummy_left] and [right][Interface.parallel_dummy_right] unit laws of -parallel resources. The abstract [parallel composition][Interface.cc_parallel_eq] and -[dummy][Interface.cc_dummy_eq] are the concrete ones. +[dummy typed system][TypedSystem.dummy]. Naturality is discharged by the +[locality of attachment][TypedConverter.parallel_attach]; associativity and unitality by +[`Interface.parallel_assoc`][Interface.parallel_assoc] and the +[left][Interface.parallel_dummy_left] and [right][Interface.parallel_dummy_right] unit laws, +which are the systems-level [regrouping][TypedSystem.parallel_assoc_mass] and +[left][TypedSystem.parallel_unit_left_mass] and [right][TypedSystem.parallel_unit_right_mass] unit +laws of parallel typed systems, read through the [renaming][TypedConverter.rename_mass] of the +regrouping isomorphisms. The abstract [parallel composition][Interface.cc_parallel_eq] and +[dummy][Interface.cc_dummy_eq] are the systems-level ones. ### 3.4 `CompatiblePseudoMetric C Φ`: distance @@ -536,16 +555,17 @@ D \in \mathcal D_A \;\Longrightarrow\; D(\alpha\,\cdot\,) \in \mathcal D_B,\ \ D Interfaces are an instance of `CompatibleDistinguisherClass` ([`Interface.compatibleDistinguisherClass`][Interface.compatibleDistinguisherClass], built by -`ofClosure`): its field `distinguishers A` is the [set of maps][Interface.distinguishers] -$`R \mapsto \Pr[d(R) = 1]`$ for the systems-level [distinguisher behaviors][Domain.DistinguisherBehavior] -$`d`$ compatible with $`A`$'s domain. Its axiom `closed_attach` is discharged by -[closure under attachment][Interface.distinguishers_attach], from -[absorbing a converter][DistinguisherBehavior.absorb]; `closed_parallel_left` by -[closure under a resource on the right][Interface.distinguishers_parallel_left], from +`ofClosure`) with carrier $`\Phi A :=`$ `TypedSystem A`: its field `distinguishers A` is the +[set of maps][Interface.distinguishers] $`R \mapsto \Pr[d(R) = 1]`$ for the systems-level +[distinguisher behaviors][Domain.DistinguisherBehavior] $`d`$ compatible with $`A`$'s domain. Its +axiom `closed_attach` is discharged by [closure under attachment][Interface.distinguishers_attach], +from [absorbing a converter][DistinguisherBehavior.absorb]; `closed_parallel_left` by +[closure under a typed system run on the right][Interface.distinguishers_parallel_left], from [absorbing a system run beside][Domain.Distinguisher.exists_absorbRight]; and `closed_parallel_right` by -[closure under a resource on the left][Interface.distinguishers_parallel_right], from the previous -two through the [swap][Interface.parallel_swap]. Its metric +[closure under a typed system run on the left][Interface.distinguishers_parallel_right], from the +previous two through the [swap][Interface.parallel_swap], the [isomorphism][Interface.swap] of the +renaming that [exchanges the two components][TypedSystem.parallel_swap_mass]. Its metric [is the transcript distance][Interface.cc_distance_eq] of §1.4: ```math @@ -587,16 +607,17 @@ G \mathrel{|\!\equiv} T,\ (D, W) \in \mathcal S_A \;\Longrightarrow\; \lvert D(G ``` Interfaces are an instance of both classes, and the instance is the only place where they meet -random systems: its games are the MBO random systems of §1.5, as [3, §3.7.1] instantiates games, -and its winners and solvers are probabilistic distinguishers, through their +random systems: its games are the typed games of §2.3, MBO random systems as [3, §3.7.1] +instantiates games, and its winners and solvers are probabilistic distinguishers, through their [solver behaviors][Domain.SolverBehavior]. Interfaces are an instance of `Games` ([`Interface.games`][Interface.games]): its field `Game A` -is the set of [games][Interface.Game] on $`A`$, the resources on the interface of $`A`$ with the MBO -whose MBO, once set, stays set ([`RandomSystem.MonotoneMBO`][RandomSystem.MonotoneMBO]); -`attachGame` attaches the systems-level [lift][PDCBehavior.liftMBO] of the converter; and -`winners A` is the set of [winning probabilities][Interface.winners] of the systems-level solver -behaviors on $`A`$'s domain. Its axiom `attachGame_identity` is discharged by +is [`TypedGame A`][TypedGame], the typed systems on the interface of $`A`$ with the MBO whose MBO, +once set, stays set ([`RandomSystem.MonotoneMBO`][RandomSystem.MonotoneMBO]); `attachGame` is +[`TypedConverter.attachGame`][TypedConverter.attachGame], the attachment of the systems-level +[lift][PDCBehavior.liftMBO] of the converter; and `winners A` is the set of +[winning probabilities][Interface.winners] of the systems-level solver behaviors on $`A`$'s +domain. Its axiom `attachGame_identity` is discharged by [`PDCBehavior.liftMBO_id`][PDCBehavior.liftMBO_id], `attachGame_serial` by [`PDCBehavior.liftMBO_comp`][PDCBehavior.liftMBO_comp], and `closed_attach` by [absorbing a PDC into a solver behavior][Domain.SolverBehavior.absorb]. A bound on the winning @@ -604,17 +625,33 @@ probability of every distinguisher [bounds the winning probability of every winner][Interface.win_le]. Interfaces are an instance of `DistinctionGames` -([`Interface.distinctionGames`][Interface.distinctionGames]): its field `solvers A` is the -[set of pairs][Interface.solvers] of the solver behaviors on $`A`$'s domain, `visible` is the -systems-level [visible system][RandomSystem.visible], and `ConditionallyEquivalent` is the -systems-level [conditional equivalence][RandomSystem.ConditionallyEquivalent]. Its axiom +([`Interface.distinctionGames`][Interface.distinctionGames]) with carrier $`\Phi A :=`$ +`TypedSystem A` and games `TypedGame A`: its field `solvers A` is the +[set of pairs][Interface.solvers] of the solver behaviors on $`A`$'s domain, `visible` is +[`TypedGame.visible`][TypedGame.visible], the systems-level [visible system][RandomSystem.visible], +and `ConditionallyEquivalent` is the systems-level +[conditional equivalence][RandomSystem.ConditionallyEquivalent] of the random systems. Its axiom `solvers_winner` holds by the definition of the winners, `solvers_closed_attach` is discharged by [`Domain.SolverBehavior.absorb`][Domain.SolverBehavior.absorb], `visible_attachGame` by [`RandomSystem.visible_attach_liftMBO`][RandomSystem.visible_attach_liftMBO], and `advantage_le_win` by [`Domain.Distinguisher.advantage_le_winProbability`][Domain.Distinguisher.advantage_le_winProbability]. -The distance bound on interfaces, [`Interface.dist_visible_le`][Interface.dist_visible_le], is -stated with this conditional equivalence. +A typed game conditionally equivalent to a typed system $`T`$, $`G \mathrel{|\!\equiv} T`$, whose MBO +stays unset with probability at least $`1 - \varepsilon`$ on fixed queries, +[has its visible typed system within][Interface.dist_visible_le] $`\varepsilon`$ of $`T`$, +$`\Delta(G^-, T) \le \varepsilon`$ [3, Theorem 4.17]. A presented typed game is conditionally +equivalent to a typed system [exactly when][Interface.conditionallyEquivalent_ofPDG_iff] the game +it presents on random systems is; if it is conditionally equivalent to $`S`$ and the condition +holds with probability at most $`\varepsilon`$ on the empty and every admitted query sequence, the +presented typed system $`R`$ is [within][Interface.game_dist_le] $`\varepsilon`$ of $`S`$, +$`\Delta(R, S) \le \varepsilon`$. + +**Notation** (`open scoped SystemAlgebra`): [`Δ R S`][notation-distance] for the distance of +§3.4, [`R ∥ S`][notation-parallel] for `TypedSystem.parallel`, +[`𝓡 —[π]→ 𝒮`][notation-constructs] for $`\mathcal R \xrightarrow{\pi} \mathcal S`$ and +[`𝓡 —[π; ε]→ 𝒮`][notation-constructsWithin] for +$`\mathcal R \xrightarrow{\pi,\ \varepsilon} \mathcal S`$ (§4), and +[`G |≡ T`][notation-conditionallyEquivalent] for $`G \mathrel{|\!\equiv} T`$. --- @@ -715,19 +752,19 @@ transports substitutions [through one converter][SubstitutesWithin.attach] and [7, Theorem 2.2.10], the [assumption uses][Implication.substitutesWithin] and the [statistical steps][Implication.substitutesWithin_of_mixed] along a witness add up. -**On interfaces.** [`DistinguisherAdvantage`][DistinguisherAdvantage] is a structure, and for every class of admitted -distinguishers [`Interface.distinguisherAdvantage`][Interface.distinguisherAdvantage] is one: its -distinguishers are the systems-level [distinguisher behaviors][Domain.DistinguisherBehavior], its -field `admissible` is that class, its field `advantage` is the systems-level +**On interfaces.** [`DistinguisherAdvantage`][DistinguisherAdvantage] is a structure, and for every +class of admitted distinguishers [`Interface.distinguisherAdvantage`][Interface.distinguisherAdvantage] +is one, with carrier $`\Phi A :=`$ `TypedSystem A`: its distinguishers are the systems-level +[distinguisher behaviors][Domain.DistinguisherBehavior], its field `admissible` is that class, its +field `advantage` is the systems-level [advantage][DistinguisherBehavior.advantage], and its laws `advantage_self`, `advantage_symm` and `advantage_triangle` are the systems-level [zero][DistinguisherBehavior.advantage_self], [symmetry][DistinguisherBehavior.advantage_symm] and [triangle][DistinguisherBehavior.advantage_triangle] laws. A converter $`\alpha`$ absorbed into a distinguisher is the reduction of a security proof [3]: -[absorbing it][Interface.absorb] gives $`D \circ \alpha`$, the systems-level -[absorption][DistinguisherBehavior.absorb], and absorbing a serial composition -[absorbs its converters in turn][Interface.absorb_comp], +the systems-level [absorption][DistinguisherBehavior.absorb] gives $`D \circ \alpha`$, and absorbing +a serial composition [absorbs its converters in turn][DistinguisherBehavior.absorb_comp], $`D \circ (\alpha \gg \beta) = (D \circ \alpha) \circ \beta`$. Hence an advantage between attachments [is the advantage with the converter absorbed][Interface.distinguisherAdvantage_attach], $`\mathrm{Adv}_D(\alpha R, \alpha S) = \mathrm{Adv}_{D \circ \alpha}(R, S)`$; every advantage @@ -757,27 +794,28 @@ compose [9, Definition 2.4.3 and Theorem 2.4.4]: a witness ## 6. Writing systems: the DSL -*`interface`, `system`, `converter` and `filter` declarations compile to the objects of §2 at every -budget ([DSL][DSL], [GRAMMAR][Grammar]).* A component compiles to a deterministic +*`interface`, `system`, `converter` and `filter` declarations compile to the typed systems and +typed converters of §2 at every budget ([DSL][DSL], [GRAMMAR][Grammar]); converters are declared +as arrows of the category of interfaces (§3.1), so that components assemble with `≫` and `⊗ₘ`.* A component compiles to a deterministic [program][Program] and **sources**: every sampling `x ←$ P` [becomes a call][desugarSampling] to -a [source][Interface.Resource.source] of fresh samples of the closed law $`P`$, and initialization +a [source][TypedSystem.source] of fresh samples of the closed law $`P`$, and initialization runs in the first invocation. An [`interface I`][elabInterface] declaration generates `I q := Interface.queryBudget … q`, the [query budget][Interface.queryBudget], and `I.perPort q := Interface.portBudget … q`, the -[per-port budget][Interface.portBudget]. A [`system S : I`][elabComponent] generates -`S : Interface.Resource (I q)`, [compiled][elabProgramDecls] to `S.program • S.randomness k`: the -[converter of its program][Interface.Converter.ofProgram] attached to its [sources][sourcesAt]. A -system that samples nothing is the [automaton][Interface.Resource.ofAutomaton] of its program, and +[per-port budget][Interface.portBudget]. A [`system S : I`][elabComponent] generates the typed +system `S : TypedSystem (I q)`, [compiled][elabProgramDecls] to `S.program • S.randomness k`: the +[converter of its program][TypedConverter.ofProgram] attached to its [sources][sourcesAt]. A +system that samples nothing is the [automaton][TypedSystem.ofAutomaton] of its program, and a system without an exact domain [also gets][elabPerPortDecls] -`S.perPort : Interface.Resource (I.perPort q)`. +`S.perPort : TypedSystem (I.perPort q)`. A [`converter C : I`][elabComponent] with `inside J` generates `C : I q ⟶ J (C.bound * q)`, -compiled to `C.program ≫ Interface.rightContext J (C.randomness k)`: its program with its sources -[beside][Interface.rightContext] the inside interface, or `C.program` when it samples nothing. With +compiled to `C.program ≫ TypedConverter.rightContext J (C.randomness k)`: its program with its sources +[beside][TypedConverter.rightContext] the inside interface, or `C.program` when it samples nothing. With a single inside interface it [also has a per-port typing][elabPerPortDecls] along a partial port map `C.portMap : I.Port → Option J.Port`, through the -[converter of a port-preserving program][Interface.Converter.ofPreservingProgram], with +[converter of a port-preserving program][TypedConverter.ofPreservingProgram], with `C.preserving` a proof of [`Program.PortPreserving`][Program.PortPreserving]. When `J` is `I` and each procedure calls its own port, at most once, it is `C.perPort : I.perPort q ⟶ I.perPort q`. When `J` is another interface, each of whose labels one @@ -787,14 +825,14 @@ inside label has the budget of the procedure calling it, and a procedure calling $`\rho^{ctxt}`$ and $`\rho^{ae}`$ of §8. When the converter samples nothing and its number of inside calls is a function of the input, the elaborator [also generates][elabExactDecls] `C.exact : (I n).restrict (fun h => (h.map C.cost).sum ≤ q) ⟶ J q`, the -[converter of the costed program][Interface.Converter.ofCostedProgram]. +[converter of the costed program][TypedConverter.ofCostedProgram]. A [`filter F : I domain h ↦ P`][elabFilter] generates `F : (I q).restrict P ⟶ I q`, the -[filter][Interface.filter] admitting `P`. +[filter][TypedConverter.filter] admitting `P`. A compiled component is an automaton with a sampled initial state. Attaching a program to an -automaton [gives the combined automaton][Interface.Converter.ofProgram_smul_ofAutomaton], also -[for port-preserving programs][Interface.Converter.ofPreservingProgram_smul_ofAutomaton], so +automaton [gives the combined automaton][TypedConverter.ofProgram_smul_ofAutomaton], also +[for port-preserving programs][TypedConverter.ofPreservingProgram_smul_ofAutomaton], so compiled systems are compared by [bisimulation][automatonSystem_eq_of_bisim]. The [memoryless source][MemorylessSource] `y ←$ ν; return y` [is the memoryless system of `ν`][MemorylessSource.memoryless_eq], so systems built from programs @@ -854,7 +892,7 @@ R \;\simeq_{\mathrm{ptxt}}\; P R \;\simeq_{\mathrm{cca}}\; P C R \;\simeq_{\math $`\lvert D(\alpha\, G^-) - D(\alpha T) \rvert \le W(\alpha \cdot G)`$ for $`G \mathrel{|\!\equiv} T`$. On interfaces, the collision game of authenticated encryption [is the game the collision discrete game presents][collision], with - [visible resource the hybrid][collision_visible] and + [visible typed system the hybrid][collision_visible] and [conditionally equivalent to the ideal][collision_conditionallyEquivalent]; every winner [wins it with probability at most][collision_win_le] $`q_e^2 / \lvert \mathcal M \rvert`$, so every solver's advantage between the hybrid and the ideal @@ -877,7 +915,7 @@ R \;\simeq_{\mathrm{ptxt}}\; P R \;\simeq_{\mathrm{cca}}\; P C R \;\simeq_{\math ## Where the formalization departs from its sources -1. **Everything is finite.** Interfaces carry finite labels and alphabets and a domain of bounded length, so resources are finite random systems with [finite presentations][RandomSystem.exists_presentation]. The sources allow infinite alphabets and unbounded interactions. +1. **Everything is finite.** Interfaces carry finite labels and alphabets and a domain of bounded length, so typed systems are finite random systems with [finite presentations][RandomSystem.exists_presentation]. The sources allow infinite alphabets and unbounded interactions. 2. **Randomness enters DSL systems only through sources.** A sampled law must be closed: it may depend on declaration parameters, not on runtime values. A probabilistic encryption is therefore a [sampled table of ciphertexts][SymmetricEncryption.encryptions] ([Encryption][SymEnc]). 3. **[9, Theorem 2.3.10(4)] needs a second [`ind-cca`][AE.INDCCA] step.** The printed chain `int-ptxt`, `ind-cca`, `int-ptxt`, followed by a collision bound, fails when a later message equals an earlier replacement message. The [corrected chain][correctedChain] and an [all-pairs collision bound][collision_mass_le] are in [Security][AESec] and [Collision][AECol]. 4. **[2, Theorem 2.29] holds with a [maximum over pairs][exists_pair_one_sub_supAgreement_le], not a minimum.** The minimum form [is refuted][not_supAgreement_disagreement_le_every_pair]. @@ -1104,51 +1142,55 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X -[Interface]: src/ConstructiveCryptography/Interface.lean#L43 -[Interface.queryBudget]: src/ConstructiveCryptography/Interface.lean#L66 -[Interface.portBudget]: src/ConstructiveCryptography/Interface.lean#L77 -[Interface.Resource]: src/ConstructiveCryptography/Interface.lean#L93 -[Interface.Converter]: src/ConstructiveCryptography/Interface.lean#L128 -[Interface.category]: src/ConstructiveCryptography/Interface.lean#L132 -[Interface.ofDDC]: src/ConstructiveCryptography/Interface.lean#L141 -[Interface.attach]: src/ConstructiveCryptography/Interface.lean#L154 -[Interface.identity_attach]: src/ConstructiveCryptography/Interface.lean#L168 -[Interface.comp_smul]: src/ConstructiveCryptography/Interface.lean#L173 -[Interface.tensor]: src/ConstructiveCryptography/InterfaceParallel.lean#L85 -[Interface.parallel]: src/ConstructiveCryptography/InterfaceParallel.lean#L147 -[Interface.parallelConverter]: src/ConstructiveCryptography/InterfaceParallel.lean#L202 -[Interface.restrict]: src/ConstructiveCryptography/InterfaceFilter.lean#L30 -[Interface.filter]: src/ConstructiveCryptography/InterfaceFilter.lean#L43 -[Interface.filter_smul]: src/ConstructiveCryptography/InterfaceFilter.lean#L54 -[Interface.filter_comp_filter_smul]: src/ConstructiveCryptography/InterfaceFilter.lean#L88 -[Interface.constant]: src/ConstructiveCryptography/Context.lean#L78 -[Interface.rightContext]: src/ConstructiveCryptography/Context.lean#L102 -[Interface.leftContext]: src/ConstructiveCryptography/Context.lean#L107 -[Interface.attach_rightContext]: src/ConstructiveCryptography/Context.lean#L111 -[Interface.attach_leftContext]: src/ConstructiveCryptography/Context.lean#L116 -[Interface.Resource.source]: src/ConstructiveCryptography/Source.lean#L49 -[Interface.Resource.ofAutomaton]: src/ConstructiveCryptography/Automaton.lean#L42 -[Interface.parallel_ofAutomaton]: src/ConstructiveCryptography/Automaton.lean#L57 -[Interface.source_eq_memoryless]: src/ConstructiveCryptography/Memoryless.lean#L45 -[Interface.parallel_eq_memoryless]: src/ConstructiveCryptography/Memoryless.lean#L143 -[Interface.Converter.ofProgram_smul_memoryless]: src/ConstructiveCryptography/Memoryless.lean#L236 -[Interface.Converter.ofPreservingProgram_smul_memoryless]: src/ConstructiveCryptography/Memoryless.lean#L257 -[Interface.Converter.ofPreservingProgram_comp_rightContext_smul_memoryless]: src/ConstructiveCryptography/Memoryless.lean#L274 -[Interface.Resource.ofFunction]: src/ConstructiveCryptography/Functional.lean#L56 -[Interface.Resource.ofConditional]: src/ConstructiveCryptography/Functional.lean#L38 -[Interface.Resource.sample]: src/ConstructiveCryptography/Functional.lean#L176 -[Interface.withMBO]: src/ConstructiveCryptography/InterfaceGame.lean#L52 -[Interface.Game]: src/ConstructiveCryptography/InterfaceGame.lean#L63 -[Interface.liftMBO]: src/ConstructiveCryptography/InterfaceGame.lean#L66 -[Interface.Game.visible]: src/ConstructiveCryptography/InterfaceGame.lean#L84 -[Interface.Game.ofPDG]: src/ConstructiveCryptography/PresentedGame.lean#L54 -[Interface.Game.visible_ofPDG]: src/ConstructiveCryptography/PresentedGame.lean#L64 -[Interface.Game.conditionallyEquivalent_ofPDG_iff]: src/ConstructiveCryptography/PresentedGame.lean#L74 -[Interface.game_dist_le]: src/ConstructiveCryptography/PresentedGame.lean#L88 -[Interface.Game.ofSingleFunction]: src/ConstructiveCryptography/PresentedGame.lean#L132 -[Interface.ofSingleFunction_conditionallyEquivalent]: src/ConstructiveCryptography/PresentedGame.lean#L145 -[Interface.swap]: src/ConstructiveCryptography/ResourceCoherence.lean#L177 -[Interface.parallel_swap]: src/ConstructiveCryptography/ResourceCoherence.lean#L211 +[Interface]: src/RandomSystems/Typed/Interface.lean#L40 +[Interface.queryBudget]: src/RandomSystems/Typed/Interface.lean#L63 +[Interface.portBudget]: src/RandomSystems/Typed/Interface.lean#L74 +[TypedSystem]: src/RandomSystems/Typed/Interface.lean#L92 +[TypedConverter]: src/RandomSystems/Typed/Interface.lean#L127 +[Interface.category]: src/ConstructiveCryptography/InterfaceCategory.lean#L30 +[TypedConverter.ofDDC]: src/RandomSystems/Typed/Interface.lean#L143 +[TypedConverter.attach]: src/RandomSystems/Typed/Interface.lean#L157 +[TypedConverter.comp]: src/RandomSystems/Typed/Interface.lean#L134 +[TypedConverter.id]: src/RandomSystems/Typed/Interface.lean#L139 +[TypedConverter.identity_attach]: src/RandomSystems/Typed/Interface.lean#L171 +[TypedConverter.comp_smul]: src/RandomSystems/Typed/Interface.lean#L177 +[Interface.identity_attach]: src/ConstructiveCryptography/InterfaceCategory.lean#L45 +[Interface.comp_smul]: src/ConstructiveCryptography/InterfaceCategory.lean#L50 +[Interface.tensor]: src/RandomSystems/Typed/Parallel.lean#L85 +[TypedSystem.parallel]: src/RandomSystems/Typed/Parallel.lean#L153 +[TypedConverter.parallel]: src/RandomSystems/Typed/Parallel.lean#L210 +[Interface.restrict]: src/RandomSystems/Typed/Filter.lean#L32 +[TypedConverter.filter]: src/RandomSystems/Typed/Filter.lean#L49 +[TypedConverter.filter_smul]: src/RandomSystems/Typed/Filter.lean#L60 +[TypedConverter.filter_comp_filter_smul]: src/RandomSystems/Typed/Filter.lean#L94 +[TypedConverter.constant]: src/RandomSystems/Typed/Context.lean#L78 +[TypedConverter.rightContext]: src/RandomSystems/Typed/Context.lean#L109 +[TypedConverter.leftContext]: src/RandomSystems/Typed/Context.lean#L116 +[TypedConverter.attach_rightContext]: src/RandomSystems/Typed/Context.lean#L122 +[TypedConverter.attach_leftContext]: src/RandomSystems/Typed/Context.lean#L127 +[TypedSystem.source]: src/RandomSystems/Typed/Source.lean#L51 +[TypedSystem.ofAutomaton]: src/RandomSystems/Typed/Automaton.lean#L42 +[TypedSystem.parallel_ofAutomaton]: src/RandomSystems/Typed/Automaton.lean#L57 +[TypedSystem.source_eq_memoryless]: src/RandomSystems/Typed/Memoryless.lean#L47 +[TypedSystem.parallel_eq_memoryless]: src/RandomSystems/Typed/Memoryless.lean#L146 +[TypedConverter.ofProgram_smul_memoryless]: src/RandomSystems/Typed/Memoryless.lean#L241 +[TypedConverter.ofPreservingProgram_smul_memoryless]: src/RandomSystems/Typed/Memoryless.lean#L262 +[TypedConverter.ofPreservingProgram_comp_rightContext_smul_memoryless]: src/RandomSystems/Typed/Memoryless.lean#L279 +[TypedSystem.ofFunction]: src/RandomSystems/Typed/Functional.lean#L56 +[TypedSystem.ofConditional]: src/RandomSystems/Typed/Functional.lean#L38 +[TypedSystem.sample]: src/RandomSystems/Typed/Functional.lean#L176 +[Interface.withMBO]: src/RandomSystems/Typed/Game.lean#L24 +[TypedGame]: src/RandomSystems/Typed/Game.lean#L35 +[TypedConverter.attachGame]: src/RandomSystems/Typed/Game.lean#L38 +[TypedGame.visible]: src/RandomSystems/Typed/Game.lean#L53 +[TypedGame.ofPDG]: src/RandomSystems/Typed/PresentedGame.lean#L41 +[TypedGame.visible_ofPDG]: src/RandomSystems/Typed/PresentedGame.lean#L51 +[Interface.conditionallyEquivalent_ofPDG_iff]: src/ConstructiveCryptography/InterfaceGame.lean#L200 +[Interface.game_dist_le]: src/ConstructiveCryptography/InterfaceGame.lean#L213 +[TypedGame.ofSingleFunction]: src/RandomSystems/Typed/PresentedGame.lean#L88 +[TypedGame.ofSingleFunction_conditionallyEquivalent]: src/RandomSystems/Typed/PresentedGame.lean#L101 +[Interface.swap]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L66 +[Interface.parallel_swap]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L107 [notation-distance]: src/ConstructiveCryptography/Notation.lean#L24 [notation-parallel]: src/ConstructiveCryptography/Notation.lean#L28 [notation-constructs]: src/ConstructiveCryptography/Notation.lean#L31 @@ -1158,22 +1200,28 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X -[Interface.monoidalStruct]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L20 -[Interface.monoidal]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L107 -[Interface.id_tensor_id]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L33 -[Interface.tensor_comp]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L36 -[Interface.associator_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L41 -[Interface.leftUnitor_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L46 -[Interface.rightUnitor_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L50 -[Interface.pentagon]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L54 -[Interface.triangle]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L78 -[Interface.unit]: src/ConstructiveCryptography/InterfaceCoherence.lean#L91 -[Interface.associator]: src/ConstructiveCryptography/InterfaceCoherence.lean#L176 -[Interface.leftUnitor]: src/ConstructiveCryptography/InterfaceCoherence.lean#L181 -[Interface.rightUnitor]: src/ConstructiveCryptography/InterfaceCoherence.lean#L185 -[Interface.comp_associator]: src/ConstructiveCryptography/ConverterCoherence.lean#L71 -[Interface.comp_leftUnitor]: src/ConstructiveCryptography/ConverterCoherence.lean#L178 -[Interface.comp_rightUnitor]: src/ConstructiveCryptography/ConverterCoherence.lean#L204 +[Interface.monoidalStruct]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L71 +[Interface.monoidal]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L162 +[Interface.isoOf]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L33 +[Interface.id_tensor_id]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L84 +[Interface.tensor_comp]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L87 +[Interface.associator_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L92 +[Interface.leftUnitor_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L97 +[Interface.rightUnitor_naturality]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L101 +[Interface.pentagon]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L105 +[Interface.triangle]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L132 +[Interface.unit]: src/RandomSystems/Typed/InterfaceCoherence.lean#L90 +[Interface.associator]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L52 +[Interface.leftUnitor]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L57 +[Interface.rightUnitor]: src/ConstructiveCryptography/InterfaceMonoidal.lean#L61 +[TypedConverter.comp_associator]: src/RandomSystems/Typed/ConverterCoherence.lean#L158 +[TypedConverter.comp_leftUnitor]: src/RandomSystems/Typed/ConverterCoherence.lean#L195 +[TypedConverter.comp_rightUnitor]: src/RandomSystems/Typed/ConverterCoherence.lean#L224 +[TypedConverter.parallel_rename]: src/RandomSystems/Typed/TensorRename.lean#L128 +[TypedConverter.rename]: src/RandomSystems/Typed/Relabel.lean#L48 +[TypedConverter.rename_comp]: src/RandomSystems/Typed/Relabel.lean#L80 +[TypedConverter.rename_refl]: src/RandomSystems/Typed/Relabel.lean#L67 +[TypedConverter.rename_mass]: src/RandomSystems/Typed/SystemParallel.lean#L55 [ResourceTheory]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L50 [ResourceTheory.functor]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L69 [CryptographicAlgebra]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L97 @@ -1183,22 +1231,26 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X [CA.parallel_assoc]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L182 [CA.parallel_dummy_left]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L196 [CA.parallel_dummy_right]: src/ConstructiveCryptography/CryptographicAlgebra/Basic.lean#L211 -[Interface.resourceTheory]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L68 -[Interface.resourcesLaxMonoidal]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L74 -[Interface.cryptographicAlgebra]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L99 -[Interface.distinguishers]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L105 -[Interface.distinguishers_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L122 -[Interface.distinguishers_parallel_left]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L128 -[Interface.distinguishers_parallel_right]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L143 -[Interface.compatibleDistinguisherClass]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L151 -[Interface.cc_parallel_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L158 -[Interface.cc_dummy_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L162 -[Interface.cc_distance_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L166 -[Interface.dummy]: src/ConstructiveCryptography/ResourceCoherence.lean#L102 -[Interface.parallel_assoc]: src/ConstructiveCryptography/ResourceCoherence.lean#L91 -[Interface.parallel_dummy_left]: src/ConstructiveCryptography/ResourceCoherence.lean#L158 -[Interface.parallel_dummy_right]: src/ConstructiveCryptography/ResourceCoherence.lean#L167 -[Interface.parallel_attach]: src/ConstructiveCryptography/ResourceParallelAttachment.lean#L18 +[Interface.resourceTheory]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L71 +[Interface.resourcesLaxMonoidal]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L116 +[Interface.cryptographicAlgebra]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L142 +[Interface.distinguishers]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L148 +[Interface.distinguishers_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L152 +[Interface.distinguishers_parallel_left]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L158 +[Interface.distinguishers_parallel_right]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L173 +[Interface.compatibleDistinguisherClass]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L181 +[Interface.cc_parallel_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L188 +[Interface.cc_dummy_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L192 +[Interface.cc_distance_eq]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L196 +[TypedSystem.dummy]: src/RandomSystems/Typed/SystemCoherence.lean#L97 +[TypedSystem.parallel_assoc_mass]: src/RandomSystems/Typed/SystemCoherence.lean#L85 +[TypedSystem.parallel_unit_left_mass]: src/RandomSystems/Typed/SystemCoherence.lean#L103 +[TypedSystem.parallel_unit_right_mass]: src/RandomSystems/Typed/SystemCoherence.lean#L128 +[TypedSystem.parallel_swap_mass]: src/RandomSystems/Typed/SystemCoherence.lean#L153 +[Interface.parallel_assoc]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L77 +[Interface.parallel_dummy_left]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L89 +[Interface.parallel_dummy_right]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L98 +[TypedConverter.parallel_attach]: src/RandomSystems/Typed/ParallelAttachment.lean#L23 [CompatiblePseudoMetric]: src/ConstructiveCryptography/CryptographicAlgebra/PseudoMetric.lean#L43 [CA.distance]: src/ConstructiveCryptography/CryptographicAlgebra/PseudoMetric.lean#L63 [distance_attach_le]: src/ConstructiveCryptography/CryptographicAlgebra/PseudoMetric.lean#L90 @@ -1212,12 +1264,12 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X [Games.absorb]: src/ConstructiveCryptography/CryptographicAlgebra/Game.lean#L93 [DistinctionGames.absorb]: src/ConstructiveCryptography/CryptographicAlgebra/Game.lean#L148 [Games.absorb_comp]: src/ConstructiveCryptography/CryptographicAlgebra/Game.lean#L101 -[Interface.games]: src/ConstructiveCryptography/InterfaceGame.lean#L100 -[Interface.distinctionGames]: src/ConstructiveCryptography/InterfaceGame.lean#L150 -[Interface.dist_visible_le]: src/ConstructiveCryptography/InterfaceGame.lean#L211 -[Interface.winners]: src/ConstructiveCryptography/InterfaceGame.lean#L89 -[Interface.solvers]: src/ConstructiveCryptography/InterfaceGame.lean#L94 -[Interface.win_le]: src/ConstructiveCryptography/InterfaceGame.lean#L195 +[Interface.games]: src/ConstructiveCryptography/InterfaceGame.lean#L69 +[Interface.distinctionGames]: src/ConstructiveCryptography/InterfaceGame.lean#L125 +[Interface.dist_visible_le]: src/ConstructiveCryptography/InterfaceGame.lean#L186 +[Interface.winners]: src/ConstructiveCryptography/InterfaceGame.lean#L58 +[Interface.solvers]: src/ConstructiveCryptography/InterfaceGame.lean#L63 +[Interface.win_le]: src/ConstructiveCryptography/InterfaceGame.lean#L170 @@ -1271,14 +1323,12 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X [SubstitutesWithin.attach_serial]: src/ConstructiveCryptography/Substitution/Reduction.lean#L175 [Implication.substitutesWithin]: src/ConstructiveCryptography/Substitution/Quantitative.lean#L49 [Implication.substitutesWithin_of_mixed]: src/ConstructiveCryptography/Substitution/Quantitative.lean#L105 -[Interface.distinguisherAdvantage]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L178 -[Interface.absorb]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L111 -[Interface.absorb_comp]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L117 -[Interface.distinguisherAdvantage_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L190 -[Interface.distinguisherAdvantage_le_distance]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L248 -[Interface.substitutesWithin_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L200 -[Interface.AdmissibleDistinguishers]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L214 -[AdmissibleDistinguishers.substitutesWithin_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L223 +[Interface.distinguisherAdvantage]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L208 +[Interface.distinguisherAdvantage_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L220 +[Interface.distinguisherAdvantage_le_distance]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L280 +[Interface.substitutesWithin_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L231 +[Interface.AdmissibleDistinguishers]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L246 +[AdmissibleDistinguishers.substitutesWithin_attach]: src/ConstructiveCryptography/InterfaceAlgebra.lean#L255 [substitutionImage]: src/ConstructiveCryptography/Substitution/Relaxation.lean#L45 [singleSubstitutionRelaxation]: src/ConstructiveCryptography/Substitution/Relaxation.lean#L59 [substitutionRelaxation]: src/ConstructiveCryptography/Substitution/Relaxation.lean#L164 @@ -1289,19 +1339,19 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X -[desugarSampling]: src/ConstructiveCryptography/DSL/Elaborator.lean#L191 -[elabInterface]: src/ConstructiveCryptography/DSL/Elaborator.lean#L348 -[elabComponent]: src/ConstructiveCryptography/DSL/Elaborator.lean#L808 -[elabProgramDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L641 -[elabPerPortDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L538 -[elabExactDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L713 -[elabFilter]: src/ConstructiveCryptography/DSL/Elaborator.lean#L924 -[sourcesAt]: src/ConstructiveCryptography/DSL/Elaborator.lean#L632 -[Interface.Converter.ofProgram]: src/ConstructiveCryptography/DSL/Converters.lean#L38 -[Interface.Converter.ofCostedProgram]: src/ConstructiveCryptography/DSL/Converters.lean#L50 -[Interface.Converter.ofPreservingProgram]: src/ConstructiveCryptography/DSL/Converters.lean#L67 -[Interface.Converter.ofProgram_smul_ofAutomaton]: src/ConstructiveCryptography/DSL/Converters.lean#L142 -[Interface.Converter.ofPreservingProgram_smul_ofAutomaton]: src/ConstructiveCryptography/DSL/Converters.lean#L152 +[desugarSampling]: src/ConstructiveCryptography/DSL/Elaborator.lean#L194 +[elabInterface]: src/ConstructiveCryptography/DSL/Elaborator.lean#L351 +[elabComponent]: src/ConstructiveCryptography/DSL/Elaborator.lean#L811 +[elabProgramDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L644 +[elabPerPortDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L541 +[elabExactDecls]: src/ConstructiveCryptography/DSL/Elaborator.lean#L716 +[elabFilter]: src/ConstructiveCryptography/DSL/Elaborator.lean#L927 +[sourcesAt]: src/ConstructiveCryptography/DSL/Elaborator.lean#L635 +[TypedConverter.ofProgram]: src/RandomSystems/Typed/DSL/Converters.lean#L39 +[TypedConverter.ofCostedProgram]: src/RandomSystems/Typed/DSL/Converters.lean#L51 +[TypedConverter.ofPreservingProgram]: src/RandomSystems/Typed/DSL/Converters.lean#L68 +[TypedConverter.ofProgram_smul_ofAutomaton]: src/RandomSystems/Typed/DSL/Converters.lean#L145 +[TypedConverter.ofPreservingProgram_smul_ofAutomaton]: src/RandomSystems/Typed/DSL/Converters.lean#L155 [MemorylessSource]: src/Commons/Definitions/Ideal.lean#L95 [MemorylessSource.memoryless_eq]: src/Commons/Definitions/Ideal.lean#L103 [cc_normalize]: src/ConstructiveCryptography/Tactics/Basic.lean#L30 @@ -1352,11 +1402,11 @@ agreeing with a map on a finite set $`S`$: there are $`\lvert Y \rvert^{\lvert X [collision_win_le]: src/Examples/Games.lean#L165 [hybrid_ideal_advantage_le]: src/Examples/Games.lean#L190 [attach_hybrid_ideal_advantage_le]: src/Examples/Games.lean#L209 -[correctedChain]: src/Examples/AuthenticatedEncryption/Security.lean#L93 -[correctedChain_cca]: src/Examples/AuthenticatedEncryption/Security.lean#L112 -[correctedChain_ptxt]: src/Examples/AuthenticatedEncryption/Security.lean#L117 +[correctedChain]: src/Examples/AuthenticatedEncryption/Security.lean#L102 +[correctedChain_cca]: src/Examples/AuthenticatedEncryption/Security.lean#L121 +[correctedChain_ptxt]: src/Examples/AuthenticatedEncryption/Security.lean#L126 [ae_of_ind_cca_int_ptxt]: src/Examples/AuthenticatedEncryption/Security.lean#L57 -[real_ideal_distance_le]: src/Examples/AuthenticatedEncryption/Security.lean#L123 +[real_ideal_distance_le]: src/Examples/AuthenticatedEncryption/Security.lean#L132 [construction_with_right_context]: src/Examples/Substitution.lean#L43 [construction_with_left_context]: src/Examples/Substitution.lean#L70 [constructsWithin_of_two_substitutions]: src/Examples/Substitution.lean#L120 diff --git a/lakefile.lean b/lakefile.lean index 56c3626..8e58c79 100644 --- a/lakefile.lean +++ b/lakefile.lean @@ -18,7 +18,7 @@ lean_lib Probability where globs := #[.andSubmodules `Probability] /-- Random systems, deterministic and probabilistic converters, attachment, -parallel composition, distance and games. -/ +parallel composition, distance and games; typed systems and typed converters on interfaces. -/ @[default_target] lean_lib RandomSystems where globs := #[.andSubmodules `RandomSystems] diff --git a/src/Commons/Definitions/AEAD.lean b/src/Commons/Definitions/AEAD.lean index 5b534c9..aa55521 100644 --- a/src/Commons/Definitions/AEAD.lean +++ b/src/Commons/Definitions/AEAD.lean @@ -136,28 +136,28 @@ scoped notation "ρ^ae" => AE.Ideal.perPort _ _ for `k ← Gen`, at the budget `q` per port. -/ def AE.INDCCA.systems [DecidableEq K] [DecidableEq M] [DecidableEq C] [Nonempty M] (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : - Interface.Resource (AE.perPort M C q) × Interface.Resource (AE.perPort M C q) := + TypedSystem (AE.perPort M C q) × TypedSystem (AE.perPort M C q) := (AE.Real.perPort scheme, AE.CCA.perPort M C • AE.Real.perPort scheme) /-- **The systems of int-ptxt** (Banfi, Definition 2.3.6): `⟦E_k, D_k⟧` and `ρ^ptxt(⟦E_k, D_k⟧)`, for `k ← Gen`, at the budget `q` per port. -/ def AE.INTPTXT.systems [DecidableEq K] [DecidableEq M] (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : - Interface.Resource (AE.perPort M C q) × Interface.Resource (AE.perPort M C q) := + TypedSystem (AE.perPort M C q) × TypedSystem (AE.perPort M C q) := (AE.Real.perPort scheme, AE.PTXT.perPort M C • AE.Real.perPort scheme) /-- **The systems of int-ctxt** (Banfi, Definition 2.3.7): `⟦E_k, D_k⟧` and `ρ^ctxt(E_k)`, for `k ← Gen`, at the budget `q` per port. -/ def AE.INTCTXT.systems [DecidableEq K] [DecidableEq M] [DecidableEq C] (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : - Interface.Resource (AE.perPort M C q) × Interface.Resource (AE.perPort M C q) := + TypedSystem (AE.perPort M C q) × TypedSystem (AE.perPort M C q) := (AE.Real.perPort scheme, AE.CTXT.perPort M C • Encryption.Real.perPort scheme) /-- **The systems of ae** (Banfi, Definition 2.3.8): `⟦E_k, D_k⟧` and `⟦E$_k, D^⊥⟧ = ρ^ae(E_k)`, for `k ← Gen`, at the budget `q` per port. -/ def AE.Secure.systems [DecidableEq K] [DecidableEq M] [DecidableEq C] [Nonempty M] (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : - Interface.Resource (AE.perPort M C q) × Interface.Resource (AE.perPort M C q) := + TypedSystem (AE.perPort M C q) × TypedSystem (AE.perPort M C q) := (AE.Real.perPort scheme, AE.Ideal.perPort M C • Encryption.Real.perPort scheme) /-- **ind-cca** within `error`: against the admitted distinguishers, `⟦E_k, D_k⟧` substitutes diff --git a/src/Commons/Definitions/Cipher.lean b/src/Commons/Definitions/Cipher.lean index a3d9710..7ba4fe5 100644 --- a/src/Commons/Definitions/Cipher.lean +++ b/src/Commons/Definitions/Cipher.lean @@ -59,15 +59,15 @@ variable [Fintype K] [Nonempty K] [Fintype X] {q : ℕ} /-- **The block cipher under a uniform key**: `E_k` for `k` uniform, answering each input with its encryption. -/ -def BlockCipher.Real (E : BlockCipher K X) : Interface.Resource (Evaluation X X q) := - Interface.Resource.sample (Distribution.uniform K) fun k => - Interface.Resource.ofFunction fun _ x => E.encrypt k x +def BlockCipher.Real (E : BlockCipher K X) : TypedSystem (Evaluation X X q) := + TypedSystem.sample (Distribution.uniform K) fun k => + TypedSystem.ofFunction fun _ x => E.encrypt k x /-- **The block cipher and its inverse under a uniform key**: `E_k` answering forward queries and `D_k` answering inverse queries, for `k` uniform. -/ -def BlockCipher.StrongReal (E : BlockCipher K X) : Interface.Resource (Bidirectional X q) := - Interface.Resource.sample (Distribution.uniform K) fun k => - Interface.Resource.ofFunction fun +def BlockCipher.StrongReal (E : BlockCipher K X) : TypedSystem (Bidirectional X q) := + TypedSystem.sample (Distribution.uniform K) fun k => + TypedSystem.ofFunction fun | .forward => fun x => E.encrypt k x | .inverse => fun y => E.decrypt k y diff --git a/src/Commons/Definitions/DiffieHellman.lean b/src/Commons/Definitions/DiffieHellman.lean index 88b8a33..4089ff0 100644 --- a/src/Commons/Definitions/DiffieHellman.lean +++ b/src/Commons/Definitions/DiffieHellman.lean @@ -54,7 +54,7 @@ system CDH.Ideal(q : ℕ) [NeZero q] (g : G) : CDH G /-- **The systems of the CDH assumption**: the real and the ideal system, at the budget `budget`. -/ noncomputable def CDH.Assumption.systems (q : ℕ) [NeZero q] (g : G) [DecidableEq G] (budget : ℕ) : - Interface.Resource (CDH G budget) × Interface.Resource (CDH G budget) := + TypedSystem (CDH G budget) × TypedSystem (CDH G budget) := (CDH.Real q g, CDH.Ideal q g) /-- **The CDH assumption** within `error`: against the admitted distinguishers, the real system diff --git a/src/Commons/Definitions/Encryption.lean b/src/Commons/Definitions/Encryption.lean index 1a4b270..1c6b29d 100644 --- a/src/Commons/Definitions/Encryption.lean +++ b/src/Commons/Definitions/Encryption.lean @@ -90,7 +90,7 @@ scoped notation "ρ^cpa" => Encryption.CPA.perPort _ _ at the budget `q` per port. -/ def Encryption.INDCPA.systems [DecidableEq K] [DecidableEq M] [Nonempty M] (scheme : SymmetricEncryption K M C) (q : Encryption.Port → ℕ) : - Interface.Resource (Encryption.perPort M C q) × Interface.Resource (Encryption.perPort M C q) := + TypedSystem (Encryption.perPort M C q) × TypedSystem (Encryption.perPort M C q) := (Encryption.Real.perPort scheme, Encryption.CPA.perPort M C • Encryption.Real.perPort scheme) /-- **ind-cpa** within `error`: against the admitted distinguishers, `E_k` substitutes for @@ -119,7 +119,7 @@ converter Encryption.Right(M C : Type) [Fintype M] [Fintype C] : LeftRight M C /-- **The systems of left-or-right CPA** (Boneh–Shoup, Attack Game 5.2): `E_k` on the left message of each pair, and on the right one, for `k ← Gen`, at the budget `q`. -/ def Encryption.LORCPA.systems [DecidableEq K] [DecidableEq M] (scheme : SymmetricEncryption K M C) - (q : ℕ) : Interface.Resource (LeftRight M C q) × Interface.Resource (LeftRight M C q) := + (q : ℕ) : TypedSystem (LeftRight M C q) × TypedSystem (LeftRight M C q) := (Encryption.Left M C • Encryption.Real scheme, Encryption.Right M C • Encryption.Real scheme) /-- **Left-or-right CPA** within `error`: against the admitted distinguishers, encrypting the left diff --git a/src/Commons/Definitions/Hash.lean b/src/Commons/Definitions/Hash.lean index c2a9c22..8167fcf 100644 --- a/src/Commons/Definitions/Hash.lean +++ b/src/Commons/Definitions/Hash.lean @@ -56,7 +56,7 @@ system Hash.Ideal(K M : Type) [Fintype K] [Nonempty K] [Fintype M] [DecidableEq /-- **The systems of collision resistance**: the collisions of `H(k, ·)` for a published `k ← K`, and the equalities of messages, at the budget `q`. -/ def Hash.CR.systems [DecidableEq M] [DecidableEq T] (H : K → M → T) (q : ℕ) : - Interface.Resource (KeyedCollision K M q) × Interface.Resource (KeyedCollision K M q) := + TypedSystem (KeyedCollision K M q) × TypedSystem (KeyedCollision K M q) := (Hash.Real H, Hash.Ideal K M) /-- **Collision resistance** within `error`: against the admitted distinguishers, the collisions diff --git a/src/Commons/Definitions/Ideal.lean b/src/Commons/Definitions/Ideal.lean index b59c6ac..a60d9c6 100644 --- a/src/Commons/Definitions/Ideal.lean +++ b/src/Commons/Definitions/Ideal.lean @@ -1,6 +1,6 @@ import ConstructiveCryptography.DSL -import ConstructiveCryptography.Functional -import ConstructiveCryptography.Memoryless +import RandomSystems.Typed.Functional +import RandomSystems.Typed.Memoryless import Mathlib.Data.Fintype.Perm /-! @@ -51,36 +51,36 @@ open Classical /-- **The uniform random function** on `A`: at each label, a uniformly random function from its inputs to its outputs. On `Evaluation X Y q` it is the `(X, Y)`-URF. -/ -def URF (A : Interface) [∀ i, Nonempty (A.Y i)] : Interface.Resource A := - Interface.Resource.sample (Distribution.uniform (∀ i, A.X i → A.Y i)) Interface.Resource.ofFunction +def URF (A : Interface) [∀ i, Nonempty (A.Y i)] : TypedSystem A := + TypedSystem.sample (Distribution.uniform (∀ i, A.X i → A.Y i)) TypedSystem.ofFunction /-- **The uniform random permutation** on `A`: at each label, a uniformly random bijection from its inputs to its outputs. On `Evaluation X X q` it is the `X`-URP. -/ -def URP (A : Interface) [∀ i, Nonempty (A.X i ≃ A.Y i)] : Interface.Resource A := - Interface.Resource.sample (Distribution.uniform (∀ i, A.X i ≃ A.Y i)) - fun π => Interface.Resource.ofFunction fun i x => π i x +def URP (A : Interface) [∀ i, Nonempty (A.X i ≃ A.Y i)] : TypedSystem A := + TypedSystem.sample (Distribution.uniform (∀ i, A.X i ≃ A.Y i)) + fun π => TypedSystem.ofFunction fun i x => π i x variable (T X : Type) [Fintype T] [Fintype X] {q : ℕ} /-- **The strong uniform random permutation**: a uniformly random permutation of `X`, answering forward queries with it and inverse queries with its inverse. -/ -def StrongURP : Interface.Resource (Bidirectional X q) := - Interface.Resource.sample (Distribution.uniform (Equiv.Perm X)) fun π => - Interface.Resource.ofFunction fun +def StrongURP : TypedSystem (Bidirectional X q) := + TypedSystem.sample (Distribution.uniform (Equiv.Perm X)) fun π => + TypedSystem.ofFunction fun | .forward => fun x => π x | .inverse => fun y => π.symm y /-- **The tweakable uniform random permutation**: an independent uniformly random permutation of `X` for each tweak. -/ -def TweakableURP : Interface.Resource (TweakedEvaluation T X q) := - Interface.Resource.sample (Distribution.uniform (T → Equiv.Perm X)) fun π => - Interface.Resource.ofFunction fun _ tx => π tx.1 tx.2 +def TweakableURP : TypedSystem (TweakedEvaluation T X q) := + TypedSystem.sample (Distribution.uniform (T → Equiv.Perm X)) fun π => + TypedSystem.ofFunction fun _ tx => π tx.1 tx.2 /-- **The strong tweakable uniform random permutation**: the tweakable URP, answering inverse queries with the inverse permutation of their tweak. -/ -def TweakableStrongURP : Interface.Resource (TweakedBidirectional T X q) := - Interface.Resource.sample (Distribution.uniform (T → Equiv.Perm X)) fun π => - Interface.Resource.ofFunction fun +def TweakableStrongURP : TypedSystem (TweakedBidirectional T X q) := + TypedSystem.sample (Distribution.uniform (T → Equiv.Perm X)) fun π => + TypedSystem.ofFunction fun | .forward => fun tx => π tx.1 tx.2 | .inverse => fun ty => (π ty.1).symm ty.2 @@ -111,10 +111,10 @@ lemma MemorylessSource.memoryless_eq {Y : Type} [Fintype Y] (ν : ProbDist Y) -- -- The source of samples is memoryless, so by the composition law the system is memoryless with -- the reply law of one invocation of the program. - -- The composition law `Interface.Converter.ofProgram_smul_memoryless`, with the source of - -- samples memoryless (`Interface.source_eq_memoryless`); the law of one invocation remains. - refine Interface.Converter.ofProgram_smul_memoryless none _ _ _ - (Interface.source_eq_memoryless _ _) ?_ + -- The composition law `TypedConverter.ofProgram_smul_memoryless`, with the source of + -- samples memoryless (`TypedSystem.source_eq_memoryless`); the law of one invocation remains. + refine TypedConverter.ofProgram_smul_memoryless none _ _ _ + (TypedSystem.source_eq_memoryless _ _) ?_ -- One invocation: draw `y ← ν` and reply `y`. Its law is `ν`, in both initialization states -- (`none` before the first call, `some ()` after). rintro (_ | ⟨⟩) ⟨⟩ ⟨⟩ diff --git a/src/Commons/Definitions/KEM.lean b/src/Commons/Definitions/KEM.lean index d300867..7a811eb 100644 --- a/src/Commons/Definitions/KEM.lean +++ b/src/Commons/Definitions/KEM.lean @@ -106,8 +106,8 @@ converter KEM.CCA(PK C K : Type) [Fintype PK] [Fintype C] [Fintype K] [Decidable `(pk, sk) ← G`, at the budget `q` per port. -/ def KEM.INDCCA.systems [DecidableEq PK] [DecidableEq C] [Nonempty K] (kem : KEM PK SK C K) (q : Encapsulation.Port → ℕ) : - Interface.Resource (Encapsulation.perPort PK C K q) × - Interface.Resource (Encapsulation.perPort PK C K q) := + TypedSystem (Encapsulation.perPort PK C K q) × + TypedSystem (Encapsulation.perPort PK C K q) := (KEM.Real.perPort kem, KEM.CCA.perPort PK C K • KEM.Real.perPort kem) /-- **IND-CCA** within `error`: against the admitted distinguishers, the real system substitutes @@ -122,8 +122,8 @@ def KEM.INDCCA [Interface.AdmissibleDistinguishers] per port with none at `decaps`. -/ def KEM.INDCPA.systems [DecidableEq PK] [DecidableEq C] [Nonempty K] (kem : KEM PK SK C K) (q : Encapsulation.Port → ℕ) : - Interface.Resource (Encapsulation.perPort PK C K (Function.update q .decaps 0)) × - Interface.Resource (Encapsulation.perPort PK C K (Function.update q .decaps 0)) := + TypedSystem (Encapsulation.perPort PK C K (Function.update q .decaps 0)) × + TypedSystem (Encapsulation.perPort PK C K (Function.update q .decaps 0)) := KEM.INDCCA.systems kem (Function.update q .decaps 0) /-- **IND-CPA** within `error`: against the admitted distinguishers, the real system without diff --git a/src/Commons/Definitions/MAC.lean b/src/Commons/Definitions/MAC.lean index d599dbf..ef2005b 100644 --- a/src/Commons/Definitions/MAC.lean +++ b/src/Commons/Definitions/MAC.lean @@ -102,14 +102,14 @@ converter MAC.SUF(M T : Type) [Fintype M] [Fintype T] [DecidableEq M] [Decidable /-- **The systems of EUF-CMA**: the real system and the one whose verification accepts only tags on tagged messages, for `k ← G`, at the budget `q` per port. -/ def MAC.EUFCMA.systems [DecidableEq K] [DecidableEq M] (mac : MAC K M T) (q : Tagging.Port → ℕ) : - Interface.Resource (Tagging.perPort M T q) × Interface.Resource (Tagging.perPort M T q) := + TypedSystem (Tagging.perPort M T q) × TypedSystem (Tagging.perPort M T q) := (MAC.Real.perPort mac, MAC.EUF.perPort M T • MAC.Real.perPort mac) /-- **The systems of SUF-CMA**: the real system and the one whose verification accepts only tagged pairs, for `k ← G`, at the budget `q` per port. -/ def MAC.SUFCMA.systems [DecidableEq K] [DecidableEq M] [DecidableEq T] (mac : MAC K M T) (q : Tagging.Port → ℕ) : - Interface.Resource (Tagging.perPort M T q) × Interface.Resource (Tagging.perPort M T q) := + TypedSystem (Tagging.perPort M T q) × TypedSystem (Tagging.perPort M T q) := (MAC.Real.perPort mac, MAC.SUF.perPort M T • MAC.Real.perPort mac) /-- **EUF-CMA** within `error`: against the admitted distinguishers, the real system substitutes diff --git a/src/Commons/Definitions/PRG.lean b/src/Commons/Definitions/PRG.lean index 39aeb99..543babb 100644 --- a/src/Commons/Definitions/PRG.lean +++ b/src/Commons/Definitions/PRG.lean @@ -33,9 +33,9 @@ variable {S R : Type} [Fintype S] [Nonempty S] [Fintype R] [Nonempty R] /-- **The systems of PRG security**: `G s` for a uniform seed `s`, and a uniform element of `R`, at the budget `q`. -/ def PRG.Secure.systems (G : S → R) (q : ℕ) : - Interface.Resource (Evaluation Unit R q) × Interface.Resource (Evaluation Unit R q) := - (Interface.Resource.sample (Distribution.uniform S) - fun s => Interface.Resource.ofFunction fun _ _ => G s, + TypedSystem (Evaluation Unit R q) × TypedSystem (Evaluation Unit R q) := + (TypedSystem.sample (Distribution.uniform S) + fun s => TypedSystem.ofFunction fun _ _ => G s, URF (Evaluation Unit R q)) /-- **PRG security** within `error`: against the admitted distinguishers, `G` on a uniform seed diff --git a/src/Commons/Definitions/PublicKeyEncryption.lean b/src/Commons/Definitions/PublicKeyEncryption.lean index 6e78fde..79ab2d7 100644 --- a/src/Commons/Definitions/PublicKeyEncryption.lean +++ b/src/Commons/Definitions/PublicKeyEncryption.lean @@ -101,7 +101,7 @@ converter PKE.CCA(PK M C : Type) [Fintype PK] [Fintype M] [Fintype C] [Decidable `(pk, sk) ← G`, at the budget `q` per port. -/ def PKE.INDCCA.systems [DecidableEq PK] [DecidableEq M] [DecidableEq C] [Nonempty M] (scheme : PublicKeyEncryption PK SK M C) (q : PKE.Port → ℕ) : - Interface.Resource (PKE.perPort PK M C q) × Interface.Resource (PKE.perPort PK M C q) := + TypedSystem (PKE.perPort PK M C q) × TypedSystem (PKE.perPort PK M C q) := (PKE.Real.perPort scheme, PKE.CCA.perPort PK M C • PKE.Real.perPort scheme) /-- **IND-CCA** within `error`: against the admitted distinguishers, the real system substitutes @@ -116,8 +116,8 @@ def PKE.INDCCA [Interface.AdmissibleDistinguishers] IND-CCA without decryption queries, at the budget `q` per port with none at `dec`. -/ def PKE.INDCPA.systems [DecidableEq PK] [DecidableEq M] [DecidableEq C] [Nonempty M] (scheme : PublicKeyEncryption PK SK M C) (q : PKE.Port → ℕ) : - Interface.Resource (PKE.perPort PK M C (Function.update q .dec 0)) × - Interface.Resource (PKE.perPort PK M C (Function.update q .dec 0)) := + TypedSystem (PKE.perPort PK M C (Function.update q .dec 0)) × + TypedSystem (PKE.perPort PK M C (Function.update q .dec 0)) := PKE.INDCCA.systems scheme (Function.update q .dec 0) /-- **IND-CPA** within `error`: against the admitted distinguishers, the real system without diff --git a/src/Commons/Definitions/Signature.lean b/src/Commons/Definitions/Signature.lean index 5eddb73..4368e8c 100644 --- a/src/Commons/Definitions/Signature.lean +++ b/src/Commons/Definitions/Signature.lean @@ -118,8 +118,8 @@ converter SignatureScheme.SUF(PK M Sig : Type) [Fintype PK] [Fintype M] [Fintype signatures on signed messages, for `(pk, sk) ← G`, at the budget `q` per port. -/ def SignatureScheme.EUFCMA.systems [DecidableEq SK] [DecidableEq M] (scheme : SignatureScheme PK SK M Sig) (q : Signing.Port → ℕ) : - Interface.Resource (Signing.perPort PK M Sig q) × - Interface.Resource (Signing.perPort PK M Sig q) := + TypedSystem (Signing.perPort PK M Sig q) × + TypedSystem (Signing.perPort PK M Sig q) := (SignatureScheme.Real.perPort scheme, SignatureScheme.EUF.perPort PK M Sig • SignatureScheme.Real.perPort scheme) @@ -127,8 +127,8 @@ def SignatureScheme.EUFCMA.systems [DecidableEq SK] [DecidableEq M] pairs, for `(pk, sk) ← G`, at the budget `q` per port. -/ def SignatureScheme.SUFCMA.systems [DecidableEq SK] [DecidableEq M] [DecidableEq Sig] (scheme : SignatureScheme PK SK M Sig) (q : Signing.Port → ℕ) : - Interface.Resource (Signing.perPort PK M Sig q) × - Interface.Resource (Signing.perPort PK M Sig q) := + TypedSystem (Signing.perPort PK M Sig q) × + TypedSystem (Signing.perPort PK M Sig q) := (SignatureScheme.Real.perPort scheme, SignatureScheme.SUF.perPort PK M Sig • SignatureScheme.Real.perPort scheme) diff --git a/src/Commons/Definitions/UniversalHash.lean b/src/Commons/Definitions/UniversalHash.lean index f15857d..6fcfc73 100644 --- a/src/Commons/Definitions/UniversalHash.lean +++ b/src/Commons/Definitions/UniversalHash.lean @@ -68,7 +68,7 @@ system UniversalHash.DifferenceIdeal(M T : Type) [Fintype M] [DecidableEq M] [Fi /-- **The systems of a UHF**: the collisions of `H(k, ·)` for `k ← K`, and the equalities of messages, at the budget `q`. -/ def UniversalHash.UHF.systems [DecidableEq M] [DecidableEq T] (H : K → M → T) (q : ℕ) : - Interface.Resource (Collision M q) × Interface.Resource (Collision M q) := + TypedSystem (Collision M q) × TypedSystem (Collision M q) := (UniversalHash.Real H, UniversalHash.Ideal M) /-- **UHF** within `error`: against the admitted distinguishers, the collisions of `H(k, ·)` @@ -82,7 +82,7 @@ def UniversalHash.UHF [Interface.AdmissibleDistinguishers] differences, at the budget `q`. -/ def UniversalHash.DUF.systems [DecidableEq M] [Fintype T] [DecidableEq T] [AddCommGroup T] (H : K → M → T) (q : ℕ) : - Interface.Resource (Difference M T q) × Interface.Resource (Difference M T q) := + TypedSystem (Difference M T q) × TypedSystem (Difference M T q) := (UniversalHash.DifferenceReal H, UniversalHash.DifferenceIdeal M T) /-- **DUF** within `error`: against the admitted distinguishers, the digest differences of diff --git a/src/Commons/Schemes/MAC/NMAC.lean b/src/Commons/Schemes/MAC/NMAC.lean index b42a031..f0432f5 100644 --- a/src/Commons/Schemes/MAC/NMAC.lean +++ b/src/Commons/Schemes/MAC/NMAC.lean @@ -42,9 +42,9 @@ variable [Fintype C] [Nonempty C] [Fintype M] {q : ℕ} /-- **NMAC under two uniform keys**: for independent uniform `K₁` and `K₂`, each message is answered with NMAC of its blocks. -/ def Real (f : C → B → C) (pad : C ↪ B) (blockForm : M → List B) : - Interface.Resource (Evaluation M C q) := - Interface.Resource.sample (Distribution.uniform (C × C)) fun keys => - Interface.Resource.ofFunction fun _ message => nmac f pad keys (blockForm message) + TypedSystem (Evaluation M C q) := + TypedSystem.sample (Distribution.uniform (C × C)) fun keys => + TypedSystem.ofFunction fun _ message => nmac f pad keys (blockForm message) end diff --git a/src/ConstructiveCryptography.lean b/src/ConstructiveCryptography.lean index e9bfc6b..0d06800 100644 --- a/src/ConstructiveCryptography.lean +++ b/src/ConstructiveCryptography.lean @@ -1,7 +1,5 @@ import ConstructiveCryptography.Construction.Basic import ConstructiveCryptography.Construction.Defs -import ConstructiveCryptography.ConverterCoherence -import ConstructiveCryptography.Automaton import ConstructiveCryptography.CryptographicAlgebra.Basic import ConstructiveCryptography.CryptographicAlgebra.Distinguisher import ConstructiveCryptography.CryptographicAlgebra.Epsilon @@ -9,31 +7,13 @@ import ConstructiveCryptography.CryptographicAlgebra.Game import ConstructiveCryptography.CryptographicAlgebra.PseudoMetric import ConstructiveCryptography.CryptographicAlgebra.Relaxation import ConstructiveCryptography.CryptographicAlgebra.Star -import ConstructiveCryptography.DDCCoherence -import ConstructiveCryptography.Functional -import ConstructiveCryptography.Interface import ConstructiveCryptography.InterfaceAlgebra -import ConstructiveCryptography.InterfaceCoherence -import ConstructiveCryptography.InterfaceFilter +import ConstructiveCryptography.InterfaceCategory import ConstructiveCryptography.InterfaceGame import ConstructiveCryptography.InterfaceMonoidal -import ConstructiveCryptography.InterfaceParallel -import ConstructiveCryptography.InterfaceRelabel -import ConstructiveCryptography.InterfaceTensorRename -import ConstructiveCryptography.Memoryless import ConstructiveCryptography.Notation -import ConstructiveCryptography.PresentedGame import ConstructiveCryptography.DSL -import ConstructiveCryptography.DSL.Converters import ConstructiveCryptography.DSL.Elaborator -import ConstructiveCryptography.DSL.Probability -import ConstructiveCryptography.DSL.Programs -import ConstructiveCryptography.DSL.Syntax -import ConstructiveCryptography.DSL.Tactics -import ConstructiveCryptography.ResourceCoherence -import ConstructiveCryptography.ResourceParallel -import ConstructiveCryptography.ResourceParallelAttachment -import ConstructiveCryptography.Source import ConstructiveCryptography.Specification import ConstructiveCryptography.Specification.Action import ConstructiveCryptography.Specification.Basic @@ -52,7 +32,6 @@ import ConstructiveCryptography.Specification.Star import ConstructiveCryptography.Specification.Star.Metric import ConstructiveCryptography.Substitution.Basic import ConstructiveCryptography.Substitution.Construction -import ConstructiveCryptography.Context import ConstructiveCryptography.Substitution.Implication import ConstructiveCryptography.Substitution.Parallel import ConstructiveCryptography.Substitution.Quantitative @@ -64,8 +43,8 @@ import ConstructiveCryptography.Tactics.Substitution import ConstructiveCryptography.Tactics.ProofAutomationAttributes /-! -Constructive Cryptography: interfaces and domains, arrows, resources and the action, parallel -composition, the resource distance, memoryless systems, specifications of resources, filters, -budgets, functional constructors, games presented by discrete games; the categorical packaging; -and the extensions (substitution, the DSL). +Constructive Cryptography: the classes of cryptographic algebras (attachment, parallel +composition, distance, distinguishers, games), specifications, constructions and substitution; +their instances on interfaces, whose fields are the typed systems and typed converters of +`RandomSystems.Typed`; the notation, the proof commands and the DSL front end. -/ diff --git a/src/ConstructiveCryptography/Context.lean b/src/ConstructiveCryptography/Context.lean deleted file mode 100644 index 43e259f..0000000 --- a/src/ConstructiveCryptography/Context.lean +++ /dev/null @@ -1,121 +0,0 @@ -import ConstructiveCryptography.ResourceParallelAttachment -import ConstructiveCryptography.ResourceCoherence -import ConstructiveCryptography.InterfaceMonoidal -import RandomSystems.Converter.EmptyInterface - -/-! -# Fixed contexts - -A resource `R` on `A` is a converter from `A` to the unit interface (`resourceConverter`): -the PDC of the DDC readings (`resourcePDC`) of the deterministic resources presenting `R`. -Attaching it to the unit resource gives `R`. In parallel with the identity it gives the fixed -contexts: attaching `rightContext A S` to `R` is `R ∥ S`, and so is attaching -`leftContext R B` to `S`. - -## Main definitions - -* `Interface.resourceConverter R`: `R` as a converter with no inside interfaces -* `Interface.constant R B`: the converter that ignores its inside resource and exposes `R` -* `Interface.rightContext A S`, `Interface.leftContext R B`: the fixed contexts - -## Main results - -* `Interface.attach_resourceConverter`, `Interface.attach_constant`: attaching them gives `R` -* `Interface.attach_rightContext`, `Interface.attach_leftContext`: attaching a context is parallel - composition - -Source: Jost, §2.2.2 and Proposition 2.2.3. --/ - -namespace SystemAlgebra.Interface - -open Classical Probability CategoryTheory MonoidalCategory - -variable {A B : Interface} - -/-! ## A resource as a converter with no inside interfaces -/ - -/-- A resource as a converter with no inside interfaces: the PDC of the DDC readings of a -presentation of the resource. -/ -noncomputable def resourceConverter (R : Interface.Resource A) : A ⟶ Interface.unit := - PDCBehavior.ofPDC (resourcePDC R.exists_ofPDS.choose) - -/-- The unit interface has exactly one resource. -/ -lemma resource_empty_eq (S : Interface.Resource Interface.unit) : S = Interface.dummy := by - apply Subtype.ext - apply RandomSystem.ext - rintro (_ | ⟨⟨⟨e, _⟩, _⟩, _⟩) - · rw [S.1.mass_nil, Interface.dummy.1.mass_nil] - · exact e.elim - -lemma attach_resourceConverter (R : Interface.Resource A) - (S : Interface.Resource Interface.unit) : - (resourceConverter R • S : Interface.Resource A) = R := by - rw [resource_empty_eq S] - have hQ := R.exists_ofPDS.choose_spec - apply Subtype.ext - apply RandomSystem.ext - intro h - rw [Interface.smul_val, PDCBehavior.attach_presents Interface.unit.nonempty_prefix - A.nonempty_prefix (resourceConverter R) Interface.dummy.1 Interface.dummy.2 - (resourcePDC R.exists_ofPDS.choose) _ (fun _ => rfl) (fun _ => rfl) h, - behaviorMass_attachPDS, Distribution.prod_single_right, Distribution.mass_fTransform] - conv_rhs => rw [← hQ] - change _ = R.exists_ofPDS.choose.1.mass _ - rw [resourcePDC, Distribution.mass_fTransform] - refine Distribution.mass_congr _ fun s => ?_ - dsimp only - erw [apply_resourceDDC _ s.2.1.1, s.2.1.trim_eq] - -/-! ## Constant converters and fixed contexts -/ - -/-- The converter that attaches to any resource and exposes no interface. -/ -noncomputable def discardConverter (B : Interface) : Interface.unit ⟶ B := - Interface.ofDDC (discardSystem B.I B.X B.Y) (discardSystem_isDDCFrom B.domain) - -/-- A constant converter: it ignores its inside resource and exposes `R`. No -efficiency claim is made for this unrestricted mathematical converter. -/ -noncomputable def constant (R : Interface.Resource A) (B : Interface) : A ⟶ B := - resourceConverter R ≫ discardConverter B - -lemma attach_constant (R : Interface.Resource A) {B : Interface} (S : Interface.Resource B) : - (constant R B • S : Interface.Resource A) = R := by - rw [constant, Interface.comp_smul, attach_resourceConverter] - -lemma rightUnitor_hom_attach (R : Interface.Resource A) : - ((Interface.rightUnitor A).hom • R : Interface.Resource (Interface.tensor A Interface.unit)) = - Interface.parallel R Interface.dummy := by - have h := congrArg (fun S : Interface.Resource A => ((Interface.rightUnitor A).hom • S : - Interface.Resource (Interface.tensor A Interface.unit))) (Interface.parallel_dummy_right R) - rw [← Interface.comp_smul, Iso.hom_inv_id, Interface.identity_attach] at h - exact h.symm - -lemma leftUnitor_hom_attach (R : Interface.Resource A) : - ((Interface.leftUnitor A).hom • R : Interface.Resource (Interface.tensor Interface.unit A)) = - Interface.parallel Interface.dummy R := by - have h := congrArg (fun S : Interface.Resource A => ((Interface.leftUnitor A).hom • S : - Interface.Resource (Interface.tensor Interface.unit A))) (Interface.parallel_dummy_left R) - rw [← Interface.comp_smul, Iso.hom_inv_id, Interface.identity_attach] at h - exact h.symm - -/-- The fixed right context, expressed in the existing converter category. -/ -noncomputable def rightContext (A : Interface) {B : Interface} (S : Interface.Resource B) : - A ⊗ B ⟶ A := - (𝟙 A ⊗ₘ resourceConverter S) ≫ (Interface.rightUnitor A).hom - -/-- The fixed left context; no symmetry of the selected substitution relation is used. -/ -noncomputable def leftContext {A : Interface} (R : Interface.Resource A) (B : Interface) : - A ⊗ B ⟶ B := - (resourceConverter R ⊗ₘ 𝟙 B) ≫ (Interface.leftUnitor B).hom - -lemma attach_rightContext (R : Interface.Resource A) (S : Interface.Resource B) : - (rightContext A S • R : Interface.Resource (A ⊗ B)) = Interface.parallel R S := by - rw [rightContext, Interface.comp_smul, rightUnitor_hom_attach, Interface.tensorHom_eq, Interface.parallel_attach, Interface.identity_attach, - attach_resourceConverter] - -lemma attach_leftContext (R : Interface.Resource A) (S : Interface.Resource B) : - (leftContext R B • S : Interface.Resource (A ⊗ B)) = Interface.parallel R S := by - rw [leftContext, Interface.comp_smul, leftUnitor_hom_attach, Interface.tensorHom_eq, Interface.parallel_attach, Interface.identity_attach, - attach_resourceConverter] - -end SystemAlgebra.Interface diff --git a/src/ConstructiveCryptography/DSL.lean b/src/ConstructiveCryptography/DSL.lean index 3a0707f..d903635 100644 --- a/src/ConstructiveCryptography/DSL.lean +++ b/src/ConstructiveCryptography/DSL.lean @@ -3,9 +3,10 @@ import ConstructiveCryptography.DSL.Elaborator /-! # The cryptographic component DSL -`interface`, `system`, `converter` and `filter` declarations elaborate to finite systems and -converters at every query budget: each component compiles to a deterministic program, and its -sampling to sources of fresh samples. Open `SystemAlgebra.DSL` and -`open scoped SystemAlgebra SystemAlgebra.DSL` for the declarations and assembly operations. +`interface`, `system`, `converter` and `filter` declarations elaborate to typed systems and +typed converters at every query budget: each component compiles to a deterministic program +(`RandomSystems.Typed.DSL`), and its sampling to sources of fresh samples. Open +`SystemAlgebra.DSL` and `open scoped SystemAlgebra SystemAlgebra.DSL` for the declarations and +assembly operations. `DSL/GRAMMAR.md` specifies the syntax and what each declaration generates. -/ diff --git a/src/ConstructiveCryptography/DSL/Elaborator.lean b/src/ConstructiveCryptography/DSL/Elaborator.lean index ce9fdfd..e2c4d9e 100644 --- a/src/ConstructiveCryptography/DSL/Elaborator.lean +++ b/src/ConstructiveCryptography/DSL/Elaborator.lean @@ -1,10 +1,10 @@ -import ConstructiveCryptography.DSL.Syntax -import ConstructiveCryptography.DSL.Converters -import ConstructiveCryptography.DSL.Tactics -import ConstructiveCryptography.Source -import ConstructiveCryptography.Context -import ConstructiveCryptography.InterfaceFilter -import ConstructiveCryptography.InterfaceCoherence +import RandomSystems.Typed.DSL.Syntax +import RandomSystems.Typed.DSL.Converters +import RandomSystems.Typed.DSL.Tactics +import RandomSystems.Typed.Source +import RandomSystems.Typed.Context +import RandomSystems.Typed.Filter +import RandomSystems.Typed.InterfaceCoherence import ConstructiveCryptography.Notation /-! @@ -18,7 +18,10 @@ that samples nothing is the deterministic system of its program. Initialization first invocation. A converter gets its inferred per-call bound `C.bound` and the arrow from budget `q` to `C.bound * q` inside queries, plus the exact arrow `C.exact` when its number of inside calls is a function of the input; a filter is the arrow from the restricted budget. -System definitions take their budget from their outermost component. +System definitions take their budget from their outermost component. The compiler is a front end +on the category of interfaces: systems are `TypedSystem`s, and converters, built from +`TypedConverter.ofProgram` and its variants, are declared as arrows `A ⟶ B` of +`Interface.category`, so that components assemble with `≫` and `⊗ₘ`. -/ namespace SystemAlgebra.DSL @@ -556,8 +559,8 @@ def elabPerPortDecls (converting : Bool) (name : Ident) if !converting then let (randK, admitsK, _) ← insideInterfaces sites used k elabCommand (← `(noncomputable def $perPortName:ident $params:bracketedBinder* - {$q : ($sigZero).I → ℕ} : Interface.Resource $sigPP := - (Interface.Converter.ofProgram none ($bodyName $args*) ($boundSpecName $args*) $admitsK : + {$q : ($sigZero).I → ℕ} : TypedSystem $sigPP := + (TypedConverter.ofProgram none ($bodyName $args*) ($boundSpecName $args*) $admitsK : $sigPP ⟶ $randK) • $randomnessName $args* $k)) else let some declared := σ.declared | return @@ -608,7 +611,7 @@ def elabPerPortDecls (converting : Bool) (name : Ident) $qIn (fun _ hne' hc' => ⟨hne', hc'⟩) $admitsK ys hne hl $within)) elabCommand (← `(noncomputable def $programName:ident $params:bracketedBinder* {$q : ($sigZero).I → ℕ} : $sigPP ⟶ $innerPP := - Interface.Converter.ofPreservingProgram none ($bodyName $args*) ($boundSpecName $args*) + TypedConverter.ofPreservingProgram none ($bodyName $args*) ($boundSpecName $args*) ($portMapName $args*) ($preservingName $args*) $q (fun _ hd => hd.2) $admitsPP)) if sites.isEmpty then elabCommand (← `(noncomputable def $perPortName:ident $params:bracketedBinder* @@ -617,7 +620,7 @@ def elabPerPortDecls (converting : Bool) (name : Ident) elabCommand (← `(noncomputable def $perPortName:ident $params:bracketedBinder* {$q : ($sigZero).I → ℕ} : $sigPP ⟶ $insidePP := CategoryTheory.CategoryStruct.comp ($programName $args* (budget := $q)) - (Interface.rightContext $insidePP ($randomnessName $args* $k)))) + (TypedConverter.rightContext $insidePP ($randomnessName $args* $k)))) if (← errorCount) > before then set saved catch _ => set saved @@ -631,9 +634,9 @@ def siteDecl (site : Site) (lawName : Ident) (args : Array (TSyntax `term)) : /-- The parallel composition of the sources of the sites at budget `k`. -/ def sourcesAt (lawNames : Array Ident) (args : Array (TSyntax `term)) (k : TSyntax `term) : CommandElabM (TSyntax `term) := do - let mut result ← `(Interface.Resource.source ($(lawNames.back!) $args*) $k) + let mut result ← `(TypedSystem.source ($(lawNames.back!) $args*) $k) for law in lawNames.pop.reverse do - result ← `(Interface.parallel (Interface.Resource.source ($law $args*) $k) $result) + result ← `(TypedSystem.parallel (TypedSystem.source ($law $args*) $k) $result) return result /-- The declarations of a component compiled to a program: its body, its inferred per-call @@ -685,13 +688,13 @@ def elabProgramDecls (converting : Bool) (name : Ident) (params : Array (TSyntax let sigB ← σ.at budget elabCommand (← `(noncomputable def $programName:ident $params:bracketedBinder* {$budget : ℕ} : $sigB ⟶ $innerK := - Interface.Converter.ofProgram none ($bodyName $args*) ($boundSpecName $args*) $admitsK)) + TypedConverter.ofProgram none ($bodyName $args*) ($boundSpecName $args*) $admitsK)) if !sites.isEmpty then -- A hygienic name, so the budget of the sources captures no parameter of the component. let q := Lean.mkIdent (← liftMacroM (Lean.Macro.addMacroScope `sourceBudget)) let (randQ, _, _) ← insideInterfaces sites used q elabCommand (← `(noncomputable def $randomnessName:ident $params:bracketedBinder* ($q : ℕ) : - Interface.Resource $randQ := $(← sourcesAt lawNames args q))) + TypedSystem $randQ := $(← sourcesAt lawNames args q))) if converting then let (declK, _, _) ← insideInterfaces insides used k if sites.isEmpty then @@ -701,10 +704,10 @@ def elabProgramDecls (converting : Bool) (name : Ident) (params : Array (TSyntax elabCommand (← `(noncomputable def $name:ident $params:bracketedBinder* {$budget : ℕ} : $sigB ⟶ $declK := CategoryTheory.CategoryStruct.comp ($programName $args* (budget := $budget)) - (Interface.rightContext $declK ($randomnessName $args* $k)))) + (TypedConverter.rightContext $declK ($randomnessName $args* $k)))) else elabCommand (← `(noncomputable def $name:ident $params:bracketedBinder* {$budget : ℕ} : - Interface.Resource $sigB := + TypedSystem $sigB := $programName $args* (budget := $budget) • $randomnessName $args* $k)) /-- The exact typing of a converter that samples nothing, when its number of inside calls is @@ -749,7 +752,7 @@ def elabExactDecls (name : Ident) (params : Array (TSyntax ``Term.bracketedBinde (fun h => (h.map fun x => $costName $args* x.1 x.2).sum ≤ $budget) (cost_prefix_closed _ _)) elabCommand (← `(noncomputable def $exactName:ident $params:bracketedBinder* {$budget $queries : ℕ} : $outside ⟶ $innerB := - Interface.Converter.ofCostedProgram none ($bodyName $args*) ($boundSpecName $args*) + TypedConverter.ofCostedProgram none ($bodyName $args*) ($boundSpecName $args*) (fun x => $costName $args* x.1 x.2) ($costsName $args*) (fun _ hd => hd.2) $admitsB)) if (← errorCount) > before then set saved catch _ => set saved @@ -892,15 +895,15 @@ def elabComponent : CommandElab := fun stx => do $stateTy → (i : ($sigZero).I) → ($sigZero).X i → $stateTy × ($sigZero).Y i := fun $state:ident i => match i with $alts:matchAlt*)) elabCommand (← `(noncomputable def $name:ident $params:bracketedBinder* {$budget : ℕ} : - Interface.Resource $sig := - Interface.Resource.ofAutomaton $sig ($stepName $args*) + TypedSystem $sig := + TypedSystem.ofAutomaton $sig ($stepName $args*) (Probability.Distribution.ProbDist.single ($initName $args*)))) let q := Lean.mkIdent `budget if let some sigPP ← σ.perPortAt q then let perPortName := Lean.mkIdent (name.getId ++ `perPort) elabCommand (← `(noncomputable def $perPortName:ident $params:bracketedBinder* - {$q : ($sigZero).I → ℕ} : Interface.Resource $sigPP := - Interface.Resource.ofAutomaton $sigPP ($stepName $args*) + {$q : ($sigZero).I → ℕ} : TypedSystem $sigPP := + TypedSystem.ofAutomaton $sigPP ($stepName $args*) (Probability.Distribution.ProbDist.single ($initName $args*)))) return let (innerZero, _, calls) ← componentInside converting insides sites used (← `(0)) @@ -943,7 +946,7 @@ others. -/ Interface.restrict ($sig q) (fun $bound:ident => $admits) $closed)) elabCommand (← `(noncomputable def $name:ident $params:bracketedBinder* {$budget : ℕ} : Interface.restrict ($sig $budget) (fun $bound:ident => $admits) $closed ⟶ ($sig $budget) := - Interface.filter ($sig $budget) (fun $bound:ident => $admits) $closed)) + TypedConverter.filter ($sig $budget) (fun $bound:ident => $admits) $closed)) /-- The outside interface family of a system expression at budget `k`: the outer family of its outermost component. -/ @@ -964,7 +967,7 @@ partial def outerOf (e : TSyntax `term) (k : TSyntax `term) : CommandElabM (Opti | `($f:ident) => return some (← `($(Lean.mkIdent (f.getId ++ `outer)) $k)) | _ => return none -/-- Whether a system expression denotes a converter rather than a resource. -/ +/-- Whether a system expression denotes a converter rather than a typed system. -/ partial def isConverterExpr (e : TSyntax `term) : Bool := match e with | `(($e)) => isConverterExpr e @@ -984,7 +987,7 @@ partial def isConverterExpr (e : TSyntax `term) : Bool := ($rhs : $outer ⟶ _))) else elabCommand (← `(noncomputable def $name:ident $params:bracketedBinder* {$budget : ℕ} : - Interface.Resource $outer := $rhs)) + TypedSystem $outer := $rhs)) let outerName := Lean.mkIdent (name.getId ++ `outer) let outerQ ← outerOf rhs (← `(q)) if let some o := outerQ then diff --git a/src/ConstructiveCryptography/DSL/GRAMMAR.md b/src/ConstructiveCryptography/DSL/GRAMMAR.md index 9c27075..01b86bb 100644 --- a/src/ConstructiveCryptography/DSL/GRAMMAR.md +++ b/src/ConstructiveCryptography/DSL/GRAMMAR.md @@ -100,7 +100,7 @@ determines every argument. With two or more ports these are instances, so the al port is finite by instance search; with one port the alphabet reduces to its declared type, whose own instances apply. -A system declares a resource for every budget: `S : Interface.Resource (I q)` with the implicit +A system declares a typed system for every budget: `S : TypedSystem (I q)` with the implicit argument `budget`. Its default domain consists of the histories of one to `q` inputs. An explicit `domain h ↦ P` is intersected with the budget and requires the nonempty-prefix condition, proved in `by`. This clause belongs to a system without an interface annotation. @@ -109,7 +109,7 @@ value. `interface I` also declares `I.perPort q := Interface.portBudget … q` for a budget `q : I.Port → ℕ` per port: at most `q i` queries at each port `i`. A system without an exact -domain also gets `S.perPort : Interface.Resource (I.perPort q)`. A converter with a single inside +domain also gets `S.perPort : TypedSystem (I.perPort q)`. A converter with a single inside port is typed by per-port budgets along a partial port map `C.portMap : I.Port → Option J.Port`, which sends each procedure to the inside label it calls, or to `none` when it calls none (`C.preserving`, a `Program.PortPreserving` proof: each procedure calls at most its own label, at @@ -156,7 +156,7 @@ not find one. A component compiles to a deterministic program with sources of randomness: sampling stays in the surface, and randomness enters the generated systems only through sources -(`Interface.Resource.source`, Maurer 2002, Definition 1). +(`TypedSystem.source`, Maurer 2002, Definition 1). - Every sampling statement `x ←$ P` becomes a call `x ← sample_k()` to a synthetic inside port whose source draws fresh samples from `P`; the law is `C.law_k`. @@ -168,21 +168,21 @@ the surface, and randomness enters the generated systems only through sources - Computation is ordinary `let` bindings; control flow is ordinary conditionals, pattern matching and list folds (`forEach`); a call is `callProg`, a reply `returnProg`. - `C.program : I q ⟶ J (C.bound * q)` is the converter of the program - (`Interface.Converter.ofProgram`), on the outside domain of `I q`. -- A converter is `C.program ≫ Interface.rightContext J (C.randomness k)`: its program with its - sources attached beside the declared inside ports, each source at the inside budget `k`. A + (`TypedConverter.ofProgram`), on the outside domain of `I q`. +- A converter is `C.program ≫ TypedConverter.rightContext J (C.randomness k)`: its program with + its sources attached beside the declared inside ports, each source at the inside budget `k`. A converter that samples nothing is `C.program`. - A system is `C.program • C.randomness k`. A system that samples nothing is the automaton of - its program started in `C.initial`, `Interface.Resource.ofAutomaton I step (single s)`. + its program started in `C.initial`, `TypedSystem.ofAutomaton I step (single s)`. -Attaching a program to a resource runs its body against the resource +Attaching a program to a typed system runs its body against the system (`Program.apply_ofProgram`, Maurer 2002, §3.3). A transcript of `C.program • R` has the mass of -the resource's deterministic systems on which the inlined program gives it -(`Interface.ofDDC_ofProgramOn_smul_ofPDS`). Sources are automata whose initial state is a table -of samples (`Interface.Resource.ofAutomaton I step initial`, Maurer 2002, Definition 2, with the +the system's deterministic systems on which the inlined program gives it +(`TypedConverter.ofDDC_ofProgramOn_smul_ofPDS`). Sources are automata whose initial state is a +table of samples (`TypedSystem.ofAutomaton I step initial`, Maurer 2002, Definition 2, with the randomness in the initial state); parallel automata are the automaton of both -(`Interface.parallel_ofAutomaton`), and a program attached to an automaton is the combined -automaton (`Interface.Converter.ofProgram_smul_ofAutomaton`, `Program.combine`). Every compiled +(`TypedSystem.parallel_ofAutomaton`), and a program attached to an automaton is the combined +automaton (`TypedConverter.ofProgram_smul_ofAutomaton`, `Program.combine`). Every compiled component is therefore an automaton with a sampled initial state; bisimilar automata have the same system (`automatonSystem_eq_of_bisim`). @@ -234,7 +234,7 @@ obligation. This example specifies the composition, without claiming a security reduction or a standardized AEAD mode. `Examples/DSL/AEADTests.lean` proves the generated encrypt/verify/reject interaction paths of -the program's converter (`Interface.ofDDC_apply`), checks the encoding bounds, and checks the +the program's converter (`TypedConverter.ofDDC_apply`), checks the encoding bounds, and checks the combination as functions (`CTR.crypt` and `PMAC.pmac`): decryption inverts encryption, and modified inputs are rejected. The published CTR and PMAC vectors are checked in `Commons/Tests`, on the functions; they are separate from a proof that the converters diff --git a/src/ConstructiveCryptography/InterfaceAlgebra.lean b/src/ConstructiveCryptography/InterfaceAlgebra.lean index 481777e..487d7c3 100644 --- a/src/ConstructiveCryptography/InterfaceAlgebra.lean +++ b/src/ConstructiveCryptography/InterfaceAlgebra.lean @@ -1,5 +1,5 @@ -import ConstructiveCryptography.ResourceParallelAttachment -import ConstructiveCryptography.ResourceCoherence +import RandomSystems.Typed.ParallelAttachment +import RandomSystems.Typed.SystemCoherence import ConstructiveCryptography.InterfaceMonoidal import ConstructiveCryptography.CryptographicAlgebra.Distinguisher import RandomSystems.Distance.Distinguisher @@ -8,29 +8,32 @@ import ConstructiveCryptography.Substitution.Reduction /-! # Interfaces as a cryptographic algebra -Interfaces are an instance of `ResourceTheory`: the resources on `A` are `Interface.Resource A`, -and attachment is `Interface.attach`, the attachment of PDC behaviors; its axioms are -`Interface.identity_attach` and `Interface.comp_smul`. They are an instance of -`CryptographicAlgebra`: the lax monoidal structure of the resource functor is parallel -composition of resources with the dummy resource. They are an instance of -`CompatibleDistinguisherClass`: -the distinguishers on `A` are the behaviors of the probabilistic distinguishers compatible with -`A`'s domain (`Domain.DistinguisherBehavior`), their probabilities of outputting `1` on -resources. The class is closed under absorbing a converter -(`Domain.DistinguisherBehavior.absorb`) and under running a fixed resource beside -(`Domain.Distinguisher.exists_absorbRight`), so Maurer's Lemma 1 +Interfaces are an instance of `ResourceTheory`: its carrier `Φ A` is `TypedSystem A`, its field +`attach` is `TypedConverter.attach`, the attachment of PDC behaviors, and its axioms +`attach_identity` and `attach_serial` are discharged by `TypedConverter.identity_attach` and +`TypedConverter.comp_smul`. They are an instance of `CryptographicAlgebra`: the lax monoidal +structure of the functor of typed systems has the product `TypedSystem.parallel` and the unit +`TypedSystem.dummy`; naturality is discharged by `TypedConverter.parallel_attach`, and +associativity and unitality by `parallel_assoc`, `parallel_dummy_left` and `parallel_dummy_right`, +which read `TypedConverter.rename_mass` with `TypedSystem.parallel_assoc_mass`, +`TypedSystem.parallel_unit_left_mass` and `TypedSystem.parallel_unit_right_mass` through the +regrouping isomorphisms. They are an instance of `CompatibleDistinguisherClass`: the +distinguishers on `A` are the behaviors of the probabilistic distinguishers compatible with `A`'s +domain (`Domain.DistinguisherBehavior`), their probabilities of outputting `1` on typed systems. +The axiom `closed_attach` is discharged by `Domain.DistinguisherBehavior.absorb`, and +`closed_parallel_left` and `closed_parallel_right` by `Domain.Distinguisher.exists_absorbRight` +and the swap (`TypedSystem.parallel_swap_mass`), so Maurer's Lemma 1 (`CompatibleDistinguisherClass.ofClosure`) makes its advantage distance a compatible -pseudo-metric. This distance of two resources is the transcript distance of their random systems -(`RandomSystem.transcriptDistance_eq_iSup_behavior`). For every class of admitted distinguishers -they carry a `DistinguisherAdvantage`: its field `advantage` is +pseudo-metric. This distance of two typed systems is the transcript distance of their random +systems (`RandomSystem.transcriptDistance_eq_iSup_behavior`). For every class of admitted +distinguishers they carry a `DistinguisherAdvantage`: its field `advantage` is `Domain.DistinguisherBehavior.advantage`, and its laws are `advantage_self`, `advantage_symm` and `advantage_triangle` of the random systems. In a security proof a converter absorbed into a -distinguisher is the reduction (CR18); absorbing a serial composition absorbs its converters in -turn. +distinguisher (`Domain.DistinguisherBehavior.absorb`) is the reduction (CR18). ## Main definitions -* `Interface.resourcesLaxMonoidal`: parallel composition and the dummy resource +* `Interface.resourcesLaxMonoidal`: parallel composition and the dummy system * `Interface.distinguishers A`: the behaviors of the probabilistic distinguishers compatible with `A`'s domain * `Interface.resourceTheory`, `Interface.cryptographicAlgebra`, @@ -38,13 +41,14 @@ turn. * `Interface.distinguisherAdvantage admissible`: the distinguishing advantage of the substitution calculus, with its field `advantage` the systems-level `Domain.DistinguisherBehavior.advantage` -* `Interface.absorb α D`: the distinguisher `D` with the converter `α` absorbed, the systems-level - `Domain.DistinguisherBehavior.absorb` * `Interface.AdmissibleDistinguishers`: the class of the admitted distinguishers, closed under absorbing converters ## Main results +* `Interface.parallel_assoc`, `Interface.parallel_dummy_left`, `Interface.parallel_dummy_right`: + the lax monoidal laws through the regrouping isomorphisms +* `Interface.parallel_swap`: parallel composition is commutative through the swap * `Interface.distinguishers_attach`, `Interface.distinguishers_parallel_left`, `Interface.distinguishers_parallel_right`: closure * `Interface.cc_parallel_eq`, `Interface.cc_dummy_eq`: the abstract operations are the @@ -56,33 +60,72 @@ turn. transports through a converter; `Interface.AdmissibleDistinguishers.substitutesWithin_attach` for the admitted distinguishers, and `Interface.AdmissibleDistinguishers.substitutesWithin_context` in a composite context -* `Interface.absorb_comp`: absorbing a serial composition absorbs its converters in turn -/ namespace SystemAlgebra.Interface open CategoryTheory CategoryTheory.MonoidalCategory -/-- Interfaces carry a resource theory: the resources on `A` are `Resource A`, and +/-- Interfaces are an instance of `ResourceTheory`: its carrier on `A` is `TypedSystem A`, and attachment is the attachment of PDC behaviors. -/ noncomputable instance resourceTheory : - ConstructiveCryptography.ResourceTheory Interface Resource where - attach := attach - attach_identity := identity_attach - attach_serial := comp_smul + ConstructiveCryptography.ResourceTheory Interface TypedSystem where + attach := TypedConverter.attach + attach_identity := TypedConverter.identity_attach + attach_serial := TypedConverter.comp_smul + +lemma parallel_assoc {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) + (T : TypedSystem C) : + ((associator A B C).inv • TypedSystem.parallel (TypedSystem.parallel R S) T : + TypedSystem (tensor A (tensor B C))) = + TypedSystem.parallel R (TypedSystem.parallel S T) := by + apply Subtype.ext + apply RandomSystem.ext + intro h + simp only [associator, isoOf] + rw [TypedConverter.rename_mass, TypedSystem.parallel_assoc_mass] + 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] + +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] + +lemma parallel_swap {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) : + ((swap A B).hom • TypedSystem.parallel S R : TypedSystem (tensor A B)) = + TypedSystem.parallel R S := by + apply Subtype.ext + apply RandomSystem.ext + intro h + simp only [swap, isoOf] + rw [TypedConverter.rename_mass, TypedSystem.parallel_swap_mass] noncomputable instance resourcesLaxMonoidal : - (ConstructiveCryptography.ResourceTheory.functor Interface Resource).LaxMonoidal where - ε := TypeCat.ofHom fun _ => dummy - μ A B := TypeCat.ofHom fun (p : Resource A.unop × Resource B.unop) => parallel p.1 p.2 + (ConstructiveCryptography.ResourceTheory.functor Interface TypedSystem).LaxMonoidal where + ε := TypeCat.ofHom fun _ => TypedSystem.dummy + μ A B := TypeCat.ofHom fun (p : TypedSystem A.unop × TypedSystem B.unop) => + TypedSystem.parallel p.1 p.2 μ_natural_left f A' := by ext p - have h := (parallel_attach f.unop (𝟙 A'.unop) p.1 p.2).symm + have h := (TypedConverter.parallel_attach f.unop (𝟙 A'.unop) p.1 p.2).symm rw [identity_attach (A := A'.unop) p.2] at h exact h μ_natural_right A' f := by ext p - have h := (parallel_attach (𝟙 A'.unop) f.unop p.1 p.2).symm + have h := (TypedConverter.parallel_attach (𝟙 A'.unop) f.unop p.1 p.2).symm rw [identity_attach (A := A'.unop) p.1] at h exact h associativity A B C := by @@ -95,75 +138,62 @@ noncomputable instance resourcesLaxMonoidal : ext p exact (parallel_dummy_right p.1).symm -/-- Interfaces, converters and resources are a cryptographic algebra. -/ +/-- Interfaces, typed converters and typed systems are a cryptographic algebra. -/ noncomputable instance cryptographicAlgebra : - ConstructiveCryptography.CryptographicAlgebra Interface Resource where + ConstructiveCryptography.CryptographicAlgebra Interface TypedSystem where laxMonoidal := resourcesLaxMonoidal /-- The distinguishers on `A`: the behaviors of the probabilistic distinguishers compatible with `A`'s domain, their probabilities of outputting `1`. -/ -def distinguishers (A : Interface) : Set (Resource A → ℝ) := - Set.range fun (d : A.inputDomain.DistinguisherBehavior) (R : Resource A) => d.1 R - -/-- **A distinguisher with a converter absorbed**: the distinguisher `D ∘ α` on `B`, deciding as -`D` does with `α : A ⟶ B` attached, the systems-level `Domain.DistinguisherBehavior.absorb`. In a -security proof `α` is the reduction. -/ -noncomputable def absorb {A B : Interface} (α : A ⟶ B) (D : A.inputDomain.DistinguisherBehavior) : - B.inputDomain.DistinguisherBehavior := - D.absorb B.nonempty_prefix A.nonempty_prefix α - -/-- **Absorbing a serial composition** absorbs its converters in turn: -`D ∘ (α ≫ β) = (D ∘ α) ∘ β`. -/ -lemma absorb_comp {A B C : Interface} (α : A ⟶ B) (β : B ⟶ C) - (D : A.inputDomain.DistinguisherBehavior) : absorb (α ≫ β) D = absorb β (absorb α D) := - D.absorb_comp C.nonempty_prefix A.nonempty_prefix B.nonempty_prefix α β +def distinguishers (A : Interface) : Set (TypedSystem A → ℝ) := + Set.range fun (d : A.inputDomain.DistinguisherBehavior) (R : TypedSystem A) => d.1 R /-- Absorbing a converter into a distinguisher gives a distinguisher. -/ -lemma distinguishers_attach {A B : Interface} (α : A ⟶ B) {d : Resource A → ℝ} - (hd : d ∈ distinguishers A) : (fun R : Resource B => d (α • R)) ∈ distinguishers B := by +lemma distinguishers_attach {A B : Interface} (α : A ⟶ B) {d : TypedSystem A → ℝ} + (hd : d ∈ distinguishers A) : (fun R : TypedSystem B => d (α • R)) ∈ distinguishers B := by obtain ⟨D, rfl⟩ := hd - exact ⟨absorb α D, rfl⟩ + exact ⟨D.absorb B.nonempty_prefix A.nonempty_prefix α, rfl⟩ -/-- Running a fixed resource beside the distinguished one gives a distinguisher. -/ -lemma distinguishers_parallel_left {A B : Interface} (T : Resource B) - {d : Resource (tensor A B) → ℝ} (hd : d ∈ distinguishers (tensor A B)) : - (fun R : Resource A => d (parallel R T)) ∈ distinguishers A := by +/-- Running a fixed typed system beside the distinguished one gives a distinguisher. -/ +lemma distinguishers_parallel_left {A B : Interface} (T : TypedSystem B) + {d : TypedSystem (tensor A B) → ℝ} (hd : d ∈ distinguishers (tensor A B)) : + (fun R : TypedSystem A => d (TypedSystem.parallel R T)) ∈ distinguishers A := by obtain ⟨D, rfl⟩ := hd obtain ⟨P, hP⟩ := D.2 obtain ⟨U, rfl⟩ := T.exists_ofPDS obtain ⟨Q, hQ⟩ := Domain.Distinguisher.exists_absorbRight (X₁ := A.X) (Y₁ := A.Y) (X₂ := B.X) (Y₂ := B.Y) (hE := A.length_le) (hF := B.length_le) A.nonempty_prefix B.nonempty_prefix P U - refine ⟨⟨fun R => D.1 (parallel R (Resource.ofPDS U)), Q, fun R => ?_⟩, rfl⟩ - obtain ⟨Pr, rfl⟩ := Resource.exists_ofPDS R - refine (hP (parallel (Resource.ofPDS Pr) (Resource.ofPDS U))).trans ?_ - rw [parallel_ofPDS] + refine ⟨⟨fun R => D.1 (TypedSystem.parallel R (TypedSystem.ofPDS U)), Q, fun R => ?_⟩, rfl⟩ + obtain ⟨Pr, rfl⟩ := TypedSystem.exists_ofPDS R + refine (hP (TypedSystem.parallel (TypedSystem.ofPDS Pr) (TypedSystem.ofPDS U))).trans ?_ + rw [TypedSystem.parallel_ofPDS] exact (hQ Pr _ _ (fun _ => rfl) (fun _ => rfl)).symm -lemma distinguishers_parallel_right {A B : Interface} (T : Resource A) - {d : Resource (tensor A B) → ℝ} (hd : d ∈ distinguishers (tensor A B)) : - (fun S : Resource B => d (parallel T S)) ∈ distinguishers B := by +lemma distinguishers_parallel_right {A B : Interface} (T : TypedSystem A) + {d : TypedSystem (tensor A B) → ℝ} (hd : d ∈ distinguishers (tensor A B)) : + (fun S : TypedSystem B => d (TypedSystem.parallel T S)) ∈ distinguishers B := by have h := distinguishers_parallel_left T (distinguishers_attach (swap A B).hom hd) simpa only [parallel_swap] using h /-- The distinguishers are a compatible distinguisher class; by Maurer's Lemma 1 their advantage distance is a compatible pseudo-metric. -/ noncomputable instance compatibleDistinguisherClass : - ConstructiveCryptography.CompatibleDistinguisherClass Interface Resource := + ConstructiveCryptography.CompatibleDistinguisherClass Interface TypedSystem := ConstructiveCryptography.CompatibleDistinguisherClass.ofClosure distinguishers (fun α _ hd => distinguishers_attach α hd) (fun T _ hd => distinguishers_parallel_left T hd) (fun T _ hd => distinguishers_parallel_right T hd) -lemma cc_parallel_eq {A B : Interface} (R : Resource A) (S : Resource B) : +lemma cc_parallel_eq {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) : ConstructiveCryptography.CryptographicAlgebra.parallel R S = - parallel R S := rfl + TypedSystem.parallel R S := rfl lemma cc_dummy_eq : - ConstructiveCryptography.CryptographicAlgebra.dummy = dummy := rfl + ConstructiveCryptography.CryptographicAlgebra.dummy = TypedSystem.dummy := rfl -/-- The distance of two resources is the transcript distance of their random systems. -/ -lemma cc_distance_eq {A : Interface} (R S : Resource A) : +/-- The distance of two typed systems is the transcript distance of their random systems. -/ +lemma cc_distance_eq {A : Interface} (R S : TypedSystem A) : ConstructiveCryptography.CryptographicAlgebra.distance R S = R.1.transcriptDistance S.1 := by rw [RandomSystem.transcriptDistance_eq_iSup_behavior R S] @@ -173,11 +203,11 @@ lemma cc_distance_eq {A : Interface} (R S : Resource A) : /-- Interfaces carry a distinguishing advantage for every class `admissible` of admitted distinguishers: the distinguishers on `A` are the behaviors of the probabilistic distinguishers -compatible with `A`'s domain, and the advantage between two resources is their advantage between -the random systems. -/ +compatible with `A`'s domain, and the advantage between two typed systems is their advantage +between the random systems. -/ noncomputable def distinguisherAdvantage (admissible : ∀ A : Interface, Set A.inputDomain.DistinguisherBehavior) : - ConstructiveCryptography.CryptographicAlgebra.DistinguisherAdvantage Interface Resource + ConstructiveCryptography.CryptographicAlgebra.DistinguisherAdvantage Interface TypedSystem fun A => A.inputDomain.DistinguisherBehavior where admissible := admissible advantage _ D R S := D.advantage R S @@ -189,9 +219,10 @@ noncomputable def distinguisherAdvantage distinguisher with the converter absorbed. -/ lemma distinguisherAdvantage_attach (admissible : ∀ A : Interface, Set A.inputDomain.DistinguisherBehavior) {A B : Interface} - (α : A ⟶ B) (D : A.inputDomain.DistinguisherBehavior) (R S : Resource B) : + (α : A ⟶ B) (D : A.inputDomain.DistinguisherBehavior) (R S : TypedSystem B) : (distinguisherAdvantage admissible).advantage A D (α • R) (α • S) = - (distinguisherAdvantage admissible).advantage B (absorb α D) R S := + (distinguisherAdvantage admissible).advantage B + (D.absorb B.nonempty_prefix A.nonempty_prefix α) R S := rfl /-- **A concrete substitution through a converter**: its loss is the loss at the distinguisher @@ -200,13 +231,14 @@ admitted distinguishers are closed under absorbing converters. -/ lemma substitutesWithin_attach (admissible : ∀ A : Interface, Set A.inputDomain.DistinguisherBehavior) (closed : ∀ {A B : Interface} (α : A ⟶ B) (D : A.inputDomain.DistinguisherBehavior), - D ∈ admissible A → absorb α D ∈ admissible B) + D ∈ admissible A → D.absorb B.nonempty_prefix A.nonempty_prefix α ∈ admissible B) {A B : Interface} (α : A ⟶ B) {error : B.inputDomain.DistinguisherBehavior → ENNReal} - {R S : Resource B} (h : (distinguisherAdvantage admissible).SubstitutesWithin error R S) : - (distinguisherAdvantage admissible).SubstitutesWithin (fun D => error (absorb α D)) - (α • R) (α • S) := + {R S : TypedSystem B} (h : (distinguisherAdvantage admissible).SubstitutesWithin error R S) : + (distinguisherAdvantage admissible).SubstitutesWithin + (fun D => error (D.absorb B.nonempty_prefix A.nonempty_prefix α)) (α • R) (α • S) := ConstructiveCryptography.CryptographicAlgebra.DistinguisherAdvantage.SubstitutesWithin.attach _ α - (absorb α) (fun D hD => closed α D hD) (distinguisherAdvantage_attach admissible α) h + (fun D => D.absorb B.nonempty_prefix A.nonempty_prefix α) (fun D hD => closed α D hD) + (distinguisherAdvantage_attach admissible α) h /-- **The admitted distinguishers**: a class of distinguishers at every interface, closed under absorbing converters. Security statements are substitutions for their distinguishing @@ -216,16 +248,16 @@ class AdmissibleDistinguishers where admissible : ∀ A : Interface, Set A.inputDomain.DistinguisherBehavior /-- An admitted distinguisher with a converter absorbed is admitted. -/ closed : ∀ {A B : Interface} (α : A ⟶ B) (D : A.inputDomain.DistinguisherBehavior), - D ∈ admissible A → absorb α D ∈ admissible B + D ∈ admissible A → D.absorb B.nonempty_prefix A.nonempty_prefix α ∈ admissible B /-- **A substitution through a converter**, for the admitted distinguishers: its loss is the loss at the distinguisher with the converter absorbed. -/ lemma AdmissibleDistinguishers.substitutesWithin_attach [AdmissibleDistinguishers] {A B : Interface} (α : A ⟶ B) {error : B.inputDomain.DistinguisherBehavior → ENNReal} - {R S : Resource B} + {R S : TypedSystem B} (h : (distinguisherAdvantage AdmissibleDistinguishers.admissible).SubstitutesWithin error R S) : (distinguisherAdvantage AdmissibleDistinguishers.admissible).SubstitutesWithin - (fun D => error (absorb α D)) (α • R) (α • S) := + (fun D => error (D.absorb B.nonempty_prefix A.nonempty_prefix α)) (α • R) (α • S) := Interface.substitutesWithin_attach _ AdmissibleDistinguishers.closed α h /-- **A substitution in a context** (Banfi 2023, §2.3.3, printed p. 16: `ε(D ∘ ρ)`): substituting @@ -234,20 +266,20 @@ context may be a serial composition; its attachments `X` and `Y` are written con converter. -/ lemma AdmissibleDistinguishers.substitutesWithin_context [AdmissibleDistinguishers] {A B : Interface} (ρ : A ⟶ B) {error : B.inputDomain.DistinguisherBehavior → ENNReal} - {R S : Resource B} + {R S : TypedSystem B} (h : (distinguisherAdvantage AdmissibleDistinguishers.admissible).SubstitutesWithin error R S) - {X Y : Resource A} + {X Y : TypedSystem A} (hX : ρ • R = X := by first | rfl | (simp only [SystemAlgebra.Interface.comp_smul] <;> rfl)) (hY : ρ • S = Y := by first | rfl | (simp only [SystemAlgebra.Interface.comp_smul] <;> rfl)) : (distinguisherAdvantage AdmissibleDistinguishers.admissible).SubstitutesWithin - (error ∘ absorb ρ) X Y := by + (fun D => error (D.absorb B.nonempty_prefix A.nonempty_prefix ρ)) X Y := by subst hX hY exact AdmissibleDistinguishers.substitutesWithin_attach ρ h /-- The advantage of a distinguisher is at most the distance. -/ lemma distinguisherAdvantage_le_distance (admissible : ∀ A : Interface, Set A.inputDomain.DistinguisherBehavior) {A : Interface} - (D : A.inputDomain.DistinguisherBehavior) (R S : Resource A) : + (D : A.inputDomain.DistinguisherBehavior) (R S : TypedSystem A) : (distinguisherAdvantage admissible).advantage A D R S ≤ ConstructiveCryptography.CryptographicAlgebra.distance R S := by rw [cc_distance_eq] diff --git a/src/ConstructiveCryptography/InterfaceCategory.lean b/src/ConstructiveCryptography/InterfaceCategory.lean new file mode 100644 index 0000000..079ea23 --- /dev/null +++ b/src/ConstructiveCryptography/InterfaceCategory.lean @@ -0,0 +1,57 @@ +import RandomSystems.Typed.Interface +import Mathlib.CategoryTheory.Types.Basic + +/-! +# The category of interfaces + +Interfaces are an instance of `Category`: its field `Hom` is `TypedConverter`, `id` is +`TypedConverter.id` and `comp` is `TypedConverter.comp`, the identity and the serial composition +of PDC behaviors; the axioms `id_comp`, `comp_id` and `assoc` are discharged by +`PDCBehavior.id_comp`, `PDCBehavior.comp_id` and `PDCBehavior.comp_assoc`. An arrow acts on +typed systems by `TypedConverter.attach`; attachment is a contravariant functor to types. + +## Main definitions + +* `Interface.category`: the category of interfaces and typed converters + +## Main results + +* `Interface.identity_attach`: attaching the identity arrow leaves a typed system unchanged, + `TypedConverter.identity_attach` +* `Interface.comp_smul`: attaching a serial composition attaches the inner arrow first, + `TypedConverter.comp_smul` +-/ + +namespace SystemAlgebra.Interface + +open CategoryTheory + +/-- Interfaces and typed converters form a category under serial composition. -/ +noncomputable instance category : Category Interface where + Hom := TypedConverter + id := TypedConverter.id + comp α β := TypedConverter.comp α β + id_comp {A _} α := PDCBehavior.id_comp α A.nonempty_prefix + comp_id {_ B} α := PDCBehavior.comp_id α B.nonempty_prefix + assoc α β γ := PDCBehavior.comp_assoc α β γ + +/-- The action of an arrow on a typed system is attachment. As a default instance, an arrow +whose domains are still to be inferred takes them from the typed system it acts on. -/ +@[default_instance high] +noncomputable instance {A B : Interface} : HSMul (A ⟶ B) (TypedSystem B) (TypedSystem A) := + ⟨TypedConverter.attach⟩ + +/-- **Attaching the identity** leaves a typed system unchanged. -/ +lemma identity_attach {A : Interface} (R : TypedSystem A) : (𝟙 A • R : TypedSystem A) = R := + TypedConverter.identity_attach R + +/-- **Serial attachment** (MR16 §3.3, printed p. 7: “(β ∘ α)ⁱR = βⁱ(αⁱR)”): attaching a +serial composition attaches the inner converter first. -/ +theorem comp_smul {A B C : Interface} (α : A ⟶ B) (β : B ⟶ C) (R : TypedSystem C) : + (α ≫ β) • R = α • (β • R) := + TypedConverter.comp_smul α β R + +lemma comp_eq {A B C : Interface} (α : A ⟶ B) (β : B ⟶ C) : + α ≫ β = PDCBehavior.comp α β := rfl + +end SystemAlgebra.Interface diff --git a/src/ConstructiveCryptography/InterfaceGame.lean b/src/ConstructiveCryptography/InterfaceGame.lean index 997de07..b5a6191 100644 --- a/src/ConstructiveCryptography/InterfaceGame.lean +++ b/src/ConstructiveCryptography/InterfaceGame.lean @@ -1,130 +1,104 @@ -import ConstructiveCryptography.InterfaceAlgebra -import ConstructiveCryptography.CryptographicAlgebra.Game -import RandomSystems.Game.MBOAttachment +import ConstructiveCryptography.Notation +import RandomSystems.Typed.Game +import RandomSystems.Typed.PresentedGame /-! # Games on interfaces Interfaces are an instance of `Games`, the abstraction of CR18, §4.4.3, §4.5.1 and §4.7.2, and of `DistinctionGames`, the abstraction of CR18, §§4.10–4.11; the instance is where these -abstractions meet random systems. Its games are MBO random systems, as CR18 instantiates games -(§3.7.1): a game on `A` is a resource on the interface of `A` with the MBO whose MBO, once set, -stays set (`RandomSystem.MonotoneMBO`). Winners and solvers are probabilistic distinguishers, +abstractions meet random systems. Its field `Game A` is the typed games `TypedGame A`, MBO random +systems as CR18 instantiates games (§3.7.1). Winners and solvers are probabilistic distinguishers, through their behaviors `Domain.SolverBehavior`: a winner does not see the MBO (`DDE.blindMBO`). -For `Games`, the field `attachGame` is the attachment of the MBO-forwarding lift -`PDCBehavior.liftMBO`, and `winners` are the winning probabilities of the solver behaviors. +For `Games`, the field `attachGame` is `TypedConverter.attachGame`, the attachment of the +MBO-forwarding lift `PDCBehavior.liftMBO`, and `winners` are the winning probabilities of the +solver behaviors. The axiom `attachGame_identity` is discharged by `PDCBehavior.liftMBO_id` and `PDCBehavior.attach_id`, `attachGame_serial` by `PDCBehavior.liftMBO_comp` and `PDCBehavior.attach_comp`, and `closed_attach` by `Domain.SolverBehavior.absorb`. -For `DistinctionGames`, the field `solvers` is the pairs of the solver behaviors, `visible` is the -visible system `RandomSystem.visible`, and `ConditionallyEquivalent` is +For `DistinctionGames`, the field `solvers` is the pairs of the solver behaviors, `visible` is +`TypedGame.visible`, the visible system `RandomSystem.visible`, and `ConditionallyEquivalent` is `RandomSystem.ConditionallyEquivalent`. The axiom `solvers_winner` holds by the definition of the winners, `solvers_closed_attach` is discharged by `Domain.SolverBehavior.absorb`, `visible_attachGame` by `RandomSystem.visible_attach_liftMBO`, and `advantage_le_win` by `Domain.Distinguisher.advantage_le_winProbability`. -Conditional equivalence then bounds the distance of the visible resource of a game by the +Conditional equivalence then bounds the distance of the visible system of a game by the probability that its MBO is set on fixed queries (CR18, Theorem 4.17), through -`RandomSystem.transcriptDistance_visible_le_of_unsetProbability`. +`RandomSystem.transcriptDistance_visible_le_of_unsetProbability`. For a game presented by a +discrete game (`TypedGame.ofPDG`), the bound on the condition bounds the distance from the +presented typed system. ## Main definitions -* `Interface.withMBO A`: the interface of `A` with the MBO -* `Interface.Game A`: games on `A` +* `Interface.winners A`, `Interface.solvers A`: the winners and solvers on `A` * `Interface.games`, `Interface.distinctionGames`: the instances ## Main results * `Interface.win_le`: a bound on winning by every distinguisher bounds winning by every winner * `Interface.dist_visible_le`: conditional equivalence bounds the distance of the visible - resource + typed system +* `Interface.conditionallyEquivalent_ofPDG_iff`: the conditional equivalence of a presented game + is that of the game on random systems +* `Interface.game_dist_le`, `Interface.game_dist_ofSingleFunction_le`: the distance bound for a + presented game and for a single-label sampled-function game -/ namespace SystemAlgebra.Interface -open CategoryTheory ConstructiveCryptography -open scoped NNReal - -/-- The interface of `A` with the MBO: its replies carry the MBO. -/ -abbrev withMBO (A : Interface) : Interface where - I := A.I - X := A.X - Y := SystemAlgebra.withMBO A.Y - domain := A.domain - nonempty_prefix := A.nonempty_prefix - bound := A.bound - length_le := A.length_le - -/-- **Games** on `A`: resources on the interface of `A` with the MBO whose MBO, once set, -stays set. -/ -def Game (A : Interface) := {G : Resource A.withMBO // G.1.MonotoneMBO} - -/-- The MBO-forwarding lift of a converter, between the interfaces with the MBO. -/ -noncomputable def liftMBO {A B : Interface} (α : A ⟶ B) : A.withMBO ⟶ B.withMBO := - PDCBehavior.liftMBO α - -/-- A converter attached to a game: its lift attached to the game's resource. -/ -noncomputable def attachGame {A B : Interface} (α : A ⟶ B) (G : Game B) : Game A := - -- The lift runs `α` on the replies of `G` without their MBO and tags each outside reply - -- with the MBO `a` of the latest reply of `G`: - -- - -- ──x────▶ ┌───────────┐ ──u────▶ ┌───┐ - -- │ liftMBO α │ │ G │ - -- ◀─(y,a)─ └───────────┘ ◀─(v,a)─ └───┘ - -- - -- The result is again a game, its MBO once set stays set - -- (`RandomSystem.MonotoneMBO.attach_liftMBO`). - ⟨liftMBO α • G.1, - G.2.attach_liftMBO B.nonempty_prefix A.nonempty_prefix α G.1.2⟩ - -/-- The visible resource of a game. -/ -noncomputable def Game.visible {A : Interface} (G : Game A) : Resource A := - ⟨G.1.1.visible, G.1.2.visible⟩ +open CategoryTheory ConstructiveCryptography Probability +open scoped SystemAlgebra NNReal /-- The winners on `A`: the winning probabilities of the solver behaviors on the input domain of `A`. -/ -def winners (A : Interface) : Set (Game A → ℝ) := +def winners (A : Interface) : Set (TypedGame A → ℝ) := Set.range fun s : Domain.SolverBehavior (Y := A.Y) A.domain A.bound A.length_le => fun G => s.1.2 ⟨G.1.1, G.1.2, G.2⟩ /-- The solvers on `A`: the solver behaviors on the input domain of `A`. -/ -def solvers (A : Interface) : Set ((Resource A → ℝ) × (Game A → ℝ)) := +def solvers (A : Interface) : Set ((TypedSystem A → ℝ) × (TypedGame A → ℝ)) := Set.range fun s : Domain.SolverBehavior (Y := A.Y) A.domain A.bound A.length_le => (fun R => s.1.1 R, fun G => s.1.2 ⟨G.1.1, G.1.2, G.2⟩) /-- **Interfaces are an instance of `Games`**: attachment is the attachment of the lift, and the winners are the winning probabilities of the solver behaviors. -/ -noncomputable instance games : Games Interface Game where +noncomputable instance games : Games Interface TypedGame where -- Field `attachGame`: the systems-level attachment `PDCBehavior.attach` of the lift -- `PDCBehavior.liftMBO α` to the game's random system. - attachGame := attachGame + attachGame := TypedConverter.attachGame -- Axiom `attachGame_identity`, discharged by the systems-level theorems -- `PDCBehavior.liftMBO_id` (the lift of the identity PDC is the identity PDC) and -- `PDCBehavior.attach_id` (attaching the identity PDC leaves a random system unchanged, - -- used here as `identity_attach`). - attachGame_identity G := by - -- Two games are equal when their resources are. + -- used here as `TypedConverter.identity_attach`). + attachGame_identity {A} G := by + -- Two games are equal when their typed systems are. apply Subtype.ext - change liftMBO (𝟙 _) • G.1 = G.1 + change TypedConverter.attach (PDCBehavior.liftMBO (𝟙 A)) G.1 = G.1 -- The lift of the identity converter is the identity converter on `A.withMBO`. - rw [show liftMBO (𝟙 _) = 𝟙 _ from PDCBehavior.liftMBO_id _] - -- Attaching the identity converter leaves the game's resource unchanged. - exact identity_attach G.1 + rw [show PDCBehavior.liftMBO (𝟙 A) = TypedConverter.id A.withMBO from + PDCBehavior.liftMBO_id _] + -- Attaching the identity converter leaves the game's typed system unchanged. + exact TypedConverter.identity_attach G.1 -- Axiom `attachGame_serial`, discharged by the systems-level theorems -- `PDCBehavior.liftMBO_comp` (the lift of `α ≫ β` is the composition of the lifts) and -- `PDCBehavior.attach_comp` (attaching a serial composition is nested attachment, used - -- here as `comp_smul`). - attachGame_serial α β G := by - -- Two games are equal when their resources are. + -- here as `TypedConverter.comp_smul`). + attachGame_serial {A B C} α β G := by + -- Two games are equal when their typed systems are. apply Subtype.ext - change liftMBO (α ≫ β) • G.1 = liftMBO α • (liftMBO β • G.1) + change TypedConverter.attach (PDCBehavior.liftMBO (α ≫ β)) G.1 = + TypedConverter.attach (A := A.withMBO) (PDCBehavior.liftMBO α) + (TypedConverter.attach (A := B.withMBO) (PDCBehavior.liftMBO β) G.1) -- The lift is functorial: lift (α ≫ β) = lift α ≫ lift β. - rw [show liftMBO (α ≫ β) = liftMBO α ≫ liftMBO β from PDCBehavior.liftMBO_comp α β] + rw [show PDCBehavior.liftMBO (α ≫ β) = TypedConverter.comp (A := A.withMBO) (B := B.withMBO) + (C := C.withMBO) (PDCBehavior.liftMBO α) (PDCBehavior.liftMBO β) from + PDCBehavior.liftMBO_comp α β] -- (lift α ≫ lift β) • G = lift α • (lift β • G): attach the inner converter first. - exact comp_smul _ _ G.1 + exact TypedConverter.comp_smul _ _ G.1 -- Field `winners`: the winning probabilities of the systems-level solver behaviors -- `Domain.SolverBehavior` on the input domain. winners := winners @@ -144,10 +118,11 @@ noncomputable instance games : Games Interface Game where -- └───────────────────────────┘ exact ⟨Domain.SolverBehavior.absorb B.nonempty_prefix A.nonempty_prefix α s, rfl⟩ -/-- **Interfaces are an instance of `DistinctionGames`**: the solvers are the solver behaviors, -the visible resource is the visible system, and conditional equivalence is that of the game's -random system and the resource. -/ -noncomputable instance distinctionGames : DistinctionGames Interface Resource Game where +/-- **Interfaces are an instance of `DistinctionGames`** with carrier `TypedSystem` and games +`TypedGame`: the solvers are the solver behaviors, `visible` is `TypedGame.visible`, the visible +system, and conditional equivalence is that of the game's random system and the typed system's +random system. -/ +noncomputable instance distinctionGames : DistinctionGames Interface TypedSystem TypedGame where toGames := games -- Field `solvers`: the pairs (decision probabilities, winning probabilities) of the -- systems-level solver behaviors `Domain.SolverBehavior`. @@ -164,14 +139,14 @@ noncomputable instance distinctionGames : DistinctionGames Interface Resource Ga rintro _ ⟨s, rfl⟩ exact ⟨Domain.SolverBehavior.absorb B.nonempty_prefix A.nonempty_prefix α s, rfl⟩ -- Field `visible`: the systems-level visible system `RandomSystem.visible` (`S⁻`). - visible := Game.visible + visible := TypedGame.visible -- Axiom `visible_attachGame`, discharged by the systems-level theorem -- `RandomSystem.visible_attach_liftMBO`: `(lift α • G)⁻ = α • G⁻`. visible_attachGame {A B} α G := Subtype.ext (RandomSystem.visible_attach_liftMBO B.nonempty_prefix A.nonempty_prefix α G.1.1 G.1.2) -- Field `ConditionallyEquivalent`: the systems-level `RandomSystem.ConditionallyEquivalent` - -- of the game's random system and the resource's random system. + -- of the game's random system and the typed system's random system. ConditionallyEquivalent G T := G.1.1.ConditionallyEquivalent T.1 -- Axiom `advantage_le_win`, discharged by the systems-level theorem -- `Domain.Distinguisher.advantage_le_winProbability` for the probabilistic distinguisher @@ -182,19 +157,19 @@ noncomputable instance distinctionGames : DistinctionGames Interface Resource Ga -- `s` comes from one probabilistic distinguisher `P`: its decisions are `P`'s decision -- probabilities (`hP`) and its winning probabilities are `P`'s (`hW`). obtain ⟨P, hP, hW⟩ := s.2 - change |s.1.1 (Game.visible G) - s.1.1 T| ≤ s.1.2 ⟨G.1.1, G.1.2, G.2⟩ + change |s.1.1 G.visible - s.1.1 T| ≤ s.1.2 ⟨G.1.1, G.1.2, G.2⟩ -- Rewrite the goal in terms of `P`: -- |Pr[P → 1 on G⁻] − Pr[P → 1 on T]| ≤ Pr[P sets the MBO of G] - rw [hP (Game.visible G), hP T, hW ⟨G.1.1, G.1.2, G.2⟩] + rw [hP G.visible, hP T, hW ⟨G.1.1, G.1.2, G.2⟩] -- Conditional equivalence `G |≡ T` bounds `P`'s advantage by its winning probability. exact P.advantage_le_winProbability G.1.2 T.2 G.2 hc /-- **Winning by every distinguisher bounds winning by every winner**: a bound on the winning probability of every distinguisher for the game's system bounds the winning probability of every winner. -/ -lemma win_le {A : Interface} {G : Game A} {ε : ℝ} +lemma win_le {A : Interface} {G : TypedGame A} {ε : ℝ} (hW : ∀ P : A.inputDomain.Distinguisher, P.winProbability G.1.1 ≤ ε) - {winner : Game A → ℝ} (hw : winner ∈ Games.winners A) : winner G ≤ ε := by + {winner : TypedGame A → ℝ} (hw : winner ∈ Games.winners A) : winner G ≤ ε := by -- The winner is the winning probability of a solver behavior `s`, which is that of one -- probabilistic distinguisher `P` (`hP`). obtain ⟨s, rfl⟩ := hw @@ -204,11 +179,11 @@ lemma win_le {A : Interface} {G : Game A} {ε : ℝ} rw [hP] exact hW P -/-- **Conditional equivalence bounds the distance of the visible resource** (CR18, -Theorem 4.17): a game on an interface conditionally equivalent to a resource `T`, whose MBO stays -unset with probability at least `1 - ε` on the queries of each transcript of `T`, has its -visible resource within `ε` of `T`. -/ -theorem dist_visible_le {A : Interface} {G : Game A} {T : Resource A} +/-- **Conditional equivalence bounds the distance of the visible system** (CR18, +Theorem 4.17): a game on an interface conditionally equivalent to a typed system `T`, whose MBO +stays unset with probability at least `1 - ε` on the queries of each transcript of `T`, has its +visible typed system within `ε` of `T`. -/ +theorem dist_visible_le {A : Interface} {G : TypedGame A} {T : TypedSystem A} (hc : DistinctionGames.ConditionallyEquivalent G T) {ε : ℝ≥0} (hε : ∀ h, T.1 h ≠ 0 → 1 - ε ≤ G.1.1.unsetProbability (h.map Prod.fst)) : CryptographicAlgebra.distance (DistinctionGames.visible G) T ≤ ε := by @@ -219,4 +194,64 @@ theorem dist_visible_le {A : Interface} {G : Game A} {T : Resource A} -- probability at least `1 - ε` on the queries of each transcript of `T`. exact RandomSystem.transcriptDistance_visible_le_of_unsetProbability G.1.2 T.2 G.2 hc hε +/-- The game a probabilistic discrete game presents is conditionally equivalent to a typed system +exactly when its game on random systems is conditionally equivalent to the typed system's random +system. -/ +lemma conditionallyEquivalent_ofPDG_iff {A : Interface} + (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) (hG : G.isProbDist) {R : TypedSystem A} + (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) + (S : TypedSystem A) : + TypedGame.ofPDG G hG visible |≡ S ↔ (G.behavior hG).ConditionallyEquivalent S.1 := + -- The field `ConditionallyEquivalent` of `DistinctionGames` on interfaces is the + -- systems-level `RandomSystem.ConditionallyEquivalent`, so both sides agree by definition. + Iff.rfl + +/-- **Conditional equivalence bounds the distance of a presented game**: if the visible systems +of a probabilistic discrete game `G` present `R`, the game it presents is conditionally +equivalent to `S`, and the condition holds with probability at most `ε` on the empty and on +every admitted query sequence, then `R` and `S` are at most `ε` apart. -/ +theorem game_dist_le {A : Interface} + {G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain} {hG : G.isProbDist} {R S : TypedSystem A} + (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) + (equiv : TypedGame.ofPDG G hG visible |≡ S) {ε : ℝ≥0} + (hbad : ∀ xs, xs = [] ∨ A.domain xs → G.badProbability xs ≤ ε) : + Δ R S ≤ ε := by + -- Δ(R, S) = Δ((ofPDG G)⁻, S) (`R` is the visible system of the presented game) + -- ≤ ε (`ofPDG G |≡ S`, MBO unset with probability ≥ 1 - ε) + -- + -- The bound on the condition gives the bound on the unset MBO on the queries of each + -- transcript of `S` (`PDG.one_sub_le_unsetProbability_behavior`); `dist_visible_le` then + -- bounds the distance of the visible system. + have bound := dist_visible_le equiv + (PDG.one_sub_le_unsetProbability_behavior hG A.nonempty_prefix hbad) + -- The visible system of the presented game is `R` (`TypedGame.visible_ofPDG`). + rwa [show DistinctionGames.visible (TypedGame.ofPDG G hG visible) = R from + TypedGame.visible_ofPDG G hG visible] at bound + +/-- **Conditional equivalence bounds the distance of a sampled-function game**: the typed system +sampling the function is at most `ε` from a typed system conditionally equivalent to the game +when the sampled condition holds with probability at most `ε` on the empty and on every admitted +query sequence. -/ +lemma game_dist_ofSingleFunction_le {I K X Y : Type} + [Unique I] [Fintype X] [Fintype Y] {D : List (Σ _ : I, X) → Prop} + {hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p} {bound : ℕ} + {hb : ∀ h, D h → h.length ≤ bound} + {P : Distribution K} [Distribution.IsProbability P] {f : K → X → Y} {bad : K → MC X} + {R S : TypedSystem ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩} + (equiv : TypedGame.ofSingleFunction D hD bound hb P f bad |≡ S) + (visible : R = TypedSystem.sample P (fun k => TypedSystem.ofFunction (fun _ => f k))) + {ε : ℝ≥0} + (hbad : ∀ xs, xs = [] ∨ D xs → P.mass (fun k => (bad k).1 (xs.map Sigma.snd)) ≤ ε) : + Δ R S ≤ ε := by + -- `R` is the typed system sampling the function. + subst visible + -- The distance bound for a presented game: `R` is presented by the visible systems of the + -- sampled-function game, which is conditionally equivalent to `S`. + refine game_dist_le (TypedSystem.sample_ofFunction_eq_behavior D hD bound hb P f bad) equiv + fun xs hxs => ?_ + -- The condition holds on `xs` with the `P`-probability of a key whose condition holds on + -- the values of `xs`, which `hbad` bounds by `ε`. + rw [PDG.ofSingleFunction, PDG.ofFunction_badProbability] + exact hbad xs hxs + end SystemAlgebra.Interface diff --git a/src/ConstructiveCryptography/InterfaceMonoidal.lean b/src/ConstructiveCryptography/InterfaceMonoidal.lean index ee5217c..f9608df 100644 --- a/src/ConstructiveCryptography/InterfaceMonoidal.lean +++ b/src/ConstructiveCryptography/InterfaceMonoidal.lean @@ -1,34 +1,85 @@ -import ConstructiveCryptography.ConverterCoherence -import ConstructiveCryptography.InterfaceTensorRename +import ConstructiveCryptography.InterfaceCategory +import RandomSystems.Typed.ConverterCoherence +import RandomSystems.Typed.TensorRename import Mathlib.CategoryTheory.Monoidal.Category /-! # The monoidal category of interfaces -The tensor of interfaces is the parallel interface and the tensor of converters is their -parallel composition; the associator and the unitors are the regrouping renamings. +A renaming `TypedConverter.rename` of interfaces is an isomorphism of the category of +interfaces: its inverse is the renaming by the inverse bijections, and the two compose to the +identity by `TypedConverter.rename_comp` and `TypedConverter.rename_refl`. Interfaces are an +instance of `MonoidalCategory`: `tensorObj` is the parallel interface `Interface.tensor`, +`tensorHom` is the parallel composition `TypedConverter.parallel` of typed converters, the unit +is `Interface.unit`, and the associator and the unitors are the isomorphisms of the regrouping +renamings. The axioms are discharged by `PDCBehavior.comp_tensor`, `PDCBehavior.tensor_id`, +`TypedConverter.comp_associator`, `TypedConverter.comp_leftUnitor`, +`TypedConverter.comp_rightUnitor`, and, for the pentagon and the triangle, +`TypedConverter.parallel_rename` and `TypedConverter.rename_comp`. ## Main definitions -* `Interface.monoidal`: the monoidal category of interfaces and converters +* `Interface.isoOf`: the isomorphism of a renaming +* `Interface.associator`, `Interface.leftUnitor`, `Interface.rightUnitor`, `Interface.swap`: the + regrouping isomorphisms +* `Interface.monoidal`: the monoidal category of interfaces and typed converters -/ namespace SystemAlgebra.Interface open CategoryTheory MonoidalCategory +/-- A bijection of interfaces is an isomorphism of the existing converter category. -/ +noncomputable def isoOf {A B : Interface} (e : A.I ≃ B.I) + (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) + (hf : ∀ x, (f x).1 = e x.1) (hg : ∀ y, (g y).1 = e y.1) + (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) : A ≅ B where + hom := TypedConverter.rename e f g hf hg hd + inv := TypedConverter.rename e.symm f.symm g.symm (alphabet_symm_label e f hf) + (alphabet_symm_label e g hg) + (fun h => by + have he := (hd (h.map f.symm)).symm + simpa only [List.map_map, Equiv.self_comp_symm, List.map_id] using he) + hom_inv_id := by + change TypedConverter.comp _ _ = TypedConverter.id A + rw [TypedConverter.rename_comp] + simpa only [Equiv.self_trans_symm] using TypedConverter.rename_refl A + inv_hom_id := by + change TypedConverter.comp _ _ = TypedConverter.id B + rw [TypedConverter.rename_comp] + simpa only [Equiv.symm_trans_self] using TypedConverter.rename_refl B + +noncomputable def associator (A B C : Interface) : + tensor (tensor A B) C ≅ tensor A (tensor B C) := + isoOf (Equiv.sumAssoc A.I B.I C.I) (assocAlphabet A.X B.X C.X) (assocAlphabet A.Y B.Y C.Y) + (assocAlphabet_fst A.X B.X C.X) (assocAlphabet_fst A.Y B.Y C.Y) (parallelDomain_assoc A B C) + +noncomputable def leftUnitor (A : Interface) : tensor unit A ≅ A := + isoOf (Equiv.emptySum Empty A.I) (leftUnitAlphabet A.X) (leftUnitAlphabet A.Y) + (leftUnitAlphabet_fst A.X) (leftUnitAlphabet_fst A.Y) (parallelDomain_unit_left A) + +noncomputable def rightUnitor (A : Interface) : tensor A unit ≅ A := + isoOf (Equiv.sumEmpty A.I Empty) (rightUnitAlphabet A.X) (rightUnitAlphabet A.Y) + (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) (parallelDomain_unit_right A) + +/-- Exchange the two interface families without changing their message values. -/ +noncomputable def swap (A B : Interface) : tensor A B ≅ tensor B A := + isoOf (Equiv.sumComm A.I B.I) (swapAlphabet A.X B.X) (swapAlphabet A.Y B.Y) + (by rintro ⟨(i | j), x⟩ <;> rfl) (by rintro ⟨(i | j), y⟩ <;> rfl) + (parallelDomain_swap A B) + noncomputable instance monoidalStruct : MonoidalCategoryStruct Interface where tensorObj := tensor - tensorHom := parallelConverter - whiskerLeft A _ _ β := parallelConverter (𝟙 A) β - whiskerRight α B := parallelConverter α (𝟙 B) + tensorHom := TypedConverter.parallel + whiskerLeft A _ _ β := TypedConverter.parallel (𝟙 A) β + whiskerRight α B := TypedConverter.parallel α (𝟙 B) tensorUnit := unit associator := associator leftUnitor := leftUnitor rightUnitor := rightUnitor lemma tensorHom_eq {A B C D : Interface} (α : A ⟶ B) (β : C ⟶ D) : - α ⊗ₘ β = parallelConverter α β := rfl + α ⊗ₘ β = TypedConverter.parallel α β := rfl lemma id_tensor_id (A B : Interface) : (𝟙 A ⊗ₘ 𝟙 B : A ⊗ B ⟶ A ⊗ B) = 𝟙 (A ⊗ B) := PDCBehavior.tensor_id A.nonempty_prefix B.nonempty_prefix @@ -41,29 +92,32 @@ lemma tensor_comp {A B C D E F : Interface} lemma associator_naturality {A B C D E F : Interface} (α : A ⟶ D) (β : B ⟶ E) (γ : C ⟶ F) : ((α ⊗ₘ β) ⊗ₘ γ) ≫ (α_ D E F).hom = (α_ A B C).hom ≫ (α ⊗ₘ (β ⊗ₘ γ)) := - comp_associator α β γ + TypedConverter.comp_associator α β γ lemma leftUnitor_naturality {A B : Interface} (α : A ⟶ B) : (𝟙 (𝟙_ Interface) ⊗ₘ α) ≫ (λ_ B).hom = (λ_ A).hom ≫ α := - comp_leftUnitor α + TypedConverter.comp_leftUnitor α lemma rightUnitor_naturality {A B : Interface} (α : A ⟶ B) : (α ⊗ₘ 𝟙 (𝟙_ Interface)) ≫ (ρ_ B).hom = (ρ_ A).hom ≫ α := - comp_rightUnitor α + TypedConverter.comp_rightUnitor α lemma pentagon (A B C D : Interface) : ((α_ A B C).hom ⊗ₘ 𝟙 D) ≫ (α_ A (B ⊗ C) D).hom ≫ (𝟙 A ⊗ₘ (α_ B C D).hom) = (α_ (A ⊗ B) C D).hom ≫ (α_ A B (C ⊗ D)).hom := by - change parallelConverter (associator A B C).hom (𝟙 D) ≫ - (associator A (tensor B C) D).hom ≫ parallelConverter (𝟙 A) (associator B C D).hom = - (associator (tensor A B) C D).hom ≫ (associator A B (tensor C D)).hom - rw [← rename_refl D, ← rename_refl A] + change TypedConverter.comp + (TypedConverter.parallel (associator A B C).hom (TypedConverter.id D)) + (TypedConverter.comp (associator A (tensor B C) D).hom + (TypedConverter.parallel (TypedConverter.id A) (associator B C D).hom)) = + TypedConverter.comp (associator (tensor A B) C D).hom (associator A B (tensor C D)).hom + rw [← TypedConverter.rename_refl D, ← TypedConverter.rename_refl A] simp only [associator, isoOf] - erw [parallelConverter_rename (A := tensor (tensor A B) C) (B := tensor A (tensor B C)) + erw [TypedConverter.parallel_rename (A := tensor (tensor A B) C) (B := tensor A (tensor B C)) (C := D) (D := D)] - erw [parallelConverter_rename (A := A) (B := A) (C := tensor (tensor B C) D) (D := tensor B (tensor C D))] - simp only [rename_comp] - erw [rename_comp] + erw [TypedConverter.parallel_rename (A := A) (B := A) (C := tensor (tensor B C) D) + (D := tensor B (tensor C D))] + simp only [TypedConverter.rename_comp] + erw [TypedConverter.rename_comp] congr 1 · apply Equiv.ext intro x @@ -77,13 +131,14 @@ lemma pentagon (A B C D : Interface) : lemma triangle (A B : Interface) : (α_ A (𝟙_ Interface) B).hom ≫ (𝟙 A ⊗ₘ (λ_ B).hom) = (ρ_ A).hom ⊗ₘ 𝟙 B := by - change (associator A unit B).hom ≫ parallelConverter (𝟙 A) (leftUnitor B).hom = - parallelConverter (rightUnitor A).hom (𝟙 B) - rw [← rename_refl A, ← rename_refl B] + change TypedConverter.comp (associator A unit B).hom + (TypedConverter.parallel (TypedConverter.id A) (leftUnitor B).hom) = + TypedConverter.parallel (rightUnitor A).hom (TypedConverter.id B) + rw [← TypedConverter.rename_refl A, ← TypedConverter.rename_refl B] simp only [associator, leftUnitor, rightUnitor, isoOf] - erw [parallelConverter_rename (A := A) (B := A) (C := tensor unit B) (D := B)] - erw [parallelConverter_rename (A := tensor A unit) (B := A) (C := B) (D := B)] - simp only [rename_comp] + erw [TypedConverter.parallel_rename (A := A) (B := A) (C := tensor unit B) (D := B)] + erw [TypedConverter.parallel_rename (A := tensor A unit) (B := A) (C := B) (D := B)] + simp only [TypedConverter.rename_comp] congr 1 · apply Equiv.ext intro x diff --git a/src/ConstructiveCryptography/Notation.lean b/src/ConstructiveCryptography/Notation.lean index 57eea4c..4ca4d6c 100644 --- a/src/ConstructiveCryptography/Notation.lean +++ b/src/ConstructiveCryptography/Notation.lean @@ -9,24 +9,24 @@ Scoped notation for the CC operations on interfaces: `Δ R S` for the distance, parallel composition, `S —[α]→ T` and `S —[α; ε]→ T` for exact and approximate construction, `R ≃[ε] S` for substitution within `ε` for the admitted distinguishers (`Interface.AdmissibleDistinguishers`), and `G |≡ T` for conditional equivalence of a game to a -resource. The compatibility laws of the distance are restated with `∥`, the concrete -parallel composition, for the `cc_nonexpand` tactic, and `cc_normalize` applies locality, -`(α ⊗ₘ β) • (R ∥ S) = α • R ∥ β • S`, whether the interfaces are written with `⊗` or with -`Interface.tensor`. +typed system. The compatibility laws of the distance are restated with `∥`, the parallel +composition `TypedSystem.parallel`, for the `cc_nonexpand` tactic, and `cc_normalize` applies +locality, `(α ⊗ₘ β) • (R ∥ S) = α • R ∥ β • S`, whether the interfaces are written with `⊗` or +with `Interface.tensor`. -/ namespace SystemAlgebra open CategoryTheory CategoryTheory.MonoidalCategory -/-- The CC distance of two resources on an interface. Both arguments are elaborated as -resources on an interface, so arrows acting on them take their domains from the resources. -/ +/-- The CC distance of two typed systems on an interface. Both arguments are elaborated as typed +systems on an interface, so arrows acting on them take their domains from the systems. -/ scoped macro "Δ " R:term:max S:term:max : term => `(ConstructiveCryptography.CryptographicAlgebra.distance - ($R : Interface.Resource _) ($S : Interface.Resource _)) + ($R : TypedSystem _) ($S : TypedSystem _)) scoped infixl:70 " ∥ " => - Interface.parallel + TypedSystem.parallel scoped notation:50 source " —[" converter "]→ " target:51 => ConstructiveCryptography.CryptographicAlgebra.Specification.Constructs @@ -42,8 +42,8 @@ scoped notation:50 R:51 " ≃[" error "] " S:51 => ConstructiveCryptography.CryptographicAlgebra.DistinguisherAdvantage.SubstitutesWithin (Interface.distinguisherAdvantage Interface.AdmissibleDistinguishers.admissible) error R S -/-- Conditional equivalence `G |≡ T` of a game to a resource (CR18, Definition 4.19): the field -of `DistinctionGames`. -/ +/-- Conditional equivalence `G |≡ T` of a game to a typed system (CR18, Definition 4.19): the +field of `DistinctionGames`. -/ scoped notation:50 G:51 " |≡ " T:51 => ConstructiveCryptography.DistinctionGames.ConditionallyEquivalent G T @@ -52,7 +52,7 @@ namespace Interface attribute [cc_normalization] comp_smul identity_attach lemma tensor_smul {A B C D : Interface} (α : A ⟶ B) (β : C ⟶ D) - (R : Resource B) (S : Resource D) : + (R : TypedSystem B) (S : TypedSystem D) : (α ⊗ₘ β) • (R ∥ S) = (α • R) ∥ (β • S) := ConstructiveCryptography.CryptographicAlgebra.attach_parallel α β R S @@ -65,35 +65,35 @@ the rule is keyed on the action alone and matches its arguments here. -/ simproc [cc_normalization] tensorSmul (@HSMul.hSMul _ _ _ _ _ _) := fun e => do let_expr HSMul.hSMul _ _ _ _ f x := e | return .continue let_expr MonoidalCategoryStruct.tensorHom _ _ _ A B C D α β := f | return .continue - let_expr Interface.parallel _ _ R S := x | return .continue + let_expr TypedSystem.parallel _ _ R S := x | return .continue let proof := mkAppN (mkConst ``tensor_smul) #[A, B, C, D, α, β, 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 : Resource B) : +lemma distance_smul_le {A B : Interface} (α : A ⟶ B) (R S : TypedSystem B) : Δ (α • R) (α • S) ≤ Δ R S := ConstructiveCryptography.CryptographicAlgebra.distance_attach_le α R S /-- The hybrid inequality, with both endpoints inferred from the goal. -/ -lemma distance_triangle {A : Interface} {R T : Resource A} (S : Resource A) : +lemma distance_triangle {A : Interface} {R T : TypedSystem A} (S : TypedSystem A) : Δ R T ≤ Δ R S + Δ S T := ConstructiveCryptography.CryptographicAlgebra.distance_triangle R S T lemma distance_parallel_left_le {A B : Interface} - (R S : Resource A) (T : Resource B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := + (R S : TypedSystem A) (T : TypedSystem B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := ConstructiveCryptography.CryptographicAlgebra.distance_parallel_left_le R S T lemma distance_parallel_right_le {A B : Interface} - (R : Resource A) (S T : Resource B) : Δ (R ∥ S) (R ∥ T) ≤ Δ S T := + (R : TypedSystem A) (S T : TypedSystem B) : Δ (R ∥ S) (R ∥ T) ≤ Δ S T := ConstructiveCryptography.CryptographicAlgebra.distance_parallel_right_le R S T lemma distance_parallel_le {A B : Interface} - (R S : Resource A) (T U : Resource B) : + (R S : TypedSystem A) (T U : TypedSystem B) : Δ (R ∥ T) (S ∥ U) ≤ Δ R S + Δ T U := ConstructiveCryptography.CryptographicAlgebra.distance_parallel_le R S T U diff --git a/src/ConstructiveCryptography/PresentedGame.lean b/src/ConstructiveCryptography/PresentedGame.lean deleted file mode 100644 index 5c7d96d..0000000 --- a/src/ConstructiveCryptography/PresentedGame.lean +++ /dev/null @@ -1,239 +0,0 @@ -import RandomSystems.Game.FunctionGame -import ConstructiveCryptography.InterfaceGame -import ConstructiveCryptography.Functional -import ConstructiveCryptography.Notation - -/-! -# Games presented by discrete games - -A probabilistic discrete game whose visible systems present a resource `R` presents a game on -the interface of `R`, the behavior of its deterministic games with the MBO, and the visible -resource of that game is `R`. Its conditional equivalence to a resource, the field of the -instance of `DistinctionGames`, is that of the game it presents on random systems. The bound of -conditional equivalence on games (`Interface.dist_visible_le`, CR18 Theorem 4.17) then bounds -the distance from `R` to a resource `S` conditionally equivalent to the game by any bound on the -condition on the empty and on every admitted query sequence. A single-label sampled function -with a hidden condition presents a game on its interface, conditionally equivalent to the -resource sampling the ideal function once the answers with the condition unset factor through -the ideal answers. - -## Main definitions - -* `Interface.Game.ofPDG`: the game a probabilistic discrete game presents -* `Interface.Game.ofSingleFunction`: the game of a single-label sampled function - -## Main results - -* `Interface.Game.visible_ofPDG`: its visible resource is the presented resource -* `Interface.Game.conditionallyEquivalent_ofPDG_iff`: its conditional equivalence is that of the - game on random systems -* `Interface.game_dist_le`: the distance bound for a presented game -* `Interface.Resource.sample_ofFunction_eq_behavior`: the resource sampling a single-label - function is presented by the sampled-function game -* `Interface.ofSingleFunction_conditionallyEquivalent`: a single-label sampled-function game is - conditionally equivalent to the resource sampling the ideal function, from the fixed-query - factorization -* `Interface.game_dist_ofSingleFunction_le`: the distance bound for a single-label - sampled-function game --/ - -namespace SystemAlgebra - -open Probability ConstructiveCryptography -open scoped SystemAlgebra NNReal - -namespace Interface - -namespace Game - -variable {A : Interface} - -/-- **The game a probabilistic discrete game presents**: when the visible systems of `G` present -the resource `R`, the behavior of its deterministic games with the MBO is a game on the interface -of `R`. -/ -noncomputable def ofPDG (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) (hG : G.isProbDist) - {R : Resource A} (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) : - Game A := - -- The random system is the behavior of `G` with the MBO. It replies at the queried interface - -- because its visible system, `R`, does, and its MBO once set stays set. - ⟨⟨G.behavior hG, PDG.repliesAtQueriedInterface_behavior hG (visible ▸ R.2)⟩, - PDG.monotoneMBO_behavior hG⟩ - -/-- The visible resource of the game a probabilistic discrete game presents is the resource its -visible systems present. -/ -lemma visible_ofPDG (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) (hG : G.isProbDist) - {R : Resource A} (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) : - DistinctionGames.visible (ofPDG G hG visible) = R := - -- The visible system of the behavior of `G` is the behavior of its visible systems - -- (`PDG.visible_behavior`), which is `R`. - Subtype.ext ((PDG.visible_behavior hG).trans visible.symm) - -/-- The game a probabilistic discrete game presents is conditionally equivalent to a resource -exactly when its game on random systems is conditionally equivalent to the resource's random -system. -/ -lemma conditionallyEquivalent_ofPDG_iff (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) - (hG : G.isProbDist) {R : Resource A} - (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) (S : Resource A) : - ofPDG G hG visible |≡ S ↔ (G.behavior hG).ConditionallyEquivalent S.1 := - -- The field `ConditionallyEquivalent` of `DistinctionGames` on interfaces is the - -- systems-level `RandomSystem.ConditionallyEquivalent`, so both sides agree by definition. - Iff.rfl - -end Game - -/-- **Conditional equivalence bounds the distance of a presented game**: if the visible systems -of a probabilistic discrete game `G` present `R`, the game it presents is conditionally -equivalent to `S`, and the condition holds with probability at most `ε` on the empty and on -every admitted query sequence, then `R` and `S` are at most `ε` apart. -/ -theorem game_dist_le {A : Interface} - {G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain} {hG : G.isProbDist} {R S : Resource A} - (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) - (equiv : Game.ofPDG G hG visible |≡ S) {ε : ℝ≥0} - (hbad : ∀ xs, xs = [] ∨ A.domain xs → G.badProbability xs ≤ ε) : - Δ R S ≤ ε := by - -- Δ(R, S) = Δ((ofPDG G)⁻, S) (`R` is the visible resource of the presented game) - -- ≤ ε (`ofPDG G |≡ S`, MBO unset with probability ≥ 1 - ε) - -- - -- The bound on the condition gives the bound on the unset MBO on the queries of each - -- transcript of `S` (`PDG.one_sub_le_unsetProbability_behavior`); `dist_visible_le` then - -- bounds the distance of the visible resource. - have bound := dist_visible_le equiv - (PDG.one_sub_le_unsetProbability_behavior hG A.nonempty_prefix hbad) - -- The visible resource of the presented game is `R`. - rwa [Game.visible_ofPDG] at bound - -/-- **The resource sampling a single-label function** is the behavior of the visible systems of -the sampled-function game. -/ -lemma Resource.sample_ofFunction_eq_behavior {I K X Y : Type} [Unique I] [Fintype X] - [Fintype Y] (D : List (Σ _ : I, X) → Prop) - (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) (bound : ℕ) - (hb : ∀ h, D h → h.length ≤ bound) (P : Distribution K) [Distribution.IsProbability P] - (f : K → X → Y) (bad : K → MC X) : - (Resource.sample (A := ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩) P - (fun k => Resource.ofFunction (fun _ => f k))).1 = - PDS.behavior (PDG.ofSingleFunction D hD bound hb P f bad).underlying - (PDG.underlying_probability (PDG.ofFunction_isProbDist D hD bound hb - (Distribution.IsProbability.isProbDist P) _ _)) := by - -- Compare the two random systems transcript by transcript. - apply RandomSystem.ext - intro h - -- The resource sampling the function gives `h` the probability that the DDS answering with - -- the sampled function replies with `h`. - rw [Resource.sample_ofFunction_mass] - change _ = behaviorMass _ _ _ - -- The visible systems of the sampled-function game are the sampled function - -- (`PDG.ofFunction_underlying`), with its answers tagged with the single label. - rw [PDG.ofSingleFunction, PDG.ofFunction_underlying] - -- Both sides are the probability, over `k ∼ P`, that the DDS of `f k` replies with `h`. - simp only [behaviorMass, PDS.ofFunction, Distribution.mass_fTransform] - -/-- **The game of a single-label sampled function** with a hidden condition: the game it presents -on its interface, whose visible resource samples the function. -/ -noncomputable def Game.ofSingleFunction {I K X Y : Type} [Unique I] [Fintype X] [Fintype Y] - (D : List (Σ _ : I, X) → Prop) (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) - (bound : ℕ) (hb : ∀ h, D h → h.length ≤ bound) (P : Distribution K) - [Distribution.IsProbability P] (f : K → X → Y) (bad : K → MC X) : - Game ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩ := - Game.ofPDG (PDG.ofSingleFunction D hD bound hb P f bad) - (PDG.ofFunction_isProbDist D hD bound hb (Distribution.IsProbability.isProbDist P) _ _) - (Resource.sample_ofFunction_eq_behavior D hD bound hb P f bad) - -open Classical in -/-- **A single-label sampled-function game is conditionally equivalent to the resource sampling -the ideal function** when, on every fixed query sequence, the answers jointly with the unset -condition factor through the ideal answers. -/ -lemma ofSingleFunction_conditionallyEquivalent {I K X Y : Type} [Unique I] [Fintype X] - [Fintype Y] (D : List (Σ _ : I, X) → Prop) - (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) (bound : ℕ) - (hb : ∀ h, D h → h.length ≤ bound) - (P : Distribution K) [Distribution.IsProbability P] - (f : K → X → Y) (bad : K → MC X) - (Q : Distribution (X → Y)) [Distribution.IsProbability Q] - (factor : ∀ xs (answers : X → Y), - P.mass (fun k => (∀ x ∈ xs, f k x = answers x) ∧ ¬ (bad k).1 xs) = - Q.mass (fun g => ∀ x ∈ xs, g x = answers x) * - P.mass (fun k => ¬ (bad k).1 xs)) : - Game.ofSingleFunction D hD bound hb P f bad |≡ - Resource.sample (A := ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩) - Q (fun g => Resource.ofFunction (fun _ => g)) := by - -- Plan: - -- 1. Reduce to conditional equivalence of the game on random systems. - -- 2. Apply the systems-level `PDG.ofFunction_conditionallyEquivalent` with the ideal law - -- `taggedLaw` (`Q`, its answers tagged with the single label); its factorization - -- hypothesis follows from `factor`. - -- 3. Identify the ideal random system of step 2 with the resource sampling `Q`. - -- - -- Step 1: the field `ConditionallyEquivalent` is that of the game's random system. - refine (Game.conditionallyEquivalent_ofPDG_iff _ _ - (Resource.sample_ofFunction_eq_behavior D hD bound hb P f bad) _).mpr ?_ - unfold PDG.ofSingleFunction - -- Step 2: a function `X → Y` as a function on the single interface, and the ideal law. - let tagged := fun g : X → Y => fun x : Σ _ : I, X => (⟨x.1, g x.2⟩ : Σ _ : I, Y) - let taggedLaw := Distribution.fTransform tagged Q - have hQ := Distribution.IsProbability.isProbDist taggedLaw - have hP := Distribution.IsProbability.isProbDist P - -- The sampled-function game, its condition read on the values of the queries, is - -- conditionally equivalent to the function sampled from `taggedLaw`. - have equiv := PDG.ofFunction_conditionallyEquivalent D hD bound hb P (fun k => tagged (f k)) - (fun k => ⟨fun xs => (bad k).1 (xs.map Sigma.snd), - fun {_ _} hp => (bad k).2 (hp.map Sigma.snd)⟩) - (hG := by exact PDG.ofFunction_isProbDist D hD bound hb hP _ _) taggedLaw hQ (by - -- The factorization on a fixed query sequence `xs`, with `xs' = xs.map Sigma.snd`: - -- - -- P[f k = answers on xs' ∧ ¬ bad k xs'] - -- = Q[g = answers on xs'] · P[¬ bad k xs'] (`factor`) - -- = (1 - P[bad k xs']) · Q[g = answers on xs'] (complement, commute) - intro xs answers - -- The mass of `taggedLaw` is the `Q`-mass of the tagged event. - dsimp only [taggedLaw] - rw [Distribution.mass_fTransform] - -- At the single label, a tagged reply equals an answer exactly when its value does. - simp only [tagged, single_interface_answers_iff] - have he := factor (xs.map Sigma.snd) (fun x => (answers ⟨default, x⟩).2) - -- P[bad] + P[¬ bad] = 1, since `P` is a probability distribution. - have complement := Distribution.mass_add_compl P - (fun k => (bad k).1 (xs.map Sigma.snd)) - rw [Distribution.IsProbability.weight_eq_one (X := P)] at complement - have good : P.mass (fun k => ¬ (bad k).1 (xs.map Sigma.snd)) = - 1 - P.mass (fun k => (bad k).1 (xs.map Sigma.snd)) := by linarith - -- Rewrite `factor` into the required form. - rw [good, mul_comm] at he - exact he) - -- Step 3: on each transcript `h`, the game sides agree by definition; it remains to show - -- that the resource sampling `Q` is the behavior of the PDS sampling from `taggedLaw`. - intro h - convert equiv h using 2 - rw [Resource.sample_ofFunction_mass] - change _ = behaviorMass _ _ _ - -- Both are the `Q`-probability that the DDS of the tagged function replies with `h`. - simp only [behaviorMass, PDS.ofFunction, taggedLaw, Distribution.mass_fTransform] - rfl - -/-- **Conditional equivalence bounds the distance of a sampled-function game**: the resource -sampling the function is at most `ε` from a resource conditionally equivalent to the game when -the sampled condition holds with probability at most `ε` on the empty and on every admitted -query sequence. -/ -lemma game_dist_ofSingleFunction_le {I K X Y : Type} - [Unique I] [Fintype X] [Fintype Y] {D : List (Σ _ : I, X) → Prop} - {hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p} {bound : ℕ} - {hb : ∀ h, D h → h.length ≤ bound} - {P : Distribution K} [Distribution.IsProbability P] {f : K → X → Y} {bad : K → MC X} - {R S : Resource ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩} - (equiv : Game.ofSingleFunction D hD bound hb P f bad |≡ S) - (visible : R = Resource.sample P (fun k => Resource.ofFunction (fun _ => f k))) {ε : ℝ≥0} - (hbad : ∀ xs, xs = [] ∨ D xs → P.mass (fun k => (bad k).1 (xs.map Sigma.snd)) ≤ ε) : - Δ R S ≤ ε := by - -- `R` is the resource sampling the function. - subst visible - -- The distance bound for a presented game: `R` is presented by the visible systems of the - -- sampled-function game, which is conditionally equivalent to `S`. - refine game_dist_le (Resource.sample_ofFunction_eq_behavior D hD bound hb P f bad) equiv - fun xs hxs => ?_ - -- The condition holds on `xs` with the `P`-probability of a key whose condition holds on - -- the values of `xs`, which `hbad` bounds by `ε`. - rw [PDG.ofSingleFunction, PDG.ofFunction_badProbability] - exact hbad xs hxs - -end Interface - -end SystemAlgebra diff --git a/src/ConstructiveCryptography/ResourceParallelAttachment.lean b/src/ConstructiveCryptography/ResourceParallelAttachment.lean deleted file mode 100644 index 7c7d237..0000000 --- a/src/ConstructiveCryptography/ResourceParallelAttachment.lean +++ /dev/null @@ -1,55 +0,0 @@ -import ConstructiveCryptography.ResourceParallel - -/-! -# Locality of independent attachment - -Attaching parallel converters to parallel resources is attachment component by component: -`(α ⊗ β)(R ∥ S) = αR ∥ βS`. With presentations of the two converters and the two resources, -both sides are mixtures over the same four independent samples. --/ - -namespace SystemAlgebra.Interface - -open Classical Probability CategoryTheory - -variable {A B C D : Interface} - -/-- **Locality**: parallel converters act on parallel resources component by component. -/ -lemma parallel_attach (α : A ⟶ B) (β : C ⟶ D) (R : Resource B) (S : Resource D) : - (parallelConverter α β • parallel R S : Resource (tensor A C)) = - parallel (α • R : Resource A) (β • S : Resource C) := by - obtain ⟨ba, P, hP⟩ := α.2 - obtain ⟨bb, Q, hQ⟩ := β.2 - obtain ⟨T, rfl⟩ := R.exists_ofPDS - obtain ⟨U, rfl⟩ := S.exists_ofPDS - have hαT : (α • Resource.ofPDS T : Resource A) = - Resource.ofPDS (attachPDS A.nonempty_prefix P T) := - Subtype.ext (RandomSystem.ext fun h => - PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix α (Resource.ofPDS T).1 - (Resource.ofPDS T).2 P T hP (fun _ => rfl) h) - have hβU : (β • Resource.ofPDS U : Resource C) = - Resource.ofPDS (attachPDS C.nonempty_prefix Q U) := - Subtype.ext (RandomSystem.ext fun h => - PDCBehavior.attach_presents D.nonempty_prefix C.nonempty_prefix β (Resource.ofPDS U).1 - (Resource.ofPDS U).2 Q U hQ (fun _ => rfl) h) - have hαβ := fun h => (PDCBehavior.tensor_presents α β P Q hP hQ h).symm - rw [hαT, hβU, parallel_ofPDS, parallel_ofPDS] - apply Subtype.ext - apply RandomSystem.ext - intro h - rw [smul_val, PDCBehavior.attach_presents (tensor B D).nonempty_prefix - (tensor A C).nonempty_prefix (parallelConverter α β) - (Resource.ofPDS (A := tensor B D) (parallelPDS T U)).1 - (Resource.ofPDS (A := tensor B D) (parallelPDS T U)).2 _ (parallelPDS T U) hαβ - (fun _ => rfl) h, - behaviorMass_attachPDS] - change _ = behaviorMass _ _ _ - simp only [behaviorMass, tensorPDC, parallelPDS, attachPDS, Distribution.mass_fTransform, - Distribution.fTransform_prod_left, Distribution.fTransform_prod_right] - rw [← Distribution.independent_product_middle P.1 Q.1 T.1 U.1, Distribution.mass_fTransform] - apply Distribution.mass_congr - intro p - exact iff_of_eq (congrArg (fun t => Replies t (h.map Prod.fst) (h.map Prod.snd)) - (trim_apply_tensorL_pair p.1.1.2.isDDC p.1.2.2.isDDC p.2.1.2.2.1 p.2.2.2.2.1)) - -end SystemAlgebra.Interface diff --git a/src/ConstructiveCryptography/Substitution/Parallel.lean b/src/ConstructiveCryptography/Substitution/Parallel.lean index 3154e11..66943ec 100644 --- a/src/ConstructiveCryptography/Substitution/Parallel.lean +++ b/src/ConstructiveCryptography/Substitution/Parallel.lean @@ -1,4 +1,4 @@ -import ConstructiveCryptography.Context +import RandomSystems.Typed.Context import ConstructiveCryptography.Substitution.Relaxation import ConstructiveCryptography.InterfaceAlgebra @@ -7,9 +7,10 @@ set_option autoImplicit false /-! # Substitution images and parallel composition -For interfaces, the fixed contexts of `ConstructiveCryptography.Context` realize parallel composition with a fixed -resource. A single-substitution relaxation whose transformation class is closed under both -contexts is therefore compatible with parallel composition. +For interfaces, the fixed contexts `TypedConverter.rightContext` and `TypedConverter.leftContext` +realize parallel composition with a fixed typed system. A single-substitution relaxation whose +transformation class is closed under both contexts is therefore compatible with parallel +composition. ## Main results @@ -38,17 +39,17 @@ Jost's locality equation, Proposition 2.2.3 (printed p. 18), supplies proved by the two context-attachment equations. -/ theorem singleSubstitutionRelaxation_parallelCompatible {D : Interface} (transformations : ∀ A : Interface, Set (A ⟶ D)) - (left right : Interface.Resource D) - (diagonal : ∀ (A : Interface) (resource : Interface.Resource A), + (left right : TypedSystem D) + (diagonal : ∀ (A : Interface) (R : TypedSystem A), ∃ transformation ∈ transformations A, - transformation • left = resource ∧ - transformation • right = resource) - (rightClosed : ∀ (A B : Interface) (context : Interface.Resource B) + transformation • left = R ∧ + transformation • right = R) + (rightClosed : ∀ (A B : Interface) (context : TypedSystem B) (transformation : A ⟶ D), transformation ∈ transformations A → - Interface.rightContext A context ≫ transformation ∈ transformations (A ⊗ B)) - (leftClosed : ∀ (A B : Interface) (context : Interface.Resource A) + TypedConverter.rightContext A context ≫ transformation ∈ transformations (A ⊗ B)) + (leftClosed : ∀ (A B : Interface) (context : TypedSystem A) (transformation : B ⟶ D), transformation ∈ transformations B → - Interface.leftContext context B ≫ transformation ∈ transformations (A ⊗ B)) : + TypedConverter.leftContext context B ≫ transformation ∈ transformations (A ⊗ B)) : Specification.Relaxation.ParallelCompatible (fun A => Specification.singleSubstitutionRelaxation (transformations A) left right (diagonal A)) := by @@ -56,42 +57,42 @@ theorem singleSubstitutionRelaxation_parallelCompatible {D : Interface} dsimp only simp only [Specification.singleSubstitutionRelaxation_apply] constructor - · rintro resource ⟨original, ⟨transformation, allowed, leftEq, center⟩, + · rintro R ⟨original, ⟨transformation, allowed, leftEq, center⟩, context, admitted, rfl⟩ -- Put the fixed right context around the same single transformation. - refine ⟨Interface.rightContext A context ≫ transformation, + refine ⟨TypedConverter.rightContext A context ≫ transformation, rightClosed A B context transformation allowed, ?_, ?_⟩ - · exact (congrArg (fun resource : Interface.Resource A => - Interface.parallel resource context) leftEq).trans - ((Interface.attach_rightContext + · exact (congrArg (fun R : TypedSystem A => + TypedSystem.parallel R context) leftEq).trans + ((TypedConverter.attach_rightContext (transformation • left) context).symm.trans (Interface.comp_smul - (Interface.rightContext A context) transformation left).symm) + (TypedConverter.rightContext A context) transformation left).symm) · -- Its other endpoint is the same context around the admitted center. refine ⟨transformation • right, center, context, admitted, ?_⟩ - exact (Interface.attach_rightContext + exact (TypedConverter.attach_rightContext (transformation • right) context).symm.trans (Interface.comp_smul - (Interface.rightContext A context) transformation right).symm - · rintro resource ⟨context, admitted, + (TypedConverter.rightContext A context) transformation right).symm + · rintro R ⟨context, admitted, original, ⟨transformation, allowed, leftEq, center⟩, rfl⟩ -- The left context uses the other ordered converter, without a swap. - refine ⟨Interface.leftContext context B ≫ transformation, + refine ⟨TypedConverter.leftContext context B ≫ transformation, leftClosed A B context transformation allowed, ?_, ?_⟩ - · exact (congrArg (fun resource : Interface.Resource B => - Interface.parallel context resource) leftEq).trans - ((Interface.attach_leftContext context + · exact (congrArg (fun R : TypedSystem B => + TypedSystem.parallel context R) leftEq).trans + ((TypedConverter.attach_leftContext context (transformation • left)).symm.trans (Interface.comp_smul - (Interface.leftContext context B) transformation left).symm) + (TypedConverter.leftContext context B) transformation left).symm) · -- Membership of the unchanged component and the original center suffice. refine ⟨context, admitted, transformation • right, center, ?_⟩ - exact (Interface.attach_leftContext context + exact (TypedConverter.attach_leftContext context (transformation • right)).symm.trans (Interface.comp_smul - (Interface.leftContext context B) transformation right).symm + (TypedConverter.leftContext context B) transformation right).symm end diff --git a/src/Examples/AuthenticatedEncryption/Collision.lean b/src/Examples/AuthenticatedEncryption/Collision.lean index 9fa115e..6be7fc6 100644 --- a/src/Examples/AuthenticatedEncryption/Collision.lean +++ b/src/Examples/AuthenticatedEncryption/Collision.lean @@ -1,5 +1,5 @@ import Examples.AuthenticatedEncryption.Hybrid -import ConstructiveCryptography.PresentedGame +import ConstructiveCryptography.InterfaceGame /-! # Authenticated encryption: the collision step @@ -453,10 +453,10 @@ lemma collisionGame_badProbability (xs : List (Σ i, (AE.perPort M C q).X i)) : /-- **The collision game is conditionally equivalent to the ideal**: the replies with no collision are the ideal replies, independently of the outer replacement table. -/ lemma collisionGame_conditionallyEquivalent : - Interface.Game.ofPDG (collisionGame scheme q) (collisionGame_isProbDist scheme q) + TypedGame.ofPDG (collisionGame scheme q) (collisionGame_isProbDist scheme q) (hybrid_visible scheme q) |≡ (AE.Ideal.perPort M C (budget := q) • Encryption.Real.perPort scheme : - Interface.Resource (AE.perPort M C q)) := by + TypedSystem (AE.perPort M C q)) := by -- Plan, on a transcript `h` with queries `xs`, `ω = (ω.1, ω.2)` the hybrid's tables with -- `ω.2` the outer replacement table, and `Coll` the collision of `xs`'s original messages -- with `ω.2`: @@ -472,11 +472,11 @@ lemma collisionGame_conditionallyEquivalent : -- = Pr[¬Coll] · P_ideal(h) (step 5, ideal_mass_hybridTables) -- = (1 − Pr[Coll]) · P_ideal(h) (step 2, complement) -- - -- Step 1: the presented game is `|≡` the ideal resource exactly when its game on random + -- Step 1: the presented game is `|≡` the ideal typed system exactly when its game on random -- systems is conditionally equivalent to the ideal's random system -- (`conditionallyEquivalent_ofPDG_iff`); that follows from the factorization above on every -- transcript `h` (`PDG.conditionallyEquivalent_behavior`). - refine (Interface.Game.conditionallyEquivalent_ofPDG_iff _ _ _ _).mpr + refine (Interface.conditionallyEquivalent_ofPDG_iff _ _ _ _).mpr (PDG.conditionallyEquivalent_behavior _ (AE.perPort M C q).nonempty_prefix fun h => ?_) -- Unfold the condition's probability (`collisionGame_badProbability`), the ideal as the -- ideal oracle on its tables (`ideal_mass`), and the left side as a mass over `hybridLaw`. @@ -537,7 +537,7 @@ theorem collisionGame_badProbability_le (xs : List (Σ i, (AE.perPort M C q).X i /-- **The collision step**: the hybrid is within `q_e² / |M|` of the ideal. -/ theorem hybrid_ideal_distance_le : Δ (Hybrid scheme q) (AE.Ideal.perPort M C (budget := q) • Encryption.Real.perPort scheme : - Interface.Resource (AE.perPort M C q)) ≤ + TypedSystem (AE.perPort M C q)) ≤ ((q .enc) ^ 2 / Fintype.card M : ℝ≥0) := -- The distinguisher D on the left queries either system at the ports `enc` (sends `m`, -- receives `c`) and `dec` (sends `c`, receives `m` or ⊥), at most `q p` times at port `p`; diff --git a/src/Examples/AuthenticatedEncryption/Hybrid.lean b/src/Examples/AuthenticatedEncryption/Hybrid.lean index a19faf4..a1d4122 100644 --- a/src/Examples/AuthenticatedEncryption/Hybrid.lean +++ b/src/Examples/AuthenticatedEncryption/Hybrid.lean @@ -41,7 +41,7 @@ lemma tableLaw_isProbDist {X : Type} (law : Distribution.ProbDist X) (k : ℕ) : /-- **The real system is an automaton** on its key and encryption tables. -/ lemma real_eq (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : - AE.Real.perPort scheme (budget := q) = Resource.ofAutomaton (AE.perPort M C q) + AE.Real.perPort scheme (budget := q) = TypedSystem.ofAutomaton (AE.perPort M C q) (realStep scheme (AE.Real.bound scheme * ∑ i, q i)) ⟨Distribution.fTransform (fun ω => (none, ((ω.1, 0), (ω.2, 0)))) (Distribution.prod (tableLaw (AE.Real.law1 scheme) (AE.Real.bound scheme * ∑ i, q i)) @@ -49,8 +49,8 @@ lemma real_eq (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : Distribution.fTransform_isProbDist _ (Distribution.prod_isProbDist _ _ (Distribution.pi_isProbDist fun _ => (AE.Real.law1 scheme).2) (Distribution.pi_isProbDist fun _ => (AE.Real.law2 scheme).2))⟩ := by - rw [AE.Real.perPort, AE.Real.randomness, Resource.source, Resource.source, parallel_ofAutomaton, - Converter.ofProgram_smul_ofAutomaton] + rw [AE.Real.perPort, AE.Real.randomness, TypedSystem.source, TypedSystem.source, + TypedSystem.parallel_ofAutomaton, TypedConverter.ofProgram_smul_ofAutomaton] congr 1 apply Subtype.ext dsimp only @@ -59,17 +59,18 @@ lemma real_eq (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) : /-- **The real encryption system is an automaton** on its key and encryption tables. -/ lemma encryptionReal_eq (scheme : SymmetricEncryption K M C) (q : Encryption.Port → ℕ) : - Encryption.Real.perPort scheme (budget := q) = Resource.ofAutomaton (Encryption.perPort M C q) - (encryptionRealStep scheme (Encryption.Real.bound scheme * ∑ i, q i)) - ⟨Distribution.fTransform (fun ω => (none, ((ω.1, 0), (ω.2, 0)))) - (Distribution.prod - (tableLaw (Encryption.Real.law1 scheme) (Encryption.Real.bound scheme * ∑ i, q i)) - (tableLaw (Encryption.Real.law2 scheme) (Encryption.Real.bound scheme * ∑ i, q i))), - Distribution.fTransform_isProbDist _ (Distribution.prod_isProbDist _ _ - (Distribution.pi_isProbDist fun _ => (Encryption.Real.law1 scheme).2) - (Distribution.pi_isProbDist fun _ => (Encryption.Real.law2 scheme).2))⟩ := by - rw [Encryption.Real.perPort, Encryption.Real.randomness, Resource.source, Resource.source, - parallel_ofAutomaton, Converter.ofProgram_smul_ofAutomaton] + Encryption.Real.perPort scheme (budget := q) = + TypedSystem.ofAutomaton (Encryption.perPort M C q) + (encryptionRealStep scheme (Encryption.Real.bound scheme * ∑ i, q i)) + ⟨Distribution.fTransform (fun ω => (none, ((ω.1, 0), (ω.2, 0)))) + (Distribution.prod + (tableLaw (Encryption.Real.law1 scheme) (Encryption.Real.bound scheme * ∑ i, q i)) + (tableLaw (Encryption.Real.law2 scheme) (Encryption.Real.bound scheme * ∑ i, q i))), + Distribution.fTransform_isProbDist _ (Distribution.prod_isProbDist _ _ + (Distribution.pi_isProbDist fun _ => (Encryption.Real.law1 scheme).2) + (Distribution.pi_isProbDist fun _ => (Encryption.Real.law2 scheme).2))⟩ := by + rw [Encryption.Real.perPort, Encryption.Real.randomness, TypedSystem.source, TypedSystem.source, + TypedSystem.parallel_ofAutomaton, TypedConverter.ofProgram_smul_ofAutomaton] congr 1 apply Subtype.ext dsimp only @@ -85,12 +86,12 @@ noncomputable abbrev ptxtStep {S : Type} lemma ptxt_smul {Ω S : Type} (q : AE.Port → ℕ) (step : S → (p : AE.Port) → AE.Input M C p → S × AE.Output M C p) (L : Distribution Ω) (hL : L.isProbDist) (init : Ω → S) : - AE.PTXT.perPort M C (budget := q) • Resource.ofAutomaton (AE.perPort M C q) step + AE.PTXT.perPort M C (budget := q) • TypedSystem.ofAutomaton (AE.perPort M C q) step ⟨Distribution.fTransform init L, Distribution.fTransform_isProbDist _ hL⟩ = - Resource.ofAutomaton (AE.perPort M C q) (ptxtStep step) + TypedSystem.ofAutomaton (AE.perPort M C q) (ptxtStep step) ⟨Distribution.fTransform (fun ω => (none, init ω)) L, Distribution.fTransform_isProbDist _ hL⟩ := by - rw [AE.PTXT.perPort, AE.PTXT.perPortProgram, Converter.ofPreservingProgram_smul_ofAutomaton] + rw [AE.PTXT.perPort, AE.PTXT.perPortProgram, TypedConverter.ofPreservingProgram_smul_ofAutomaton] congr 1 apply Subtype.ext dsimp only @@ -114,15 +115,16 @@ table of replacement messages. -/ lemma cca_smul {Ω S : Type} (q : AE.Port → ℕ) (step : S → (p : AE.Port) → AE.Input M C p → S × AE.Output M C p) (L : Distribution Ω) (hL : L.isProbDist) (init : Ω → S) : - AE.CCA.perPort M C (budget := q) • Resource.ofAutomaton (AE.perPort M C q) step + AE.CCA.perPort M C (budget := q) • TypedSystem.ofAutomaton (AE.perPort M C q) step ⟨Distribution.fTransform init L, Distribution.fTransform_isProbDist _ hL⟩ = - Resource.ofAutomaton (AE.perPort M C q) (ccaStep (AE.CCA.bound M C * ∑ i, q i) step) + TypedSystem.ofAutomaton (AE.perPort M C q) (ccaStep (AE.CCA.bound M C * ∑ i, q i) step) ⟨Distribution.fTransform (fun p => (none, (init p.1, (p.2, 0)))) (Distribution.prod L (tableLaw (AE.CCA.law1 M C) (AE.CCA.bound M C * ∑ i, q i))), Distribution.fTransform_isProbDist _ (Distribution.prod_isProbDist _ _ hL (Distribution.pi_isProbDist fun _ => (AE.CCA.law1 M C).2))⟩ := by - rw [AE.CCA.perPort, Interface.comp_smul, attach_rightContext, AE.CCA.randomness, Resource.source, - parallel_ofAutomaton, AE.CCA.perPortProgram, Converter.ofPreservingProgram_smul_ofAutomaton] + rw [AE.CCA.perPort, Interface.comp_smul, TypedConverter.attach_rightContext, AE.CCA.randomness, + TypedSystem.source, TypedSystem.parallel_ofAutomaton, AE.CCA.perPortProgram, + TypedConverter.ofPreservingProgram_smul_ofAutomaton] congr 1 apply Subtype.ext dsimp only @@ -143,16 +145,16 @@ lemma aeIdeal_smul {Ω S : Type} (q : AE.Port → ℕ) (step : S → (p : Encryption.Port) → Encryption.Input M p → S × Encryption.Output C p) (L : Distribution Ω) (hL : L.isProbDist) (init : Ω → S) : AE.Ideal.perPort M C (budget := q) • - Resource.ofAutomaton (Encryption.perPort M C (AE.Ideal.insideBudget M C q)) step + TypedSystem.ofAutomaton (Encryption.perPort M C (AE.Ideal.insideBudget M C q)) step ⟨Distribution.fTransform init L, Distribution.fTransform_isProbDist _ hL⟩ = - Resource.ofAutomaton (AE.perPort M C q) (aeIdealStep (AE.Ideal.bound M C * ∑ i, q i) step) + TypedSystem.ofAutomaton (AE.perPort M C q) (aeIdealStep (AE.Ideal.bound M C * ∑ i, q i) step) ⟨Distribution.fTransform (fun p => (none, (init p.1, (p.2, 0)))) (Distribution.prod L (tableLaw (AE.Ideal.law1 M C) (AE.Ideal.bound M C * ∑ i, q i))), Distribution.fTransform_isProbDist _ (Distribution.prod_isProbDist _ _ hL (Distribution.pi_isProbDist fun _ => (AE.Ideal.law1 M C).2))⟩ := by - rw [AE.Ideal.perPort, Interface.comp_smul, attach_rightContext, AE.Ideal.randomness, - Resource.source, parallel_ofAutomaton, AE.Ideal.perPortProgram, - Converter.ofPreservingProgram_smul_ofAutomaton] + rw [AE.Ideal.perPort, Interface.comp_smul, TypedConverter.attach_rightContext, + AE.Ideal.randomness, TypedSystem.source, TypedSystem.parallel_ofAutomaton, + AE.Ideal.perPortProgram, TypedConverter.ofPreservingProgram_smul_ofAutomaton] congr 1 apply Subtype.ext dsimp only @@ -217,7 +219,7 @@ lemma aeIdeal_system {Ω S : Type} {k : ℕ} variable (scheme : SymmetricEncryption K M C) (q : AE.Port → ℕ) /-- **The corrected hybrid** `ρ^ptxt ∘ ρ^cca ∘ ρ^ptxt ∘ ρ^cca` of the real system. -/ -noncomputable def Hybrid : Interface.Resource (AE.perPort M C q) := +noncomputable def Hybrid : TypedSystem (AE.perPort M C q) := AE.PTXT.perPort M C • AE.CCA.perPort M C • AE.PTXT.perPort M C • AE.CCA.perPort M C • AE.Real.perPort scheme @@ -246,7 +248,7 @@ lemma hybrid_mass (h : List ((Σ i, (AE.perPort M C q).X i) × (Σ i, (AE.perPor Replies (filterDom (AE.perPort M C q).domain (automatonSystem (oracleStep (hybridEncrypt scheme) (hybridDecrypt scheme)) (ω, []))) (h.map Prod.fst) (h.map Prod.snd) := by - rw [Hybrid, real_eq, cca_smul, ptxt_smul, cca_smul, ptxt_smul, Resource.ofAutomaton_mass, + rw [Hybrid, real_eq, cca_smul, ptxt_smul, cca_smul, ptxt_smul, TypedSystem.ofAutomaton_mass, Distribution.mass_fTransform] refine Distribution.mass_congr _ fun ω => ?_ dsimp only @@ -265,7 +267,7 @@ abbrev idealTableSize : ℕ := /-- **The ideal is the ideal oracle** on independent key, encryption and replacement tables. -/ lemma ideal_mass (h : List ((Σ i, (AE.perPort M C q).X i) × (Σ i, (AE.perPort M C q).Y i))) : (AE.Ideal.perPort M C (budget := q) • Encryption.Real.perPort scheme : - Interface.Resource (AE.perPort M C q)).1 h = + TypedSystem (AE.perPort M C q)).1 h = (Distribution.prod (Distribution.prod (tableLaw (AE.Real.law1 scheme) (idealTableSize scheme q)) (tableLaw (AE.Real.law2 scheme) (idealTableSize scheme q))) @@ -274,7 +276,7 @@ lemma ideal_mass (h : List ((Σ i, (AE.perPort M C q).X i) × (Σ i, (AE.perPort (automatonSystem (oracleStep (idealEncrypt scheme) (idealDecrypt (AE.Ideal.law1 M C) (realEncrypt scheme))) (ω, []))) (h.map Prod.fst) (h.map Prod.snd) := by - rw [encryptionReal_eq, aeIdeal_smul, Resource.ofAutomaton_mass, Distribution.mass_fTransform] + rw [encryptionReal_eq, aeIdeal_smul, TypedSystem.ofAutomaton_mass, Distribution.mass_fTransform] refine Distribution.mass_congr _ fun ω => ?_ dsimp only rw [aeIdeal_system (encryptionReal_system scheme ω.1) ω.2] diff --git a/src/Examples/AuthenticatedEncryption/Security.lean b/src/Examples/AuthenticatedEncryption/Security.lean index 4ee3dda..67c4193 100644 --- a/src/Examples/AuthenticatedEncryption/Security.lean +++ b/src/Examples/AuthenticatedEncryption/Security.lean @@ -48,7 +48,7 @@ local notation "⟦" "E_k" "," "D_k" "⟧" => AE.Real.perPort scheme (budget := /-- `⟦E$_k, D^⊥⟧ = ρ^ae(E_k)` for `k ← Gen`, at the budget `q` per port. -/ local notation "⟦" "E$_k" "," "D^⊥" "⟧" => - (AE.Ideal.perPort M C • Encryption.Real.perPort scheme : Interface.Resource (AE.perPort M C q)) + (AE.Ideal.perPort M C • Encryption.Real.perPort scheme : TypedSystem (AE.perPort M C q)) /-- **`(ind-cca, int-ptxt) → ae`, corrected** (Banfi, Theorem 2.3.10(4)). For the admitted distinguishers, which are closed under absorbing converters, `int-ptxt` within `εptxt` and @@ -58,17 +58,26 @@ theorem ae_of_ind_cca_int_ptxt [AdmissibleDistinguishers] (εptxt εcca : (AE.perPort M C q).inputDomain.DistinguisherBehavior → ENNReal) (ptxt : AE.INTPTXT scheme εptxt) (cca : AE.INDCCA scheme εcca) : AE.Secure scheme fun D => - εptxt D + εcca (absorb ρ^ptxt D) + εptxt (absorb (ρ^ptxt ≫ ρ^cca) D) + - εcca (absorb (ρ^ptxt ≫ ρ^cca ≫ ρ^ptxt) D) + + εptxt D + + εcca (D.absorb (AE.perPort M C q).nonempty_prefix (AE.perPort M C q).nonempty_prefix + ρ^ptxt) + + εptxt (D.absorb (AE.perPort M C q).nonempty_prefix (AE.perPort M C q).nonempty_prefix + (ρ^ptxt ≫ ρ^cca)) + + εcca (D.absorb (AE.perPort M C q).nonempty_prefix (AE.perPort M C q).nonempty_prefix + (ρ^ptxt ≫ ρ^cca ≫ ρ^ptxt)) + ((q .enc) ^ 2 / Fintype.card M : ℝ≥0) := by cc_calc mixed (distinguisherAdvantage AdmissibleDistinguishers.admissible) using (fun D _ R S => distinguisherAdvantage_le_distance _ D R S) ⟦E_k, D_k⟧ ≃[εptxt] ρ^ptxt • ⟦E_k, D_k⟧ := ptxt - _ ≃[εcca ∘ absorb ρ^ptxt] ρ^ptxt • ρ^cca • ⟦E_k, D_k⟧ := + _ ≃[fun D => εcca (D.absorb (AE.perPort M C q).nonempty_prefix + (AE.perPort M C q).nonempty_prefix ρ^ptxt)] ρ^ptxt • ρ^cca • ⟦E_k, D_k⟧ := AdmissibleDistinguishers.substitutesWithin_context ρ^ptxt cca - _ ≃[εptxt ∘ absorb (ρ^ptxt ≫ ρ^cca)] ρ^ptxt • ρ^cca • ρ^ptxt • ⟦E_k, D_k⟧ := + _ ≃[fun D => εptxt (D.absorb (AE.perPort M C q).nonempty_prefix + (AE.perPort M C q).nonempty_prefix (ρ^ptxt ≫ ρ^cca))] + ρ^ptxt • ρ^cca • ρ^ptxt • ⟦E_k, D_k⟧ := AdmissibleDistinguishers.substitutesWithin_context (ρ^ptxt ≫ ρ^cca) ptxt - _ ≃[εcca ∘ absorb (ρ^ptxt ≫ ρ^cca ≫ ρ^ptxt)] + _ ≃[fun D => εcca (D.absorb (AE.perPort M C q).nonempty_prefix + (AE.perPort M C q).nonempty_prefix (ρ^ptxt ≫ ρ^cca ≫ ρ^ptxt))] ρ^ptxt • ρ^cca • ρ^ptxt • ρ^cca • ⟦E_k, D_k⟧ := AdmissibleDistinguishers.substitutesWithin_context (ρ^ptxt ≫ ρ^cca ≫ ρ^ptxt) cca _ ≈[((q .enc) ^ 2 / Fintype.card M : ℝ≥0)] ⟦E$_k, D^⊥⟧ := @@ -82,7 +91,7 @@ inductive Assumption /-- The systems of each assumption, the pairs `AE.INDCCA.systems` and `AE.INTPTXT.systems`, indexed by Banfi's direction bit: `X_{i,false} = X₀` and `X_{i,true} = X₁`. -/ -noncomputable def assumptionSystems (i : Assumption) (b : Bool) : Resource (AE.perPort M C q) := +noncomputable def assumptionSystems (i : Assumption) (b : Bool) : TypedSystem (AE.perPort M C q) := let X := match i with | .cca => AE.INDCCA.systems scheme q | .ptxt => AE.INTPTXT.systems scheme q diff --git a/src/Examples/DSL/AEAD.lean b/src/Examples/DSL/AEAD.lean index 4f07f2f..ef95d86 100644 --- a/src/Examples/DSL/AEAD.lean +++ b/src/Examples/DSL/AEAD.lean @@ -64,7 +64,7 @@ system AESCTR ≔ CTR (2 ^ 36) • AES system AESPMAC ≔ PMAC authenticationBytes • AES system AuthenticatedEncryption ≔ EncryptThenMAC • (AESCTR ∥ AESPMAC) -/-- The combined converter uses two independently keyed AES resources. -/ +/-- The combined converter uses two independently keyed AES systems. -/ lemma authenticatedEncryption_eq (q : ℕ) : AuthenticatedEncryption (budget := q) = (EncryptThenMAC ≫ (CTR (2 ^ 36) ⊗ₘ PMAC authenticationBytes)) • (AES ∥ AES) := by diff --git a/src/Examples/DSL/AEADTests.lean b/src/Examples/DSL/AEADTests.lean index e2aeb2f..c6b5d02 100644 --- a/src/Examples/DSL/AEADTests.lean +++ b/src/Examples/DSL/AEADTests.lean @@ -34,8 +34,8 @@ lemma encrypt_transcript {q : ℕ} (hq : 1 ≤ q) (nonce : Nonce) ⟨⟨some (), .inr Tagging.Port.tag⟩, (nonce, ad, ciphertext)⟩), (⟨⟨some (), .inr Tagging.Port.tag⟩, tag⟩, ⟨⟨none, AEAD.Port.encrypt⟩, (ciphertext, tag)⟩)] = 1 := by - simp only [EncryptThenMAC, EncryptThenMAC.program, Interface.Converter.ofProgram, - Interface.ofDDC_apply] + simp only [EncryptThenMAC, EncryptThenMAC.program, TypedConverter.ofProgram, + TypedConverter.ofDDC_apply] rw [if_pos] refine ⟨rfl, fun k hk _ => ?_⟩ simp only [List.map_cons, List.map_nil, List.length_cons, List.length_nil] at hk @@ -54,8 +54,8 @@ lemma decrypt_transcript {q : ℕ} (hq : 1 ≤ q) (nonce : Nonce) ⟨⟨some (), .inl StreamCipher.Port.crypt⟩, (nonce, ciphertext)⟩), (⟨⟨some (), .inl StreamCipher.Port.crypt⟩, message⟩, ⟨⟨none, AEAD.Port.decrypt⟩, some message⟩)] = 1 := by - simp only [EncryptThenMAC, EncryptThenMAC.program, Interface.Converter.ofProgram, - Interface.ofDDC_apply] + simp only [EncryptThenMAC, EncryptThenMAC.program, TypedConverter.ofProgram, + TypedConverter.ofDDC_apply] rw [if_pos] refine ⟨rfl, fun k hk _ => ?_⟩ simp only [List.map_cons, List.map_nil, List.length_cons, List.length_nil] at hk @@ -72,8 +72,8 @@ lemma decrypt_rejects {q : ℕ} (hq : 1 ≤ q) (nonce : Nonce) (ad ciphertext : ⟨⟨some (), .inr Tagging.Port.verify⟩, ((nonce, ad, ciphertext), tag)⟩), (⟨⟨some (), .inr Tagging.Port.verify⟩, false⟩, ⟨⟨none, AEAD.Port.decrypt⟩, none⟩)] = 1 := by - simp only [EncryptThenMAC, EncryptThenMAC.program, Interface.Converter.ofProgram, - Interface.ofDDC_apply] + simp only [EncryptThenMAC, EncryptThenMAC.program, TypedConverter.ofProgram, + TypedConverter.ofDDC_apply] rw [if_pos] refine ⟨rfl, fun k hk _ => ?_⟩ simp only [List.map_cons, List.map_nil, List.length_cons, List.length_nil] at hk diff --git a/src/Examples/DSL/AES.lean b/src/Examples/DSL/AES.lean index 49da64e..20e633f 100644 --- a/src/Examples/DSL/AES.lean +++ b/src/Examples/DSL/AES.lean @@ -8,7 +8,7 @@ import Commons.Schemes.BlockCipher.AES AES-256 as a system with a random key, and converters around it: whitening, double encryption, a fresh mask, CBC-MAC over a finite message space, and a two-key cascade; at per-port budgets, whitening and the fresh mask are endomorphisms of the interface of a block function. Whitened AES -beside an unrelated resource, and a two-step hybrid bound through an ideal block cipher. The block +beside an unrelated system, and a two-step hybrid bound through an ideal block cipher. The block cipher is AES-256 of `Commons.Schemes.BlockCipher.AES`, answering at the interface `Evaluation` of `Commons.Definitions.Ideal`, on blocks of sixteen bytes with bytewise exclusive or. -/ @@ -91,11 +91,11 @@ system ParallelAES ≔ (Twice ⊗ₘ Twice) • (AES ∥ AES) /-- At per-port budgets, port-preserving converters are endomorphisms of the block-cipher interface: they compose and attach without changing the budget. -/ noncomputable def WhitenedMaskedAES (mask : Block) (q : Evaluation.Port → ℕ) : - Interface.Resource (Evaluation.perPort Block Block q) := + TypedSystem (Evaluation.perPort Block Block q) := (Whitening.perPort mask ≫ RandomMask.perPort) • AES.perPort /-- The same converter accepts messages with different block counts. -/ -noncomputable example (q : ℕ) : Interface.Resource (Authentication (Bool × Block × Block) q) := +noncomputable example (q : ℕ) : TypedSystem (Authentication (Bool × Block × Block) q) := CBCMAC (fun (long, first, second) => if long then [first, second] else [first]) lemma composedAES_eq (mask : Block) (q : ℕ) : @@ -108,12 +108,12 @@ lemma parallelAES_eq (q : ℕ) : ParallelAES (budget := q) = DoubleAES ∥ Doubl cc_normalize lemma cbc_nonexpanding (blockForm : M → List Block) {q : ℕ} - (R S : Interface.Resource (Evaluation Block Block (CBC.bound blockForm * q))) : + (R S : TypedSystem (Evaluation Block Block (CBC.bound blockForm * q))) : Δ (CBC blockForm • R) (CBC blockForm • S) ≤ Δ R S := by cc_nonexpand -/-- Parallel components keep their own alphabets: whitening AES beside an unrelated resource -leaves that resource unchanged. -/ +/-- Parallel components keep their own alphabets: whitening AES beside an unrelated system +leaves that system unchanged. -/ lemma whitening_beside_switch (mask : Block) (q n : ℕ) : (Whitening mask (budget := q) ⊗ₘ 𝟙 (Control n)) • (AES ∥ Switch) = (Whitening mask • AES) ∥ Switch := by @@ -122,7 +122,7 @@ lemma whitening_beside_switch (mask : Block) (q n : ℕ) : /-- A two-step hybrid: a bound on distinguishing AES from an ideal block cipher `R`, and a bound on the ideal system, give a bound on the real system. -/ lemma aes_hybrid {A : Interface} {q : ℕ} (α : A ⟶ Evaluation Block Block q) - (R : Interface.Resource (Evaluation Block Block q)) (V : Interface.Resource A) (ε δ : ENNReal) + (R : TypedSystem (Evaluation Block Block q)) (V : TypedSystem A) (ε δ : ENNReal) (aesBound : Δ AES R ≤ ε) (idealBound : Δ (α • R) V ≤ δ) : Δ (α • AES) V ≤ ε + δ := by calc diff --git a/src/Examples/Games.lean b/src/Examples/Games.lean index 0896dd6..8e9ca04 100644 --- a/src/Examples/Games.lean +++ b/src/Examples/Games.lean @@ -16,7 +16,7 @@ construction attached (`advantage_attach_le_win`). On interfaces, the collision game of authenticated encryption is the game the collision discrete game presents (`collision`): the hybrid oracle with the MBO the collision so far. Its -visible resource is the hybrid, it is conditionally equivalent to the ideal system, and every +visible typed system is the hybrid, it is conditionally equivalent to the ideal system, and every winner wins it with probability at most `q_e² / |M|`. Every solver's advantage between the hybrid and the ideal is then at most `q_e² / |M|` (`hybrid_ideal_advantage_le`), also inside any construction (`attach_hybrid_ideal_advantage_le`). @@ -146,19 +146,19 @@ variable {K M C : Type} [Fintype K] [Fintype M] [Fintype C] [DecidableEq K] [Dec /-- **The collision game** on the authenticated-encryption interface: the game the collision discrete game presents, the hybrid oracle with the MBO the collision between the original messages so far and the outer replacement messages. -/ -noncomputable def collision : Interface.Game (AE.perPort M C q) := - Interface.Game.ofPDG (collisionGame scheme q) (collisionGame_isProbDist scheme q) +noncomputable def collision : TypedGame (AE.perPort M C q) := + TypedGame.ofPDG (collisionGame scheme q) (collisionGame_isProbDist scheme q) (hybrid_visible scheme q) -/-- The visible resource of the collision game is the hybrid. -/ +/-- The visible typed system of the collision game is the hybrid. -/ lemma collision_visible : DistinctionGames.visible (collision scheme q) = Hybrid scheme q := - Interface.Game.visible_ofPDG _ _ _ + TypedGame.visible_ofPDG _ _ _ /-- The collision game is conditionally equivalent to the ideal system. -/ lemma collision_conditionallyEquivalent : DistinctionGames.ConditionallyEquivalent (collision scheme q) (AE.Ideal.perPort M C (budget := q) • Encryption.Real.perPort scheme : - Interface.Resource (AE.perPort M C q)) := + TypedSystem (AE.perPort M C q)) := collisionGame_conditionallyEquivalent scheme q /-- **Every winner wins the collision game with probability at most `q_e² / |M|`.** -/ @@ -179,8 +179,8 @@ theorem collision_win_le {w} (hw : w ∈ Games.winners (AE.perPort M C q)) : exact P.winProbability_le_of_unsetProbability (PDG.repliesAtQueriedInterface_behavior _ (hybrid_visible scheme q ▸ (Hybrid scheme q).2)) (AE.Ideal.perPort M C (budget := q) • Encryption.Real.perPort scheme : - Interface.Resource (AE.perPort M C q)).2 (PDG.monotoneMBO_behavior _) - ((Interface.Game.conditionallyEquivalent_ofPDG_iff _ _ (hybrid_visible scheme q) _).mp + TypedSystem (AE.perPort M C q)).2 (PDG.monotoneMBO_behavior _) + ((Interface.conditionallyEquivalent_ofPDG_iff _ _ (hybrid_visible scheme q) _).mp (collisionGame_conditionallyEquivalent scheme q)) (PDG.one_sub_le_unsetProbability_behavior _ (AE.perPort M C q).nonempty_prefix (collisionGame_badProbability_le scheme q)) @@ -189,9 +189,9 @@ theorem collision_win_le {w} (hw : w ∈ Games.winners (AE.perPort M C q)) : and the ideal is at most `q_e² / |M|`. -/ theorem hybrid_ideal_advantage_le {s} (hs : s ∈ DistinctionGames.solvers (AE.perPort M C q)) : |s.1 (Hybrid scheme q) - s.1 (AE.Ideal.perPort M C (budget := q) • - Encryption.Real.perPort scheme : Interface.Resource (AE.perPort M C q))| ≤ + Encryption.Real.perPort scheme : TypedSystem (AE.perPort M C q))| ≤ (q .enc : ℝ) ^ 2 / Fintype.card M := by - -- The hybrid is the visible resource `G⁻` of the collision game `G`. + -- The hybrid is the visible typed system `G⁻` of the collision game `G`. rw [← collision_visible] -- With `Ideal` the ideal system `AE.Ideal.perPort M C • Encryption.Real.perPort scheme`: -- @@ -209,9 +209,9 @@ construction on the hybrid and on the ideal is at most `q_e² / |M|`. -/ theorem attach_hybrid_ideal_advantage_le {B : Interface} (α : B ⟶ AE.perPort M C q) {s} (hs : s ∈ DistinctionGames.solvers B) : |s.1 (α • Hybrid scheme q) - s.1 (α • (AE.Ideal.perPort M C (budget := q) • - Encryption.Real.perPort scheme : Interface.Resource (AE.perPort M C q)))| ≤ + Encryption.Real.perPort scheme : TypedSystem (AE.perPort M C q)))| ≤ (q .enc : ℝ) ^ 2 / Fintype.card M := by - -- The hybrid is the visible resource `G⁻` of the collision game `G`. + -- The hybrid is the visible typed system `G⁻` of the collision game `G`. rw [← collision_visible] -- The game hop inside the construction `α` (`advantage_attach_le`), with the bound on -- winning `G` by every solver on `AE.perPort M C q` (`collision_win_le`): diff --git a/src/Examples/PRGLengthExtension.lean b/src/Examples/PRGLengthExtension.lean index 91d53b6..c3e7519 100644 --- a/src/Examples/PRGLengthExtension.lean +++ b/src/Examples/PRGLengthExtension.lean @@ -16,7 +16,7 @@ samples [2, Example 3.2, p. 56], the memoryless source `MemorylessSource 𝒰[R] Every system of the proof is a memoryless source [2, Definition 3.1, p. 55], and the calling programs `𝓡₁` and `𝓡₂` of the two swaps map memoryless sources to memoryless sources, with the -law of one invocation (the composition laws `Interface.Converter.*_smul_memoryless`). So each +law of one invocation (the composition laws `TypedConverter.*_smul_memoryless`). So each hop is an equality of the laws of one reply: ``` @@ -105,9 +105,10 @@ lemma prgReal_eq_source [Nonempty S] (G : S → R) : -- of one invocation of the program. have real : (PRGReal.perPort G (budget := q)).1 = memoryless _ (portLaw fun _ _ => ProbDist.map G 𝒰[S]) := by - -- The composition law `Converter.ofProgram_smul_memoryless`, with the source of seeds - -- memoryless (`source_eq_memoryless`); the law of one invocation remains. - refine Converter.ofProgram_smul_memoryless none _ _ _ (source_eq_memoryless _ _) ?_ + -- The composition law `TypedConverter.ofProgram_smul_memoryless`, with the source of seeds + -- memoryless (`TypedSystem.source_eq_memoryless`); the law of one invocation remains. + refine TypedConverter.ofProgram_smul_memoryless none _ _ _ + (TypedSystem.source_eq_memoryless _ _) ?_ -- One invocation: draw `s ← 𝒰[S]`, reply `G s`; the same in both initialization states. -- The cases: initialization state `none` or `some ()`, the port `eval`, the input `()`. rintro (_ | ⟨⟩) ⟨⟩ ⟨⟩ @@ -135,7 +136,7 @@ lemma 𝓡₁_smul_source (G : S → S × S) (ν : ProbDist (S × S)) : unfold 𝓡₁.perPort 𝓡₁.perPortProgram -- The composition law for port-preserving programs, with the source of `ν` memoryless -- (`MemorylessSource.memoryless_eq`); the law of one invocation remains. - refine Converter.ofPreservingProgram_smul_memoryless none _ _ _ _ _ _ _ + refine TypedConverter.ofPreservingProgram_smul_memoryless none _ _ _ _ _ _ _ (MemorylessSource.memoryless_eq ν _) ?_ -- The law of one invocation: one call, answered `(a, b) ← ν`, reply `(a, G b)`. -- The cases: initialization state `none` or `some ()`, the port `eval`, the input `()`. @@ -164,10 +165,10 @@ lemma 𝓡₂_smul_source [Nonempty S] (ν : ProbDist (S × S)) : unfold 𝓡₂.perPort 𝓡₂.perPortProgram 𝓡₂.randomness -- The composition law with the converter's own source beside its inside interface: the -- source of `ν` and the source of the `a`'s are memoryless (`MemorylessSource.memoryless_eq`, - -- `source_eq_memoryless`); the law of one invocation against their side-by-side laws - -- remains. - refine Converter.ofPreservingProgram_comp_rightContext_smul_memoryless none _ _ _ _ _ _ _ - (MemorylessSource.memoryless_eq ν _) (source_eq_memoryless _ _) ?_ + -- `TypedSystem.source_eq_memoryless`); the law of one invocation against their side-by-side + -- laws remains. + refine TypedConverter.ofPreservingProgram_comp_rightContext_smul_memoryless none _ _ _ _ _ _ _ + (MemorylessSource.memoryless_eq ν _) (TypedSystem.source_eq_memoryless _ _) ?_ -- The law of one invocation: `a` from its own source, `(c, d)` from the source of `ν`, -- reply `(a, c, d)`: the product of the two laws. -- The cases: initialization state `none` or `some ()`, the port `eval`, the input `()`. @@ -252,7 +253,10 @@ theorem prg_length_extension [AdmissibleDistinguishers] (G : S → S × S) → ENNReal) (secure : PRGSamples G ε) : PRGSamples (H G) (q := q) fun D => - ε (absorb (𝓡₁.perPort G) D) + ε (absorb (𝓡₂.perPort S) D) := by + ε (D.absorb (Evaluation.perPort Unit (S × S) (𝓡₁.insideBudget G q)).nonempty_prefix + (Evaluation.perPort Unit (S × S × S) q).nonempty_prefix (𝓡₁.perPort G)) + + ε (D.absorb (Evaluation.perPort Unit (S × S) (𝓡₂.insideBudget S q)).nonempty_prefix + (Evaluation.perPort Unit (S × S × S) q).nonempty_prefix (𝓡₂.perPort S)) := by -- The hybrids, as systems (the distinguisher D on the left): -- -- D ─ prg-real^H start @@ -269,13 +273,15 @@ theorem prg_length_extension [AdmissibleDistinguishers] (G : S → S × S) PRGReal.perPort (H G) = 𝓡₁.perPort G • PRGReal.perPort G := prgReal_H_eq G q -- The first swap: `prg-real^G` ≃ `prg-rand` (`secure`), attached through `𝓡₁`; its loss is -- `ε` at `D` with `𝓡₁` absorbed (`substitutesWithin_attach`). - _ ≃[fun D => ε (absorb (𝓡₁.perPort G) D)] + _ ≃[fun D => ε (D.absorb (Evaluation.perPort Unit (S × S) (𝓡₁.insideBudget G q)).nonempty_prefix + (Evaluation.perPort Unit (S × S × S) q).nonempty_prefix (𝓡₁.perPort G))] 𝓡₁.perPort G • MemorylessSource.perPort (S × S) 𝒰[S × S] := AdmissibleDistinguishers.substitutesWithin_attach _ secure -- The middle hop: both are the memoryless source of `𝒰[S] ⊗ G_* 𝒰[S]`. _ = 𝓡₂.perPort S • PRGReal.perPort G := 𝓡₁_smul_prgRand G q -- The second swap, through `𝓡₂`; its loss is `ε` at `D` with `𝓡₂` absorbed. - _ ≃[fun D => ε (absorb (𝓡₂.perPort S) D)] + _ ≃[fun D => ε (D.absorb (Evaluation.perPort Unit (S × S) (𝓡₂.insideBudget S q)).nonempty_prefix + (Evaluation.perPort Unit (S × S × S) q).nonempty_prefix (𝓡₂.perPort S))] 𝓡₂.perPort S • MemorylessSource.perPort (S × S) 𝒰[S × S] := AdmissibleDistinguishers.substitutesWithin_attach _ secure -- The last hop: both are the memoryless source of `𝒰[S × S × S]`. diff --git a/src/Examples/Substitution.lean b/src/Examples/Substitution.lean index 78ef941..5ed4d6d 100644 --- a/src/Examples/Substitution.lean +++ b/src/Examples/Substitution.lean @@ -6,7 +6,7 @@ import ConstructiveCryptography.Tactics.Substitution # Substitutions on interfaces A single substitution establishes a construction `{R} —[π]→ …`, and the context rules of the -relaxation add an independent resource on either side (Jost, §2.2.2 and Proposition 2.2.3). +relaxation add an independent typed system on either side (Jost, §2.2.2 and Proposition 2.2.3). Constant converters supply the diagonal of the unrestricted converter class; a restricted class needs its own closure under the two contexts. A calculation of statistical substitutions `≈[ε]` joined by exact equalities gives an approximate construction `{R} —[π; ε]→ …`. @@ -30,19 +30,19 @@ open SystemAlgebra SystemAlgebra.Substitution open scoped SystemAlgebra /-- Constant converters supply the diagonal of the unrestricted converter class. -/ -lemma unrestricted_diagonal {B : Interface} (left right : Interface.Resource B) - (A : Interface) (resource : Interface.Resource A) : +lemma unrestricted_diagonal {B : Interface} (left right : TypedSystem B) + (A : Interface) (R : TypedSystem A) : ∃ transformation ∈ (Set.univ : Set (A ⟶ B)), - transformation • left = resource ∧ transformation • right = resource := - ⟨Interface.constant resource B, Set.mem_univ _, - Interface.attach_constant resource left, Interface.attach_constant resource right⟩ + transformation • left = R ∧ transformation • right = R := + ⟨TypedConverter.constant R B, Set.mem_univ _, + TypedConverter.attach_constant R left, TypedConverter.attach_constant R right⟩ /-- **A single substitution with a right context**: the substitution of `right` for `left` -through `transformation` constructs the simulated ideal, and an independent resource on the +through `transformation` constructs the simulated ideal, and an independent typed system on the right is carried along. -/ theorem construction_with_right_context {A B C D E : Interface} - (left right : Interface.Resource B) (protocol : A ⟶ D) (simulator : A ⟶ E) - (real : Interface.Resource D) (ideal : Interface.Resource E) (context : Interface.Resource C) + (left right : TypedSystem B) (protocol : A ⟶ D) (simulator : A ⟶ E) + (real : TypedSystem D) (ideal : TypedSystem E) (context : TypedSystem C) (transformation : A ⟶ B) (realEq : protocol • real = transformation • left) (idealEq : transformation • right = simulator • ideal) : @@ -68,8 +68,8 @@ theorem construction_with_right_context {A B C D E : Interface} /-- **A single substitution with a left context**, in the other order. -/ theorem construction_with_left_context {A B C D E : Interface} - (left right : Interface.Resource B) (protocol : A ⟶ D) (simulator : A ⟶ E) - (real : Interface.Resource D) (ideal : Interface.Resource E) (context : Interface.Resource C) + (left right : TypedSystem B) (protocol : A ⟶ D) (simulator : A ⟶ E) + (real : TypedSystem D) (ideal : TypedSystem E) (context : TypedSystem C) (transformation : A ⟶ B) (realEq : protocol • real = transformation • left) (idealEq : transformation • right = simulator • ideal) : @@ -96,16 +96,16 @@ theorem construction_with_left_context {A B C D E : Interface} /-- A restricted class is compatible with parallel composition once it is closed under both contexts; membership of the composed converter is not automatic. -/ example {D : Interface} (transformations : ∀ A : Interface, Set (A ⟶ D)) - (left right : Interface.Resource D) - (diagonal : ∀ A (resource : Interface.Resource A), + (left right : TypedSystem D) + (diagonal : ∀ A (R : TypedSystem A), ∃ transformation ∈ transformations A, - transformation • left = resource ∧ transformation • right = resource) - (rightClosed : ∀ (A B : Interface) (context : Interface.Resource B) + transformation • left = R ∧ transformation • right = R) + (rightClosed : ∀ (A B : Interface) (context : TypedSystem B) (transformation : A ⟶ D), transformation ∈ transformations A → - Interface.rightContext A context ≫ transformation ∈ transformations (A ⊗ B)) - (leftClosed : ∀ (A B : Interface) (context : Interface.Resource A) + TypedConverter.rightContext A context ≫ transformation ∈ transformations (A ⊗ B)) + (leftClosed : ∀ (A B : Interface) (context : TypedSystem A) (transformation : B ⟶ D), transformation ∈ transformations B → - Interface.leftContext context B ≫ transformation ∈ transformations (A ⊗ B)) : + TypedConverter.leftContext context B ≫ transformation ∈ transformations (A ⊗ B)) : Specification.Relaxation.ParallelCompatible (fun A => Specification.singleSubstitutionRelaxation (transformations A) left right (diagonal A)) := by @@ -119,7 +119,7 @@ example {D : Interface} (transformations : ∀ A : Interface, Set (A ⟶ D)) protocol, a join, `H'` by `S'` through a transformation, and a join to the simulated ideal. -/ theorem constructsWithin_of_two_substitutions {A B D E : Interface} (protocol : A ⟶ B) (transformation : A ⟶ D) (simulator : A ⟶ E) - (R H : Interface.Resource B) (H' S' : Interface.Resource D) (ideal : Interface.Resource E) + (R H : TypedSystem B) (H' S' : TypedSystem D) (ideal : TypedSystem E) (ε₁ ε₂ : ENNReal) (first : Δ R H ≤ ε₁) (join : protocol • H = transformation • H') (second : Δ H' S' ≤ ε₂) (finish : transformation • S' = simulator • ideal) : {R} —[protocol; ε₁ + ε₂]→ {simulator • ideal} := by diff --git a/src/Examples/Usability.lean b/src/Examples/Usability.lean index d536eef..56c1427 100644 --- a/src/Examples/Usability.lean +++ b/src/Examples/Usability.lean @@ -16,63 +16,63 @@ open scoped SystemAlgebra variable {A B C : Interface} -example (α : A ⟶ B) (β : B ⟶ C) (R : Resource C) : +example (α : A ⟶ B) (β : B ⟶ C) (R : TypedSystem C) : (α ≫ β) • R = α • (β • R) := by cc_normalize -example (R : Resource A) : (𝟙 A • R : Resource A) = R := by +example (R : TypedSystem A) : (𝟙 A • R : TypedSystem A) = R := by cc_normalize example {D : Interface} (α : A ⟶ B) (β : C ⟶ D) - (R : Resource B) (S : Resource D) : + (R : TypedSystem B) (S : TypedSystem D) : (α ⊗ₘ β) • (R ∥ S) = (α • R) ∥ (β • S) := by cc_normalize example {D : Interface} (α : A ⟶ B) (β : C ⟶ D) - (R : Resource B) (S : Resource D) : - ((α ⊗ₘ β) • (R ∥ S) : Resource (tensor A C)) = (α • R) ∥ (β • S) := by + (R : TypedSystem B) (S : TypedSystem D) : + ((α ⊗ₘ β) • (R ∥ S) : TypedSystem (tensor A C)) = (α • R) ∥ (β • S) := by cc_normalize example {D E : Interface} (γ : E ⟶ tensor A C) (α : A ⟶ B) (β : C ⟶ D) - (R : Resource B) (S : Resource D) : + (R : TypedSystem B) (S : TypedSystem D) : (γ ≫ (α ⊗ₘ β)) • (R ∥ S) = γ • ((α • R) ∥ (β • S)) := by cc_normalize -example (α : A ⟶ B) (R S : Resource B) : Δ (α • R) (α • S) ≤ Δ R S := by +example (α : A ⟶ B) (R S : TypedSystem B) : Δ (α • R) (α • S) ≤ Δ R S := by cc_nonexpand -example (R S T : Resource A) : Δ R S ≤ Δ R T + Δ T S := by +example (R S T : TypedSystem A) : Δ R S ≤ Δ R T + Δ T S := by cc_triangle via T · exact le_rfl · exact le_rfl -example (α : A ⟶ B) (β : A ⟶ B) (R S : Resource B) : +example (α : A ⟶ B) (β : A ⟶ B) (R S : TypedSystem B) : Δ (α • R) (β • S) ≤ Δ R S + Δ (α • S) (β • S) := by cc_triangle via (α • S) · cc_nonexpand · exact le_rfl -example (R S : Resource A) (T : Resource B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := by +example (R S : TypedSystem A) (T : TypedSystem B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := by cc_nonexpand -example (R : Resource A) (S T : Resource B) : Δ (R ∥ S) (R ∥ T) ≤ Δ S T := by +example (R : TypedSystem A) (S T : TypedSystem B) : Δ (R ∥ S) (R ∥ T) ≤ Δ S T := by cc_nonexpand -example (R S : Resource A) (T U : Resource B) : +example (R S : TypedSystem A) (T U : TypedSystem B) : Δ (R ∥ T) (S ∥ U) ≤ Δ R S + Δ T U := by cc_nonexpand -example (R S : Resource A) (h : Δ R S ≤ 0) : Δ R S ≤ 0 := by +example (R S : TypedSystem A) (h : Δ R S ≤ 0) : Δ R S ≤ 0 := by fail_if_success cc_nonexpand exact h /-- trace: [ConstructiveCryptography.ProofAutomation.rule] ConstructiveCryptography.CryptographicAlgebra.distance_parallel_left_le -/ #guard_msgs in set_option trace.ConstructiveCryptography.ProofAutomation.rule true in -example (R S : Resource A) (T : Resource B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := by +example (R S : TypedSystem A) (T : TypedSystem B) : Δ (R ∥ T) (S ∥ T) ≤ Δ R S := by cc_nonexpand -example (α : A ⟶ B) (R : Resource B) : +example (α : A ⟶ B) (R : TypedSystem B) : ({R} —[α]→ {α • R}) := by cc_construct using rfl diff --git a/src/RandomSystems.lean b/src/RandomSystems.lean index 828d014..76532bb 100644 --- a/src/RandomSystems.lean +++ b/src/RandomSystems.lean @@ -54,9 +54,33 @@ import RandomSystems.System.Memoryless import RandomSystems.System.Observation import RandomSystems.System.ProbAutomaton import RandomSystems.System.Replies +import RandomSystems.Typed.Automaton +import RandomSystems.Typed.Context +import RandomSystems.Typed.ConverterCoherence +import RandomSystems.Typed.DDCCoherence +import RandomSystems.Typed.DSL.Converters +import RandomSystems.Typed.DSL.Probability +import RandomSystems.Typed.DSL.Programs +import RandomSystems.Typed.DSL.Syntax +import RandomSystems.Typed.DSL.Tactics +import RandomSystems.Typed.Filter +import RandomSystems.Typed.Functional +import RandomSystems.Typed.Game +import RandomSystems.Typed.Interface +import RandomSystems.Typed.InterfaceCoherence +import RandomSystems.Typed.Memoryless +import RandomSystems.Typed.Parallel +import RandomSystems.Typed.ParallelAttachment +import RandomSystems.Typed.PresentedGame +import RandomSystems.Typed.Relabel +import RandomSystems.Typed.Source +import RandomSystems.Typed.SystemCoherence +import RandomSystems.Typed.SystemParallel +import RandomSystems.Typed.TensorRename /-! Random systems: raw systems and connection, deterministic converters, PDSs, cumulative random systems, probabilistic automata and memoryless systems, converters and attachment, parallel -composition, distance and games. +composition, distance and games; typed systems and typed converters on interfaces, and the +programs and converters of the component DSL. -/ diff --git a/src/ConstructiveCryptography/Automaton.lean b/src/RandomSystems/Typed/Automaton.lean similarity index 55% rename from src/ConstructiveCryptography/Automaton.lean rename to src/RandomSystems/Typed/Automaton.lean index de9f5f3..2c01fc0 100644 --- a/src/ConstructiveCryptography/Automaton.lean +++ b/src/RandomSystems/Typed/Automaton.lean @@ -1,35 +1,35 @@ -import ConstructiveCryptography.ResourceParallel +import RandomSystems.Typed.SystemParallel /-! -# Automata as resources +# Automata as typed systems -An automaton whose initial state is sampled from a law is a resource: the behavior of its +An automaton whose initial state is sampled from a law is a typed system: the behavior of its deterministic systems on the interface's domain, one for each initial state (Maurer 2002, Definition 2, with the randomness in the initial state). Parallel composition runs two such automata side by side from independent initial states. ## Main definitions -* `Interface.automatonDDS T step s`: the deterministic resource of the automaton started in `s` -* `Interface.Resource.ofAutomaton T step initial`: the automaton with initial state sampled - from `initial` +* `Interface.automatonDDS T step s`: the deterministic system of the automaton started in `s` +* `TypedSystem.ofAutomaton T step initial`: the automaton with initial state sampled from + `initial` ## Main results -* `Interface.Resource.ofAutomaton_mass`: a transcript has the mass of the initial states from - which the automaton gives it -* `Interface.parallel_ofAutomaton`: parallel automata are the automaton running both side by +* `TypedSystem.ofAutomaton_mass`: a transcript has the mass of the initial states from which + the automaton gives it +* `TypedSystem.parallel_ofAutomaton`: parallel automata are the automaton running both side by side -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra -open Probability +open Probability Interface variable {S : Type} (T : Interface) (step : S → (i : T.I) → T.X i → S × T.Y i) -/-- The deterministic resource of the automaton started in `s`, on `T`'s domain. -/ -noncomputable def automatonDDS (s : S) : {r : InterfaceSystem T.I T.X T.Y // +/-- The deterministic system of the automaton started in `s`, on `T`'s domain. -/ +noncomputable def Interface.automatonDDS (s : S) : {r : InterfaceSystem T.I T.X T.Y // IsDDS r ∧ RepliesAtQueriedInterface r ∧ ∀ h, (r h).Dom ↔ T.domain h} := ⟨filterDom T.domain (automatonSystem step s), (automatonSystem_isDDS step s).filterDom _ T.nonempty_prefix.2, @@ -38,15 +38,15 @@ noncomputable def automatonDDS (s : S) : {r : InterfaceSystem T.I T.X T.Y // rw [filterDom_dom, automatonSystem_dom] exact ⟨fun hd => hd.1, fun hd => ⟨hd, fun he => T.nonempty_prefix.1 (he ▸ hd)⟩⟩⟩ -/-- **The resource of an automaton** with its initial state sampled from `initial`. -/ -noncomputable def Resource.ofAutomaton (initial : Distribution.ProbDist S) : Resource T := - Resource.ofPDS ⟨Distribution.fTransform (automatonDDS T step) initial.1, +/-- **The typed system of an automaton** with its initial state sampled from `initial`. -/ +noncomputable def TypedSystem.ofAutomaton (initial : Distribution.ProbDist S) : TypedSystem T := + TypedSystem.ofPDS ⟨Distribution.fTransform (automatonDDS T step) initial.1, Distribution.fTransform_isProbDist _ initial.2⟩ /-- A transcript has the mass of the initial states from which the automaton gives it. -/ -lemma Resource.ofAutomaton_mass (initial : Distribution.ProbDist S) +lemma TypedSystem.ofAutomaton_mass (initial : Distribution.ProbDist S) (h : List ((Σ i, T.X i) × (Σ i, T.Y i))) : - (Resource.ofAutomaton T step initial).1 h = initial.1.mass fun s => + (TypedSystem.ofAutomaton T step initial).1 h = initial.1.mass fun s => Replies (filterDom T.domain (automatonSystem step s)) (h.map Prod.fst) (h.map Prod.snd) := by change behaviorMass _ _ _ = _ rw [behaviorMass, Distribution.mass_fTransform] @@ -54,11 +54,11 @@ lemma Resource.ofAutomaton_mass (initial : Distribution.ProbDist S) /-- **Parallel automata** are the automaton running both side by side from independent initial states. -/ -lemma parallel_ofAutomaton {A B : Interface} {S T : Type} +lemma TypedSystem.parallel_ofAutomaton {A B : Interface} {S T : Type} (f : S → (i : A.I) → A.X i → S × A.Y i) (g : T → (j : B.I) → B.X j → T × B.Y j) (P : Distribution.ProbDist S) (Q : Distribution.ProbDist T) : - parallel (Resource.ofAutomaton A f P) (Resource.ofAutomaton B g Q) = - Resource.ofAutomaton (tensor A B) (parallelStep f g) + parallel (ofAutomaton A f P) (ofAutomaton B g Q) = + ofAutomaton (tensor A B) (parallelStep f g) ⟨Distribution.prod P.1 Q.1, Distribution.prod_isProbDist _ _ P.2 Q.2⟩ := by apply Subtype.ext apply RandomSystem.ext @@ -66,9 +66,9 @@ lemma parallel_ofAutomaton {A B : Interface} {S T : Type} rw [parallel_mass_of_presentations _ _ P.1 Q.1 (fun s => filterDom A.domain (automatonSystem f s)) (fun t => filterDom B.domain (automatonSystem g t)) - (Resource.ofAutomaton_mass A f P) (Resource.ofAutomaton_mass B g Q), - Resource.ofAutomaton_mass] + (ofAutomaton_mass A f P) (ofAutomaton_mass B g Q), + ofAutomaton_mass] refine Distribution.mass_congr _ fun st => ?_ rw [parallel_automatonSystem f g A.nonempty_prefix B.nonempty_prefix] -end SystemAlgebra.Interface +end SystemAlgebra diff --git a/src/RandomSystems/Typed/Context.lean b/src/RandomSystems/Typed/Context.lean new file mode 100644 index 0000000..4cf355d --- /dev/null +++ b/src/RandomSystems/Typed/Context.lean @@ -0,0 +1,134 @@ +import RandomSystems.Typed.ParallelAttachment +import RandomSystems.Typed.SystemCoherence +import RandomSystems.Converter.EmptyInterface + +/-! +# Fixed contexts + +A typed system `R` on `A` is a typed converter from `A` to the unit interface (`ofSystem`): +the PDC of the DDC readings (`resourcePDC`) of the deterministic systems presenting `R`. +Attaching it to the unit system gives `R`. In parallel with the identity it gives the fixed +contexts: attaching `rightContext A S` to `R` is `R ∥ S`, and so is attaching +`leftContext R B` to `S`. + +## Main definitions + +* `TypedConverter.ofSystem R`: `R` as a typed converter with no inside interfaces +* `TypedConverter.constant R B`: the converter that ignores its inside system and exposes `R` +* `TypedConverter.rightContext A S`, `TypedConverter.leftContext R B`: the fixed contexts + +## Main results + +* `TypedConverter.attach_ofSystem`, `TypedConverter.attach_constant`: attaching them gives `R` +* `TypedConverter.attach_rightContext`, `TypedConverter.attach_leftContext`: attaching a + context is parallel composition + +Source: Jost, §2.2.2 and Proposition 2.2.3. +-/ + +namespace SystemAlgebra + +open Classical Probability Interface + +variable {A B : Interface} + +/-- The unit interface has exactly one typed system. -/ +lemma TypedSystem.empty_eq (S : TypedSystem unit) : S = TypedSystem.dummy := by + apply Subtype.ext + apply RandomSystem.ext + rintro (_ | ⟨⟨⟨e, _⟩, _⟩, _⟩) + · rw [S.1.mass_nil, TypedSystem.dummy.1.mass_nil] + · exact e.elim + +namespace TypedConverter + +/-! ## A typed system as a converter with no inside interfaces -/ + +/-- A typed system as a typed converter with no inside interfaces: the PDC of the DDC readings +of a presentation of the system. -/ +noncomputable def ofSystem (R : TypedSystem A) : TypedConverter A unit := + PDCBehavior.ofPDC (resourcePDC R.exists_ofPDS.choose) + +lemma attach_ofSystem (R : TypedSystem A) (S : TypedSystem unit) : + (ofSystem R • S : TypedSystem A) = R := by + rw [TypedSystem.empty_eq S] + have hQ := R.exists_ofPDS.choose_spec + apply Subtype.ext + apply RandomSystem.ext + intro h + rw [smul_val, PDCBehavior.attach_presents unit.nonempty_prefix + A.nonempty_prefix (ofSystem R) TypedSystem.dummy.1 TypedSystem.dummy.2 + (resourcePDC R.exists_ofPDS.choose) _ (fun _ => rfl) (fun _ => rfl) h, + behaviorMass_attachPDS, Distribution.prod_single_right, Distribution.mass_fTransform] + conv_rhs => rw [← hQ] + change _ = R.exists_ofPDS.choose.1.mass _ + rw [resourcePDC, Distribution.mass_fTransform] + refine Distribution.mass_congr _ fun s => ?_ + dsimp only + erw [apply_resourceDDC _ s.2.1.1, s.2.1.trim_eq] + +/-! ## Constant converters and fixed contexts -/ + +/-- The typed converter that attaches to any typed system and exposes no interface. -/ +noncomputable def discard (B : Interface) : TypedConverter unit B := + ofDDC (discardSystem B.I B.X B.Y) (discardSystem_isDDCFrom B.domain) + +/-- A constant converter: it ignores its inside system and exposes `R`. No +efficiency claim is made for this unrestricted mathematical converter. -/ +noncomputable def constant (R : TypedSystem A) (B : Interface) : TypedConverter A B := + comp (ofSystem R) (discard B) + +lemma attach_constant (R : TypedSystem A) {B : Interface} (S : TypedSystem B) : + (constant R B • S : TypedSystem A) = R := by + rw [constant, comp_smul, attach_ofSystem] + +/-- The right unit renaming attached to a typed system puts the dummy system beside it. -/ +lemma rightUnitor_hom_attach (R : TypedSystem A) : + (rename (A := tensor A unit) (B := A) (Equiv.sumEmpty A.I Empty) (rightUnitAlphabet A.X) + (rightUnitAlphabet A.Y) (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) + (parallelDomain_unit_right A) • R : TypedSystem (tensor A unit)) = + TypedSystem.parallel R TypedSystem.dummy := by + apply Subtype.ext + apply RandomSystem.ext + intro h + rw [rename_mass, TypedSystem.parallel_unit_right_mass] + +/-- The left unit renaming attached to a typed system puts the dummy system beside it. -/ +lemma leftUnitor_hom_attach (R : TypedSystem A) : + (rename (A := tensor unit A) (B := A) (Equiv.emptySum Empty A.I) (leftUnitAlphabet A.X) + (leftUnitAlphabet A.Y) (leftUnitAlphabet_fst A.X) (leftUnitAlphabet_fst A.Y) + (parallelDomain_unit_left A) • R : TypedSystem (tensor unit A)) = + TypedSystem.parallel TypedSystem.dummy R := by + apply Subtype.ext + apply RandomSystem.ext + intro h + rw [rename_mass, TypedSystem.parallel_unit_left_mass] + +/-- The fixed right context: the identity beside `S` as a converter, followed by the right unit +renaming. -/ +noncomputable def rightContext (A : Interface) {B : Interface} (S : TypedSystem B) : + TypedConverter (tensor A B) A := + comp (parallel (TypedConverter.id A) (ofSystem S)) + (rename (Equiv.sumEmpty A.I Empty) (rightUnitAlphabet A.X) (rightUnitAlphabet A.Y) + (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) (parallelDomain_unit_right A)) + +/-- The fixed left context; no symmetry of the selected substitution relation is used. -/ +noncomputable def leftContext {A : Interface} (R : TypedSystem A) (B : Interface) : + TypedConverter (tensor A B) B := + comp (parallel (ofSystem R) (TypedConverter.id B)) + (rename (Equiv.emptySum Empty B.I) (leftUnitAlphabet B.X) (leftUnitAlphabet B.Y) + (leftUnitAlphabet_fst B.X) (leftUnitAlphabet_fst B.Y) (parallelDomain_unit_left B)) + +lemma attach_rightContext (R : TypedSystem A) (S : TypedSystem B) : + (rightContext A S • R : TypedSystem (tensor A B)) = TypedSystem.parallel R S := by + rw [rightContext, comp_smul, rightUnitor_hom_attach, parallel_attach, identity_attach, + attach_ofSystem] + +lemma attach_leftContext (R : TypedSystem A) (S : TypedSystem B) : + (leftContext R B • S : TypedSystem (tensor A B)) = TypedSystem.parallel R S := by + rw [leftContext, comp_smul, leftUnitor_hom_attach, parallel_attach, identity_attach, + attach_ofSystem] + +end TypedConverter + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/ConverterCoherence.lean b/src/RandomSystems/Typed/ConverterCoherence.lean similarity index 75% rename from src/ConstructiveCryptography/ConverterCoherence.lean rename to src/RandomSystems/Typed/ConverterCoherence.lean index 345543b..49d278a 100644 --- a/src/ConstructiveCryptography/ConverterCoherence.lean +++ b/src/RandomSystems/Typed/ConverterCoherence.lean @@ -1,22 +1,26 @@ -import ConstructiveCryptography.DDCCoherence -import ConstructiveCryptography.InterfaceTensorRename +import RandomSystems.Typed.DDCCoherence +import RandomSystems.Typed.TensorRename /-! -# Naturality of the associator and the unitors +# Naturality of regrouping -The associator and the unitors are natural for arbitrary converters. With presentations of the -converters, both sides are mixtures over the same samples; on each sample both sides are DDCs -with the same domains below one unrestricted regrouping, so they have the same transcripts. +The regrouping renamings (associativity and the two unit laws of parallel interfaces) are +natural for arbitrary typed converters. With presentations of the converters, both sides are +mixtures over the same samples; on each sample both sides are DDCs with the same domains below +one unrestricted regrouping, so they have the same transcripts. ## Main results -* `Interface.comp_associator`: naturality of the associator -* `Interface.comp_leftUnitor`, `Interface.comp_rightUnitor`: naturality of the unitors +* `TypedConverter.comp_associator`: naturality of the associativity renaming +* `TypedConverter.comp_leftUnitor`, `TypedConverter.comp_rightUnitor`: naturality of the unit + renamings -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra -open Classical CategoryTheory Probability +open Classical Probability + +namespace Interface variable {A B C D E F : Interface} {a : InsideOutsideSystem A.I D.I A.X A.Y D.X D.Y} @@ -67,38 +71,6 @@ lemma replies_associator_iff {ba bb bc : ℕ} (ha : IsDDCFrom D.domain A.domain exact (replies_trim_iff _ _ _).mpr (((replies_trim_iff _ _ _).mp hr).serialM_mono hA (fun _ _ hy => hy)) -/-- **The associator is natural.** -/ -lemma comp_associator (α : A ⟶ D) (β : B ⟶ E) (γ : C ⟶ F) : - parallelConverter (parallelConverter α β) γ ≫ (associator D E F).hom = - (associator A B C).hom ≫ parallelConverter α (parallelConverter β γ) := by - obtain ⟨rD, hrD, hD, hDle⟩ := exists_rename_eq_ofDDC (A := tensor (tensor D E) F) - (B := tensor D (tensor E F)) _ _ _ (assocAlphabet_fst D.X E.X F.X) - (assocAlphabet_fst D.Y E.Y F.Y) (parallelDomain_assoc D E F) - obtain ⟨rA, hrA, hA, hAle⟩ := exists_rename_eq_ofDDC (A := tensor (tensor A B) C) - (B := tensor A (tensor B C)) _ _ _ (assocAlphabet_fst A.X B.X C.X) - (assocAlphabet_fst A.Y B.Y C.Y) (parallelDomain_assoc A B C) - have hD' : (associator D E F).hom = PDCBehavior.ofDDC rD hrD := hD - have hA' : (associator A B C).hom = PDCBehavior.ofDDC rA hrA := hA - rw [hD', hA'] - obtain ⟨ba, P, hP⟩ := α.2 - obtain ⟨bb, Q, hQ⟩ := β.2 - obtain ⟨bc, R, hR⟩ := γ.2 - apply PDCBehavior.ext - intro h - change (PDCBehavior.comp _ _).1 h = (PDCBehavior.comp _ _).1 h - have hAB := fun h => (PDCBehavior.tensor_presents α β P Q hP hQ h).symm - have hBC := fun h => (PDCBehavior.tensor_presents β γ Q R hQ hR h).symm - have hL := fun h => (PDCBehavior.tensor_presents (parallelConverter α β) γ _ R hAB hR h).symm - have hR' := fun h => (PDCBehavior.tensor_presents α (parallelConverter β γ) P _ hP hBC h).symm - rw [PDCBehavior.comp_ofDDC_presents (parallelConverter (parallelConverter α β) γ) _ hL hrD h, - PDCBehavior.ofDDC_comp_presents hrA (parallelConverter α (parallelConverter β γ)) _ hR' h] - simp only [tensorPDC, Distribution.mass_fTransform, Distribution.fTransform_prod_left, - Distribution.fTransform_prod_right] - rw [← Distribution.fTransform_assoc_prod P.1 Q.1 R.1, Distribution.mass_fTransform] - apply Distribution.mass_congr - intro p - exact replies_associator_iff p.1.2 p.2.1.2 p.2.2.2 hrD hrA hDle hAle h - /-- The identity on the unit interface is the forwarding converter. -/ lemma filter_unit : (DDC.filter (Y := unit.Y) (fun h => h = [] ∨ unit.domain h) @@ -174,56 +146,109 @@ lemma replies_rightUnitor_iff {ba : ℕ} (ha : IsDDCFrom D.domain A.domain ba a) exact (replies_trim_iff _ _ _).mpr (((replies_trim_iff _ _ _).mp hr).serialM_mono hA (fun _ _ hy => hy)) -/-- **The left unitor is natural.** -/ -lemma comp_leftUnitor (α : A ⟶ D) : - parallelConverter (𝟙 unit) α ≫ (leftUnitor D).hom = (leftUnitor A).hom ≫ α := by +end Interface + +namespace TypedConverter + +open Interface + +variable {A B C D E F : Interface} + +/-- **The associativity renaming is natural.** -/ +lemma comp_associator (α : TypedConverter A D) (β : TypedConverter B E) + (γ : TypedConverter C F) : + comp (parallel (parallel α β) γ) + (rename (Equiv.sumAssoc D.I E.I F.I) (assocAlphabet D.X E.X F.X) + (assocAlphabet D.Y E.Y F.Y) (assocAlphabet_fst D.X E.X F.X) + (assocAlphabet_fst D.Y E.Y F.Y) (parallelDomain_assoc D E F)) = + comp (rename (Equiv.sumAssoc A.I B.I C.I) (assocAlphabet A.X B.X C.X) + (assocAlphabet A.Y B.Y C.Y) (assocAlphabet_fst A.X B.X C.X) + (assocAlphabet_fst A.Y B.Y C.Y) (parallelDomain_assoc A B C)) + (parallel α (parallel β γ)) := by + obtain ⟨rD, hrD, hD, hDle⟩ := exists_rename_eq_ofDDC (A := tensor (tensor D E) F) + (B := tensor D (tensor E F)) _ _ _ (assocAlphabet_fst D.X E.X F.X) + (assocAlphabet_fst D.Y E.Y F.Y) (parallelDomain_assoc D E F) + obtain ⟨rA, hrA, hA, hAle⟩ := exists_rename_eq_ofDDC (A := tensor (tensor A B) C) + (B := tensor A (tensor B C)) _ _ _ (assocAlphabet_fst A.X B.X C.X) + (assocAlphabet_fst A.Y B.Y C.Y) (parallelDomain_assoc A B C) + rw [hD, hA] + obtain ⟨ba, P, hP⟩ := α.2 + obtain ⟨bb, Q, hQ⟩ := β.2 + obtain ⟨bc, R, hR⟩ := γ.2 + apply PDCBehavior.ext + intro h + change (PDCBehavior.comp _ _).1 h = (PDCBehavior.comp _ _).1 h + have hAB := fun h => (PDCBehavior.tensor_presents α β P Q hP hQ h).symm + have hBC := fun h => (PDCBehavior.tensor_presents β γ Q R hQ hR h).symm + have hL := fun h => (PDCBehavior.tensor_presents (parallel α β) γ _ R hAB hR h).symm + have hR' := fun h => (PDCBehavior.tensor_presents α (parallel β γ) P _ hP hBC h).symm + rw [PDCBehavior.comp_ofDDC_presents (parallel (parallel α β) γ) _ hL hrD h, + PDCBehavior.ofDDC_comp_presents hrA (parallel α (parallel β γ)) _ hR' h] + simp only [tensorPDC, Distribution.mass_fTransform, Distribution.fTransform_prod_left, + Distribution.fTransform_prod_right] + rw [← Distribution.fTransform_assoc_prod P.1 Q.1 R.1, Distribution.mass_fTransform] + apply Distribution.mass_congr + intro p + exact replies_associator_iff p.1.2 p.2.1.2 p.2.2.2 hrD hrA hDle hAle h + +/-- **The left unit renaming is natural.** -/ +lemma comp_leftUnitor (α : TypedConverter A D) : + comp (parallel (TypedConverter.id unit) α) + (rename (Equiv.emptySum Empty D.I) (leftUnitAlphabet D.X) (leftUnitAlphabet D.Y) + (leftUnitAlphabet_fst D.X) (leftUnitAlphabet_fst D.Y) (parallelDomain_unit_left D)) = + comp (rename (Equiv.emptySum Empty A.I) (leftUnitAlphabet A.X) (leftUnitAlphabet A.Y) + (leftUnitAlphabet_fst A.X) (leftUnitAlphabet_fst A.Y) (parallelDomain_unit_left A)) + α := by obtain ⟨rD, hrD, hD, hDle⟩ := exists_rename_eq_ofDDC (A := tensor unit D) (B := D) _ _ _ (leftUnitAlphabet_fst D.X) (leftUnitAlphabet_fst D.Y) (parallelDomain_unit_left D) obtain ⟨rA, hrA, hA, hAle⟩ := exists_rename_eq_ofDDC (A := tensor unit A) (B := A) _ _ _ (leftUnitAlphabet_fst A.X) (leftUnitAlphabet_fst A.Y) (parallelDomain_unit_left A) - have hD' : (leftUnitor D).hom = PDCBehavior.ofDDC rD hrD := hD - have hA' : (leftUnitor A).hom = PDCBehavior.ofDDC rA hrA := hA - rw [hD', hA'] + rw [hD, hA] obtain ⟨ba, P, hP⟩ := α.2 apply PDCBehavior.ext intro h change (PDCBehavior.comp _ _).1 h = (PDCBehavior.comp _ _).1 h - have hT := fun h => (PDCBehavior.tensor_presents (𝟙 unit) α + have hT := fun h => (PDCBehavior.tensor_presents (TypedConverter.id unit) α ⟨Finsupp.single ⟨_, isDDCFrom_filter unit.nonempty_prefix⟩ 1, Distribution.isProbDist_single _⟩ P (fun _ => rfl) hP h).symm - rw [PDCBehavior.comp_ofDDC_presents (parallelConverter (𝟙 unit) α) _ hT hrD h, + rw [PDCBehavior.comp_ofDDC_presents (parallel (TypedConverter.id unit) α) _ hT hrD h, PDCBehavior.ofDDC_comp_presents hrA α P hP h] simp only [tensorPDC, Distribution.mass_fTransform, Distribution.prod_single_left] apply Distribution.mass_congr intro p exact replies_leftUnitor_iff p.2 hrD hrA hDle hAle h -/-- **The right unitor is natural.** -/ -lemma comp_rightUnitor (α : A ⟶ D) : - parallelConverter α (𝟙 unit) ≫ (rightUnitor D).hom = (rightUnitor A).hom ≫ α := by +/-- **The right unit renaming is natural.** -/ +lemma comp_rightUnitor (α : TypedConverter A D) : + comp (parallel α (TypedConverter.id unit)) + (rename (Equiv.sumEmpty D.I Empty) (rightUnitAlphabet D.X) (rightUnitAlphabet D.Y) + (rightUnitAlphabet_fst D.X) (rightUnitAlphabet_fst D.Y) (parallelDomain_unit_right D)) = + comp (rename (Equiv.sumEmpty A.I Empty) (rightUnitAlphabet A.X) (rightUnitAlphabet A.Y) + (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) (parallelDomain_unit_right A)) + α := by obtain ⟨rD, hrD, hD, hDle⟩ := exists_rename_eq_ofDDC (A := tensor D unit) (B := D) _ _ _ (rightUnitAlphabet_fst D.X) (rightUnitAlphabet_fst D.Y) (parallelDomain_unit_right D) obtain ⟨rA, hrA, hA, hAle⟩ := exists_rename_eq_ofDDC (A := tensor A unit) (B := A) _ _ _ (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) (parallelDomain_unit_right A) - have hD' : (rightUnitor D).hom = PDCBehavior.ofDDC rD hrD := hD - have hA' : (rightUnitor A).hom = PDCBehavior.ofDDC rA hrA := hA - rw [hD', hA'] + rw [hD, hA] obtain ⟨ba, P, hP⟩ := α.2 apply PDCBehavior.ext intro h change (PDCBehavior.comp _ _).1 h = (PDCBehavior.comp _ _).1 h - have hT := fun h => (PDCBehavior.tensor_presents α (𝟙 unit) P + have hT := fun h => (PDCBehavior.tensor_presents α (TypedConverter.id unit) P ⟨Finsupp.single ⟨_, isDDCFrom_filter unit.nonempty_prefix⟩ 1, Distribution.isProbDist_single _⟩ hP (fun _ => rfl) h).symm - rw [PDCBehavior.comp_ofDDC_presents (parallelConverter α (𝟙 unit)) _ hT hrD h, + rw [PDCBehavior.comp_ofDDC_presents (parallel α (TypedConverter.id unit)) _ hT hrD h, PDCBehavior.ofDDC_comp_presents hrA α P hP h] simp only [tensorPDC, Distribution.mass_fTransform, Distribution.prod_single_right] apply Distribution.mass_congr intro p exact replies_rightUnitor_iff p.2 hrD hrA hDle hAle h -end SystemAlgebra.Interface +end TypedConverter + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/DDCCoherence.lean b/src/RandomSystems/Typed/DDCCoherence.lean similarity index 99% rename from src/ConstructiveCryptography/DDCCoherence.lean rename to src/RandomSystems/Typed/DDCCoherence.lean index ee5292e..307b9b1 100644 --- a/src/ConstructiveCryptography/DDCCoherence.lean +++ b/src/RandomSystems/Typed/DDCCoherence.lean @@ -1,5 +1,5 @@ import RandomSystems.Converter.ConverterRelabel -import ConstructiveCryptography.InterfaceCoherence +import RandomSystems.Typed.InterfaceCoherence /-! # Regrouping parallel DDCs diff --git a/src/ConstructiveCryptography/DSL/Converters.lean b/src/RandomSystems/Typed/DSL/Converters.lean similarity index 69% rename from src/ConstructiveCryptography/DSL/Converters.lean rename to src/RandomSystems/Typed/DSL/Converters.lean index a273362..e950c44 100644 --- a/src/ConstructiveCryptography/DSL/Converters.lean +++ b/src/RandomSystems/Typed/DSL/Converters.lean @@ -1,29 +1,30 @@ -import ConstructiveCryptography.DSL.Programs -import ConstructiveCryptography.InterfaceFilter -import ConstructiveCryptography.Source -import ConstructiveCryptography.InterfaceParallel +import RandomSystems.Typed.DSL.Programs +import RandomSystems.Typed.Filter +import RandomSystems.Typed.Source +import RandomSystems.Typed.Parallel /-! # Programs as converters -A program making at most `b` inside queries per invocation is a converter from `A` to `B` -whenever `B` admits every nonempty history of at most `b` times `A`'s bound; a program making -exactly `cost u` inside queries on `u` is a converter from outside histories of total cost at -most `q` to an inside budget of `q`. +A program making at most `b` inside queries per invocation is a typed converter from `A` to +`B` whenever `B` admits every nonempty history of at most `b` times `A`'s bound; a program making +exactly `cost u` inside queries on `u` is a typed converter from outside histories of total cost +at most `q` to an inside budget of `q`. ## Main definitions -* `Interface.Converter.ofProgram s P`: the converter of a bounded program -* `Interface.Converter.ofCostedProgram s P`: the converter of a program with exact costs -* `Interface.Converter.ofPreservingProgram s P ι`: the converter of a program preserving the +* `TypedConverter.ofProgram s P`: the converter of a bounded program +* `TypedConverter.ofCostedProgram s P`: the converter of a program with exact costs +* `TypedConverter.ofPreservingProgram s P ι`: the converter of a program preserving the partial port map `ι`, typed by per-port budgets ## Main results -* `Interface.ofDDC_ofProgramOn_smul_ofPDS`: attaching the converter of a program to a resource - inlines the program -* `Interface.ofDDC_ofProgramOn_smul_ofAutomaton`, `Interface.Converter.ofProgram_smul_ofAutomaton`, - `Interface.Converter.ofPreservingProgram_smul_ofAutomaton`: attached to an automaton, it is +* `TypedConverter.ofDDC_ofProgramOn_smul_ofPDS`: attaching the converter of a program to a + typed system inlines the program +* `TypedConverter.ofDDC_ofProgramOn_smul_ofAutomaton`, + `TypedConverter.ofProgram_smul_ofAutomaton`, + `TypedConverter.ofPreservingProgram_smul_ofAutomaton`: attached to an automaton, it is the combined automaton -/ @@ -35,10 +36,10 @@ variable {S : Type} /-- **The converter of a program** making at most `b` inside queries per invocation, started in the state `s`. -/ -noncomputable def Interface.Converter.ofProgram {A B : Interface} (s : S) +noncomputable def TypedConverter.ofProgram {A B : Interface} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) - (hB : ∀ xs, xs ≠ [] → xs.length ≤ b * A.bound → B.domain xs) : A ⟶ B := - Interface.ofDDC (DDC.ofProgramOn s P A.domain) + (hB : ∀ xs, xs ≠ [] → xs.length ≤ b * A.bound → B.domain xs) : TypedConverter A B := + TypedConverter.ofDDC (DDC.ofProgramOn s P A.domain) (DDC.ofProgramOn_isDDCFrom hb A.nonempty_prefix.2 fun h hr hF => by by_cases hne : insideQueries (h.map Prod.snd) = [] · exact Or.inl hne @@ -47,12 +48,12 @@ noncomputable def Interface.Converter.ofProgram {A B : Interface} (s : S) /-- **The converter of a program with exact costs**: outside histories of total cost at most `q` make at most `q` inside queries. -/ -noncomputable def Interface.Converter.ofCostedProgram {A B : Interface} (s : S) +noncomputable def TypedConverter.ofCostedProgram {A B : Interface} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (cost : (Σ o, A.X o) → ℕ) (hc : P.Costs cost) {q : ℕ} (hA : ∀ us, A.domain us → (us.map cost).sum ≤ q) - (hB : ∀ xs, xs ≠ [] → xs.length ≤ q → B.domain xs) : A ⟶ B := - Interface.ofDDC (DDC.ofProgramOn s P A.domain) + (hB : ∀ xs, xs ≠ [] → xs.length ≤ q → B.domain xs) : TypedConverter A B := + TypedConverter.ofDDC (DDC.ofProgramOn s P A.domain) (DDC.ofProgramOn_isDDCFrom hb A.nonempty_prefix.2 fun h hr hF => by by_cases hne : insideQueries (h.map Prod.snd) = [] · exact Or.inl hne @@ -64,14 +65,14 @@ noncomputable def Interface.Converter.ofCostedProgram {A B : Interface} (s : S) /-- **The converter of a port-preserving program**: on outside histories with at most `q o` queries at each label `o`, it makes at most `q o` inside queries at `ι o`, and none for `ι o = none`. -/ -noncomputable def Interface.Converter.ofPreservingProgram {A B : Interface} (s : S) +noncomputable def TypedConverter.ofPreservingProgram {A B : Interface} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (ι : A.I → Option B.I) (hι : P.PortPreserving ι) (q : A.I → ℕ) (hA : ∀ xs, A.domain xs → ∀ o, (SystemAlgebra.restrict o xs).length ≤ q o) (hB : ∀ ys, ys ≠ [] → ys.length ≤ b * A.bound → (∀ o j, ι o = some j → (SystemAlgebra.restrict j ys).length ≤ q o) → B.domain ys) : - A ⟶ B := - Interface.ofDDC (DDC.ofProgramOn s P A.domain) + TypedConverter A B := + TypedConverter.ofDDC (DDC.ofProgramOn s P A.domain) (DDC.ofProgramOn_isDDCFrom hb A.nonempty_prefix.2 fun h hr hF => by by_cases hne : insideQueries (h.map Prod.snd) = [] · exact Or.inl hne @@ -98,18 +99,19 @@ lemma Interface.perPort_tensor_admits {A B : Interface} (q : A.I → ℕ) · exact Or.inl he · exact Or.inr (hB _ he ((SystemAlgebra.length_restrict_le _ _).trans (by simpa using hl))) -/-- **Attaching the converter of a program** to the resource of a PDS: a transcript has the -mass of the resources on which the inlined program, on the outside domain, gives it. -/ -lemma Interface.ofDDC_ofProgramOn_smul_ofPDS {A B : Interface} (s : S) +/-- **Attaching the converter of a program** to the typed system of a PDS: a transcript has the +mass of the deterministic systems on which the inlined program, on the outside domain, gives +it. -/ +lemma TypedConverter.ofDDC_ofProgramOn_smul_ofPDS {A B : Interface} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (hα : IsDDCFrom B.domain A.domain b (DDC.ofProgramOn s P A.domain)) (Q : Probability.Distribution.ProbDist {r : InterfaceSystem B.I B.X B.Y // IsDDS r ∧ RepliesAtQueriedInterface r ∧ ∀ h, (r h).Dom ↔ B.domain h}) (t : List ((Σ i, A.X i) × (Σ i, A.Y i))) : - (Interface.ofDDC (DDC.ofProgramOn s P A.domain) hα • Interface.Resource.ofPDS Q).1 t = + (TypedConverter.ofDDC (DDC.ofProgramOn s P A.domain) hα • TypedSystem.ofPDS Q).1 t = Q.1.mass fun r => Replies (filterDom A.domain (P.inline r.1 b s)) (t.map Prod.fst) (t.map Prod.snd) := by - rw [Interface.smul_val, PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix _ _ _ + rw [TypedConverter.smul_val, PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix _ _ _ ⟨Finsupp.single ⟨_, hα⟩ 1, Probability.Distribution.isProbDist_single _⟩ Q (fun _ => rfl) (fun _ => rfl) t, behaviorMass_attachPDS, Probability.Distribution.prod_single_left, Probability.Distribution.mass_fTransform] @@ -118,20 +120,21 @@ lemma Interface.ofDDC_ofProgramOn_smul_ofPDS {A B : Interface} (s : S) /-- **Attaching the converter of a program to an automaton** gives the combined automaton, its initial state paired with the program's. -/ -lemma Interface.ofDDC_ofProgramOn_smul_ofAutomaton {A B : Interface} {R : Type} (s : S) +lemma TypedConverter.ofDDC_ofProgramOn_smul_ofAutomaton {A B : Interface} {R : Type} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (hα : IsDDCFrom B.domain A.domain b (DDC.ofProgramOn s P A.domain)) (stepR : R → (j : B.I) → B.X j → R × B.Y j) (initial : Probability.Distribution.ProbDist R) : - Interface.ofDDC (DDC.ofProgramOn s P A.domain) hα • Interface.Resource.ofAutomaton B stepR initial = - Interface.Resource.ofAutomaton A (P.combine stepR hb) + TypedConverter.ofDDC (DDC.ofProgramOn s P A.domain) hα • + TypedSystem.ofAutomaton B stepR initial = + TypedSystem.ofAutomaton A (P.combine stepR hb) ⟨Probability.Distribution.fTransform (fun r => (s, r)) initial.1, Probability.Distribution.fTransform_isProbDist _ initial.2⟩ := by apply Subtype.ext apply RandomSystem.ext intro t - rw [Interface.Resource.ofAutomaton_mass] - conv_lhs => rw [Interface.Resource.ofAutomaton] - rw [Interface.ofDDC_ofProgramOn_smul_ofPDS s P hb hα, + rw [TypedSystem.ofAutomaton_mass] + conv_lhs => rw [TypedSystem.ofAutomaton] + rw [TypedConverter.ofDDC_ofProgramOn_smul_ofPDS s P hb hα, Probability.Distribution.mass_fTransform, Probability.Distribution.mass_fTransform] refine Probability.Distribution.mass_congr _ fun r => ?_ change Replies (filterDom A.domain (P.inline (filterDom B.domain (automatonSystem stepR r)) b s)) @@ -139,28 +142,28 @@ lemma Interface.ofDDC_ofProgramOn_smul_ofAutomaton {A B : Interface} {R : Type} rw [← Program.trim_apply_ofProgramOn s hb A.domain A.nonempty_prefix.2, Program.trim_apply_ofProgramOn_automaton stepR hb s r B.nonempty_prefix A.nonempty_prefix hα] -lemma Interface.Converter.ofProgram_smul_ofAutomaton {A B : Interface} {R : Type} (s : S) +lemma TypedConverter.ofProgram_smul_ofAutomaton {A B : Interface} {R : Type} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (hB : ∀ xs, xs ≠ [] → xs.length ≤ b * A.bound → B.domain xs) (stepR : R → (j : B.I) → B.X j → R × B.Y j) (initial : Probability.Distribution.ProbDist R) : - Interface.Converter.ofProgram s P hb hB • Interface.Resource.ofAutomaton B stepR initial = - Interface.Resource.ofAutomaton A (P.combine stepR hb) + TypedConverter.ofProgram s P hb hB • TypedSystem.ofAutomaton B stepR initial = + TypedSystem.ofAutomaton A (P.combine stepR hb) ⟨Probability.Distribution.fTransform (fun r => (s, r)) initial.1, Probability.Distribution.fTransform_isProbDist _ initial.2⟩ := - Interface.ofDDC_ofProgramOn_smul_ofAutomaton s P hb _ stepR initial + TypedConverter.ofDDC_ofProgramOn_smul_ofAutomaton s P hb _ stepR initial -lemma Interface.Converter.ofPreservingProgram_smul_ofAutomaton {A B : Interface} {R : Type} +lemma TypedConverter.ofPreservingProgram_smul_ofAutomaton {A B : Interface} {R : Type} (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (ι : A.I → Option B.I) (hι : P.PortPreserving ι) (q : A.I → ℕ) (hA : ∀ xs, A.domain xs → ∀ o, (SystemAlgebra.restrict o xs).length ≤ q o) (hB : ∀ ys, ys ≠ [] → ys.length ≤ b * A.bound → (∀ o j, ι o = some j → (SystemAlgebra.restrict j ys).length ≤ q o) → B.domain ys) (stepR : R → (j : B.I) → B.X j → R × B.Y j) (initial : Probability.Distribution.ProbDist R) : - Interface.Converter.ofPreservingProgram s P hb ι hι q hA hB • - Interface.Resource.ofAutomaton B stepR initial = - Interface.Resource.ofAutomaton A (P.combine stepR hb) + TypedConverter.ofPreservingProgram s P hb ι hι q hA hB • + TypedSystem.ofAutomaton B stepR initial = + TypedSystem.ofAutomaton A (P.combine stepR hb) ⟨Probability.Distribution.fTransform (fun r => (s, r)) initial.1, Probability.Distribution.fTransform_isProbDist _ initial.2⟩ := - Interface.ofDDC_ofProgramOn_smul_ofAutomaton s P hb _ stepR initial + TypedConverter.ofDDC_ofProgramOn_smul_ofAutomaton s P hb _ stepR initial end SystemAlgebra diff --git a/src/ConstructiveCryptography/DSL/Probability.lean b/src/RandomSystems/Typed/DSL/Probability.lean similarity index 92% rename from src/ConstructiveCryptography/DSL/Probability.lean rename to src/RandomSystems/Typed/DSL/Probability.lean index f28a7b6..b3ff523 100644 --- a/src/ConstructiveCryptography/DSL/Probability.lean +++ b/src/RandomSystems/Typed/DSL/Probability.lean @@ -1,4 +1,4 @@ -import ConstructiveCryptography.Functional +import RandomSystems.Typed.Functional /-! # Laws diff --git a/src/ConstructiveCryptography/DSL/Programs.lean b/src/RandomSystems/Typed/DSL/Programs.lean similarity index 99% rename from src/ConstructiveCryptography/DSL/Programs.lean rename to src/RandomSystems/Typed/DSL/Programs.lean index 44c3b12..3026702 100644 --- a/src/ConstructiveCryptography/DSL/Programs.lean +++ b/src/RandomSystems/Typed/DSL/Programs.lean @@ -1,5 +1,5 @@ import RandomSystems.Converter.ProgramAttachment -import ConstructiveCryptography.DSL.Probability +import RandomSystems.Typed.DSL.Probability import Mathlib.Data.Fintype.Order /-! diff --git a/src/ConstructiveCryptography/DSL/Syntax.lean b/src/RandomSystems/Typed/DSL/Syntax.lean similarity index 100% rename from src/ConstructiveCryptography/DSL/Syntax.lean rename to src/RandomSystems/Typed/DSL/Syntax.lean diff --git a/src/ConstructiveCryptography/DSL/Tactics.lean b/src/RandomSystems/Typed/DSL/Tactics.lean similarity index 99% rename from src/ConstructiveCryptography/DSL/Tactics.lean rename to src/RandomSystems/Typed/DSL/Tactics.lean index 21fe214..da5764f 100644 --- a/src/ConstructiveCryptography/DSL/Tactics.lean +++ b/src/RandomSystems/Typed/DSL/Tactics.lean @@ -1,4 +1,4 @@ -import ConstructiveCryptography.DSL.Programs +import RandomSystems.Typed.DSL.Programs import Lean /-! diff --git a/src/ConstructiveCryptography/InterfaceFilter.lean b/src/RandomSystems/Typed/Filter.lean similarity index 75% rename from src/ConstructiveCryptography/InterfaceFilter.lean rename to src/RandomSystems/Typed/Filter.lean index b4ed784..a68ea97 100644 --- a/src/ConstructiveCryptography/InterfaceFilter.lean +++ b/src/RandomSystems/Typed/Filter.lean @@ -1,30 +1,32 @@ -import ConstructiveCryptography.Interface +import RandomSystems.Typed.Interface import RandomSystems.Distance.Restriction /-! # Domain filters A filter forwards the queries of an admitted history and stops on the others. The filter -admitting `D` on `A` is a converter from `A` restricted to `D` to `A`: the forwarding DDC of -the restricted domain, a DDC from `A`'s domain. Attached to a resource, it is the restriction of -the resource's random system to the restricted domain, so two filters in series act as the -filter of both conditions. +admitting `D` on `A` is a typed converter from `A` restricted to `D` to `A`: the forwarding DDC +of the restricted domain, a DDC from `A`'s domain. Attached to a typed system, it is the +restriction of the system's random system to the restricted domain, so two filters in series act +as the filter of both conditions. Source: CR18, §3.4.3 (printed p. 62). ## Main definitions * `Interface.restrict A D`: the histories of `A`'s domain admitted by `D` -* `Interface.filter A D`: the filter admitting `D` on `A` +* `TypedConverter.filter A D`: the filter admitting `D` on `A` ## Main results -* `Interface.filter_smul`: a filter attached to a resource is the restriction of its random - system -* `Interface.filter_comp_filter_smul`: two filters in series act as the filter of both +* `TypedConverter.filter_smul`: a filter attached to a typed system is the restriction of its + random system +* `TypedConverter.filter_comp_filter_smul`: two filters in series act as the filter of both conditions -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra + +namespace Interface /-- The histories of `A`'s domain admitted by `D`. -/ abbrev restrict (A : Interface) (D : List (Σ i, A.X i) → Prop) @@ -38,23 +40,27 @@ abbrev restrict (A : Interface) (D : List (Σ i, A.X i) → Prop) bound := A.bound length_le h hd := A.length_le h hd.1 +end Interface + +namespace TypedConverter + /-- **The filter** admitting `D` on `A`: it forwards the queries of an admitted history and stops on the others. -/ noncomputable def filter (A : Interface) (D : List (Σ i, A.X i) → Prop) - (hD : ∀ p h, p <+: h → D h → D p) : A.restrict D hD ⟶ A := + (hD : ∀ p h, p <+: h → D h → D p) : TypedConverter (A.restrict D hD) A := ofDDC (DDC.filter (Y := A.Y) (fun h => h = [] ∨ (A.restrict D hD).domain h) (prefix_or_nil (A.restrict D hD).nonempty_prefix.2)).1 ((isDDCFrom_filter (A.restrict D hD).nonempty_prefix).inside_mono fun _ hd => hd.1) -open Classical Probability CategoryTheory +open Classical Probability -/-- **A filter attached to a resource** is the restriction of the resource's random system to +/-- **A filter attached to a typed system** is the restriction of the system's random system to the restricted domain. -/ lemma filter_smul (A : Interface) (D : List (Σ i, A.X i) → Prop) - (hD : ∀ p h, p <+: h → D h → D p) (R : Resource A) : + (hD : ∀ p h, p <+: h → D h → D p) (R : TypedSystem A) : (filter A D hD • R).1 = R.1.restrict (A.restrict D hD).inputDomain fun _ _ hx => hx.1 := by - obtain ⟨Q, hQ⟩ := Resource.exists_ofPDS R + obtain ⟨Q, hQ⟩ := TypedSystem.exists_ofPDS R subst hQ ext h change _ = if Admitted _ h then _ else _ @@ -83,12 +89,12 @@ lemma filter_smul (A : Interface) (D : List (Σ i, A.X i) → Prop) have hf := ((filterDom_dom _ _ _).mp (hr.dom hne)).1 exact Or.inr (hf.resolve_left hne) -/-- **Two filters in series** act as the filter of both conditions: the resources have the +/-- **Two filters in series** act as the filter of both conditions: the typed systems have the same transcript masses. -/ lemma filter_comp_filter_smul (A : Interface) (D : List (Σ i, A.X i) → Prop) (hD : ∀ p h, p <+: h → D h → D p) (D' : List (Σ i, A.X i) → Prop) - (hD' : ∀ p h, p <+: h → D' h → D' p) (R : Resource A) : - ((filter (A.restrict D hD) D' hD' ≫ filter A D hD) • R).1.1 = + (hD' : ∀ p h, p <+: h → D' h → D' p) (R : TypedSystem A) : + (comp (filter (A.restrict D hD) D' hD') (filter A D hD) • R).1.1 = (filter A (fun h => D h ∧ D' h) (fun p h hp hh => ⟨hD p h hp hh.1, hD' p h hp hh.2⟩) • R).1.1 := by rw [comp_smul, filter_smul, filter_smul, filter_smul] @@ -101,4 +107,6 @@ lemma filter_comp_filter_smul (A : Interface) (D : List (Σ i, A.X i) → Prop) admitted_ofInputs_iff (A.restrict _ both).nonempty_prefix] exact or_congr_right and_assoc -end SystemAlgebra.Interface +end TypedConverter + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/Functional.lean b/src/RandomSystems/Typed/Functional.lean similarity index 87% rename from src/ConstructiveCryptography/Functional.lean rename to src/RandomSystems/Typed/Functional.lean index e6a2c05..aa19548 100644 --- a/src/ConstructiveCryptography/Functional.lean +++ b/src/RandomSystems/Typed/Functional.lean @@ -1,36 +1,36 @@ -import ConstructiveCryptography.Interface +import RandomSystems.Typed.Interface import RandomSystems.PDS.Function /-! -# Functional resources +# Functional typed systems -Resources given by reply functions, by conditional reply laws, and by sampling once and +Typed systems given by reply functions, by conditional reply laws, and by sampling once and retaining the sample. Each is a random system on the declared alphabets and domain: reply laws use `RandomSystem.ofConditional`, sampling uses `RandomSystem.mix`. ## Main definitions -* `Interface.Resource.ofConditional`: conditional reply distributions on the domain -* `Interface.Resource.ofFunction`: a reply function at each interface -* `Interface.Resource.sample`: sample once, then keep the sample +* `TypedSystem.ofConditional`: conditional reply distributions on the domain +* `TypedSystem.ofFunction`: a reply function at each interface +* `TypedSystem.sample`: sample once, then keep the sample ## Main results -* `Interface.Resource.ofFunction_mass`: the behavior of a function is the indicator of its +* `TypedSystem.ofFunction_mass`: the behavior of a function is the indicator of its admitted transcripts -* `Interface.Resource.eq_ofFunction`: probability one on the functional transcripts - determines the resource -* `Interface.Resource.sample_ofFunction_mass`: sampled functions are the finite PDS of the +* `TypedSystem.eq_ofFunction`: probability one on the functional transcripts + determines the typed system +* `TypedSystem.sample_ofFunction_mass`: sampled functions are the finite PDS of the function systems -/ namespace SystemAlgebra -open Classical Probability CategoryTheory +open Classical Probability open scoped BigOperators -namespace Interface.Resource +namespace TypedSystem variable {A : Interface} @@ -38,7 +38,7 @@ variable {A : Interface} noncomputable def ofConditional (q : ∀ (h : List ((Σ i, A.X i) × (Σ i, A.Y i))) (i : A.I) (x : A.X i), A.domain (h.map Prod.fst ++ [⟨i, x⟩]) → Distribution.ProbDist (A.Y i)) : - Resource A := by + TypedSystem A := by let reply : ∀ h (x : Σ i, A.X i), A.inputDomain h x → Distribution.ProbDist (Σ i, A.Y i) := fun h x hd => Distribution.PMF (q h x.1 x.2 hd) (fun y => (⟨x.1, y⟩ : Σ i, A.Y i)) refine ⟨RandomSystem.ofConditional reply, ?_⟩ @@ -53,7 +53,7 @@ noncomputable def ofConditional · rfl /-- A deterministic function at each interface, on the declared input domain. -/ -noncomputable def ofFunction (f : ∀ i, A.X i → A.Y i) : Resource A := +noncomputable def ofFunction (f : ∀ i, A.X i → A.Y i) : TypedSystem A := ofConditional fun _ i x _ => ⟨Finsupp.single (f i x) 1, Distribution.isProbDist_single _⟩ lemma ofFunction_snoc (f : ∀ i, A.X i → A.Y i) @@ -69,7 +69,7 @@ lemma ofFunction_snoc (f : ∀ i, A.X i → A.Y i) simp [Distribution.PMF, Distribution.fTransform, Finsupp.single_apply, eq_comm] · rw [dif_neg (show ¬ A.inputDomain h x from hd), if_neg hd] -/-- A functional resource gives probability one to its prescribed answers on +/-- A functional typed system gives probability one to its prescribed answers on each admitted history. -/ lemma ofFunction_mass_eq_one (f : ∀ i, A.X i → A.Y i) (h : List ((Σ i, A.X i) × (Σ i, A.Y i))) @@ -125,7 +125,7 @@ lemma ofFunction_mass (f : ∀ i, A.X i → A.Y i) /-- Probability one on the functional transcripts determines the entire behavior, including probability zero for every different answer. -/ -lemma eq_ofFunction (R : Resource A) (f : ∀ i, A.X i → A.Y i) +lemma eq_ofFunction (R : TypedSystem A) (f : ∀ i, A.X i → A.Y i) (certain : ∀ h, (h = [] ∨ A.domain (h.map Prod.fst)) → (∀ z ∈ h, z.2 = ⟨z.1.1, f z.1.1 z.1.2⟩) → R.1 h = 1) : R = ofFunction f := by @@ -174,14 +174,14 @@ lemma eq_ofFunction (R : Resource A) (f : ∀ i, A.X i → A.Y i) /-- Sample once and retain that choice throughout the interaction. -/ noncomputable def sample {K : Type} (P : Distribution K) [Distribution.IsProbability P] - (R : K → Resource A) : Resource A := + (R : K → TypedSystem A) : TypedSystem A := ⟨RandomSystem.mix ⟨P, Distribution.IsProbability.isProbDist P⟩ (fun k => (R k).1), by intro h x y hne rw [RandomSystem.mix_mass] exact Finset.sum_eq_zero fun k _ => by rw [(R k).2 h x y hne, mul_zero]⟩ lemma sample_mass {K : Type} (P : Distribution K) [Distribution.IsProbability P] - (R : K → Resource A) h : + (R : K → TypedSystem A) h : (sample P R).1 h = ∑ k ∈ P.support, P k * (R k).1 h := rfl /-- Initial sampling of functions is their existing finite DDS presentation. -/ @@ -205,25 +205,25 @@ lemma sample_ofFunction_mass {K : Type} (P : Distribution K) simp only [answers, List.map_eq_nil_iff] split_ifs <;> simp -end Interface.Resource +end TypedSystem open Lean.Parser.Term in /-- A function at each named interface. -/ scoped macro "system " i:funBinder x:funBinder " => " f:term : term => - `(Interface.Resource.ofFunction (fun $i $x => $f)) + `(TypedSystem.ofFunction (fun $i $x => $f)) open Lean.Parser.Term in /-- Annotate a functional system with its interface. -/ scoped macro "system " "[" A:term "] " i:funBinder x:funBinder " => " f:term : term => - `(Interface.Resource.ofFunction (A := $A) (fun $i $x => $f)) + `(TypedSystem.ofFunction (A := $A) (fun $i $x => $f)) /-- Initial sampling scopes over the complete system expression that follows. -/ scoped macro "sample " k:ident " ← " law:term "; " body:term : term => - `(Interface.Resource.sample $law (fun $k => $body)) + `(TypedSystem.sample $law (fun $k => $body)) /-- Initial sampling, with the same sampling symbol as component declarations. -/ scoped macro "sample " k:ident " ←$ " law:term "; " body:term : term => - `(Interface.Resource.sample (show Probability.Distribution.ProbDist _ from $law).1 + `(TypedSystem.sample (show Probability.Distribution.ProbDist _ from $law).1 (fun $k => $body)) end SystemAlgebra diff --git a/src/RandomSystems/Typed/Game.lean b/src/RandomSystems/Typed/Game.lean new file mode 100644 index 0000000..855cf22 --- /dev/null +++ b/src/RandomSystems/Typed/Game.lean @@ -0,0 +1,56 @@ +import RandomSystems.Typed.Interface +import RandomSystems.Game.MBOAttachment + +/-! +# Typed games + +A typed game on an interface `A` is a typed system on the interface of `A` with the MBO whose +MBO, once set, stays set (`RandomSystem.MonotoneMBO`): a game in the sense of CR18, §3.7.1. A +typed converter attaches to it through its MBO-forwarding lift `PDCBehavior.liftMBO`, which +keeps games games (`RandomSystem.MonotoneMBO.attach_liftMBO`), and its visible typed system is +the visible system `RandomSystem.visible`. + +## Main definitions + +* `Interface.withMBO A`: the interface of `A` with the MBO +* `TypedGame A`: typed games on `A` +* `TypedConverter.attachGame α G`: a typed converter attached to a typed game +* `TypedGame.visible G`: the visible typed system of a typed game +-/ + +namespace SystemAlgebra + +/-- The interface of `A` with the MBO: its replies carry the MBO. -/ +abbrev Interface.withMBO (A : Interface) : Interface where + I := A.I + X := A.X + Y := SystemAlgebra.withMBO A.Y + domain := A.domain + nonempty_prefix := A.nonempty_prefix + bound := A.bound + length_le := A.length_le + +/-- **Typed games** on `A`: typed systems on the interface of `A` with the MBO whose MBO, once +set, stays set. -/ +def TypedGame (A : Interface) := {G : TypedSystem A.withMBO // G.1.MonotoneMBO} + +/-- A typed converter attached to a typed game: its lift attached to the game's typed system. -/ +noncomputable def TypedConverter.attachGame {A B : Interface} (α : TypedConverter A B) + (G : TypedGame B) : TypedGame A := + -- The lift runs `α` on the replies of `G` without their MBO and tags each outside reply + -- with the MBO `a` of the latest reply of `G`: + -- + -- ──x────▶ ┌───────────┐ ──u────▶ ┌───┐ + -- │ liftMBO α │ │ G │ + -- ◀─(y,a)─ └───────────┘ ◀─(v,a)─ └───┘ + -- + -- The result is again a game, its MBO once set stays set + -- (`RandomSystem.MonotoneMBO.attach_liftMBO`). + ⟨TypedConverter.attach (A := A.withMBO) (B := B.withMBO) (PDCBehavior.liftMBO α) G.1, + G.2.attach_liftMBO B.nonempty_prefix A.nonempty_prefix α G.1.2⟩ + +/-- The visible typed system of a typed game. -/ +noncomputable def TypedGame.visible {A : Interface} (G : TypedGame A) : TypedSystem A := + ⟨G.1.1.visible, G.1.2.visible⟩ + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/Interface.lean b/src/RandomSystems/Typed/Interface.lean similarity index 55% rename from src/ConstructiveCryptography/Interface.lean rename to src/RandomSystems/Typed/Interface.lean index 4140cd4..77db1f7 100644 --- a/src/ConstructiveCryptography/Interface.lean +++ b/src/RandomSystems/Typed/Interface.lean @@ -1,16 +1,14 @@ import RandomSystems.Converter.ConverterAttachment -import Mathlib.CategoryTheory.Types.Basic /-! -# Interfaces, resources and converters +# Interfaces, typed systems and typed converters An interface is the tuple `A = (I, X, Y, D)`: finitely many labels, finite input and output alphabets at each label, and a finite domain of input histories, prefix-closed and without -the empty history. A resource on `A` is a random system on these alphabets over this domain -that replies at the queried interface. A converter from `A` to `B` is the behavior of a PDC -from `B`'s domain (inside) to `A`'s domain (outside); it acts on resources by attachment. -Interfaces and converters are an instance of `Category`, with serial composition and the -identity; attachment is a contravariant functor to types. +the empty history. A typed system on `A` is a random system on these alphabets over this domain +that replies at the queried interface. A typed converter from `A` to `B` is the behavior of a PDC +from `B`'s domain (inside) to `A`'s domain (outside); it acts on typed systems by the +attachment of PDC behaviors. Sources: MR16, §3 (printed pp. 6–8); Jost, Definitions 2.2.1–2.2.2 (printed pp. 16–18); CR18, Definitions 3.8, 3.9 and 3.17 (printed pp. 61–64). @@ -19,27 +17,26 @@ CR18, Definitions 3.8, 3.9 and 3.17 (printed pp. 61–64). * `Interface`: labels, alphabets and a finite domain * `Interface.queryBudget I X Y q`: the domain of at most `q` queries * `Interface.portBudget I X Y q`: the domain of at most `q i` queries at each label `i` -* `Interface.Resource A`: resources on `A` -* `Interface.Resource.ofPDS`, `Interface.ofDeterministic`: the resource of a PDS of - deterministic resources, and of one deterministic resource -* `Interface.Converter A B`: converters from `A` to `B`, concretely behaviors of PDCs -* `Interface.category`: the category of interfaces and converters -* `Interface.ofDDC`: the converter of a DDC from `B`'s domain to `A`'s -* `Interface.attach`: attachment of a converter to a resource +* `TypedSystem A`: typed systems on `A` +* `TypedSystem.ofPDS`, `TypedSystem.ofDeterministic`: the typed system of a PDS of + deterministic systems, and of one deterministic system +* `TypedConverter A B`: typed converters from `A` to `B`, behaviors of PDCs +* `TypedConverter.comp`, `TypedConverter.id`: serial composition and the identity, of PDC + behaviors +* `TypedConverter.ofDDC`: the typed converter of a DDC from `B`'s domain to `A`'s +* `TypedConverter.attach`: attachment of a typed converter to a typed system ## Main results -* `Interface.Resource.exists_ofPDS`: every resource is the resource of a PDS -* `Interface.identity_attach`: attaching the identity leaves a resource unchanged -* `Interface.comp_smul`: attaching a serial composition attaches the inner converter first -* `Interface.ofDDC_apply`: the converter of a DDC is one on its transcripts +* `TypedSystem.exists_ofPDS`: every typed system is the typed system of a PDS +* `TypedConverter.identity_attach`: attaching the identity leaves a typed system unchanged +* `TypedConverter.comp_smul`: attaching a serial composition attaches the inner converter first +* `TypedConverter.ofDDC_apply`: the typed converter of a DDC is one on its transcripts -/ namespace SystemAlgebra -open CategoryTheory - -/-- The interface-and-domain tuple indexing a class of resources. -/ +/-- The interface-and-domain tuple indexing a class of typed systems. -/ structure Interface where /-- Local interface labels. -/ I : Type @@ -89,60 +86,66 @@ abbrev portBudget (I : Type) [Fintype I] (X Y : I → Type) [∀ i, Fintype (X i abbrev inputDomain (A : Interface) : Domain (Σ i, A.X i) (Σ i, A.Y i) := Domain.ofInputs A.domain A.bound A.length_le -/-- Resources on `A`: random systems over its domain replying at the queried interface. -/ -def Resource (A : Interface) := +end Interface + +/-- Typed systems on `A`: random systems over its domain replying at the queried interface. -/ +def TypedSystem (A : Interface) := {R : RandomSystem (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain // R.RepliesAtQueriedInterface} -/-- The behavior of a PDS of deterministic resources with domain `A.domain`. -/ -noncomputable def Resource.ofPDS {A : Interface} +/-- The behavior of a PDS of deterministic systems with domain `A.domain`. -/ +noncomputable def TypedSystem.ofPDS {A : Interface} (P : Probability.Distribution.ProbDist {s : InterfaceSystem A.I A.X A.Y // - IsDDS s ∧ RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h}) : Resource A := + IsDDS s ∧ RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h}) : TypedSystem A := ⟨RandomSystem.ofPDS P.1 P.2 (fun s _ _ _ _ => s.2.2.2 _), RandomSystem.ofPDS_repliesAtQueriedInterface P⟩ -/-- Every resource is the behavior of a PDS of deterministic resources. -/ -lemma Resource.exists_ofPDS {A : Interface} (R : Resource A) : +/-- Every typed system is the behavior of a PDS of deterministic systems. -/ +lemma TypedSystem.exists_ofPDS {A : Interface} (R : TypedSystem A) : ∃ Q : Probability.Distribution.ProbDist {s : InterfaceSystem A.I A.X A.Y // IsDDS s ∧ SystemAlgebra.RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h}, - Resource.ofPDS Q = R := by + TypedSystem.ofPDS Q = R := by obtain ⟨Q, hQ⟩ := RandomSystem.exists_resource_presentation A.nonempty_prefix R.1 R.2 exact ⟨Q, Subtype.ext (RandomSystem.ext hQ)⟩ -/-- A deterministic resource, as its point distribution. -/ -noncomputable def ofDeterministic {A : Interface} (s : InterfaceSystem A.I A.X A.Y) +/-- A deterministic system, as its point distribution. -/ +noncomputable def TypedSystem.ofDeterministic {A : Interface} (s : InterfaceSystem A.I A.X A.Y) (hs : IsDDS s ∧ SystemAlgebra.RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h) : - Resource A := - Resource.ofPDS ⟨Finsupp.single ⟨s, hs⟩ 1, Probability.Distribution.isProbDist_single _⟩ + TypedSystem A := + TypedSystem.ofPDS ⟨Finsupp.single ⟨s, hs⟩ 1, Probability.Distribution.isProbDist_single _⟩ open Classical in -lemma ofDeterministic_mass {A : Interface} (s : InterfaceSystem A.I A.X A.Y) +lemma TypedSystem.ofDeterministic_mass {A : Interface} (s : InterfaceSystem A.I A.X A.Y) (hs : IsDDS s ∧ SystemAlgebra.RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h) (h : List ((Σ i, A.X i) × (Σ i, A.Y i))) : - (ofDeterministic s hs).1 h = + (TypedSystem.ofDeterministic s hs).1 h = if Replies s (h.map Prod.fst) (h.map Prod.snd) then 1 else 0 := by - simp [ofDeterministic, Resource.ofPDS, RandomSystem.ofPDS, behaviorMass, + simp [TypedSystem.ofDeterministic, TypedSystem.ofPDS, RandomSystem.ofPDS, behaviorMass, Probability.Distribution.mass, Finsupp.sum] -/-- Converters from `A` to `B`: behaviors of PDCs from `B`'s domain (inside) to `A`'s +/-- Typed converters from `A` to `B`: behaviors of PDCs from `B`'s domain (inside) to `A`'s domain (outside). -/ -abbrev Converter (A B : Interface) := +@[instance_reducible] def TypedConverter (A B : Interface) := PDCBehavior A.I B.I A.X A.Y B.X B.Y B.domain B.bound B.length_le A.domain A.bound A.length_le -/-- Interfaces and converters form a category under serial composition. -/ -noncomputable instance category : Category Interface where - Hom := Converter - id A := PDCBehavior.id A.nonempty_prefix - comp α β := PDCBehavior.comp α β - id_comp {A _} α := PDCBehavior.id_comp α A.nonempty_prefix - comp_id {_ B} α := PDCBehavior.comp_id α B.nonempty_prefix - assoc α β γ := PDCBehavior.comp_assoc α β γ +namespace TypedConverter + +/-- Serial composition of typed converters: the composition of their PDC behaviors, `α` outside +and `β` inside. -/ +noncomputable def comp {A B C : Interface} (α : TypedConverter A B) (β : TypedConverter B C) : + TypedConverter A C := + PDCBehavior.comp α β -/-- The converter of a DDC from `B`'s domain to `A`'s domain. -/ +/-- The identity typed converter: the identity PDC behavior on `A`'s domain. -/ +protected noncomputable def id (A : Interface) : TypedConverter A A := + PDCBehavior.id A.nonempty_prefix + +/-- The typed converter of a DDC from `B`'s domain to `A`'s domain. -/ noncomputable def ofDDC {A B : Interface} (α : InsideOutsideSystem A.I B.I A.X A.Y B.X B.Y) - {b : ℕ} (hα : IsDDCFrom B.domain A.domain b α) : A ⟶ B := + {b : ℕ} (hα : IsDDCFrom B.domain A.domain b α) : TypedConverter A B := PDCBehavior.ofDDC α hα -/-- The converter of a DDC gives probability one to its transcripts and zero to all others. -/ +/-- The typed converter of a DDC gives probability one to its transcripts and zero to all +others. -/ lemma ofDDC_apply {A B : Interface} (α : InsideOutsideSystem A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hα : IsDDCFrom B.domain A.domain b α) (t : List ((Σ l, twoFam A.X B.Y l) × (Σ l, twoFam A.Y B.X l))) : @@ -150,34 +153,32 @@ lemma ofDDC_apply {A B : Interface} (α : InsideOutsideSystem A.I B.I A.X A.Y B. if Replies α (t.map Prod.fst) (t.map Prod.snd) then 1 else 0 := PDCBehavior.ofDDC_apply α hα t -/-- Attachment of a converter to a resource. -/ -noncomputable def attach {A B : Interface} (α : A ⟶ B) (R : Resource B) : Resource A := +/-- Attachment of a typed converter to a typed system. -/ +noncomputable def attach {A B : Interface} (α : TypedConverter A B) (R : TypedSystem B) : + TypedSystem A := ⟨PDCBehavior.attach B.nonempty_prefix A.nonempty_prefix α R.1 R.2, PDCBehavior.attach_repliesAtQueriedInterface _ _ α R.1 R.2⟩ -/-- The action of a converter on a resource is attachment. As a default instance, an arrow -whose domains are still to be inferred takes them from the resource it acts on. -/ -@[default_instance high] -noncomputable instance {A B : Interface} : HSMul (A ⟶ B) (Resource B) (Resource A) := +/-- The action of a typed converter on a typed system is attachment. -/ +noncomputable instance {A B : Interface} : + HSMul (TypedConverter A B) (TypedSystem B) (TypedSystem A) := ⟨attach⟩ -lemma smul_val {A B : Interface} (α : A ⟶ B) (R : Resource B) : +lemma smul_val {A B : Interface} (α : TypedConverter A B) (R : TypedSystem B) : (α • R).1 = PDCBehavior.attach B.nonempty_prefix A.nonempty_prefix α R.1 R.2 := rfl -/-- **Attaching the identity** leaves a resource unchanged. -/ -lemma identity_attach {A : Interface} (R : Resource A) : (𝟙 A • R : Resource A) = R := +/-- **Attaching the identity** leaves a typed system unchanged. -/ +lemma identity_attach {A : Interface} (R : TypedSystem A) : + (TypedConverter.id A • R : TypedSystem A) = R := Subtype.ext (PDCBehavior.attach_id A.nonempty_prefix R.1 R.2) /-- **Serial attachment** (MR16 §3.3, printed p. 7: “(β ∘ α)ⁱR = βⁱ(αⁱR)”): attaching a serial composition attaches the inner converter first. -/ -theorem comp_smul {A B C : Interface} (α : A ⟶ B) (β : B ⟶ C) (R : Resource C) : - (α ≫ β) • R = α • (β • R) := +theorem comp_smul {A B C : Interface} (α : TypedConverter A B) (β : TypedConverter B C) + (R : TypedSystem C) : comp α β • R = α • (β • R) := Subtype.ext (PDCBehavior.attach_comp C.nonempty_prefix A.nonempty_prefix B.nonempty_prefix α β R.1 R.2) -lemma comp_eq {A B C : Interface} (α : A ⟶ B) (β : B ⟶ C) : - α ≫ β = PDCBehavior.comp α β := rfl - -end Interface +end TypedConverter end SystemAlgebra diff --git a/src/ConstructiveCryptography/InterfaceCoherence.lean b/src/RandomSystems/Typed/InterfaceCoherence.lean similarity index 85% rename from src/ConstructiveCryptography/InterfaceCoherence.lean rename to src/RandomSystems/Typed/InterfaceCoherence.lean index da364b1..c1a3819 100644 --- a/src/ConstructiveCryptography/InterfaceCoherence.lean +++ b/src/RandomSystems/Typed/InterfaceCoherence.lean @@ -1,17 +1,16 @@ -import ConstructiveCryptography.InterfaceRelabel +import RandomSystems.Typed.Relabel /-! # Regrouping interfaces -The associator and the unitors keep every message and regroup its interface label; each -component sees the same inputs in either grouping, so the domains correspond exactly. The -unit interface has no labels. +Regrouping keeps every message and regroups its interface label; each component sees the same +inputs in either grouping, so the domains correspond exactly. The unit interface has no labels. ## Main definitions * `Interface.unit`: the interface without labels -* `Interface.associator`, `Interface.leftUnitor`, `Interface.rightUnitor`: the regrouping - isomorphisms +* `Interface.assocAlphabet`, `Interface.leftUnitAlphabet`, `Interface.rightUnitAlphabet`: the + regroupings of the alphabets ## Main results @@ -21,7 +20,7 @@ unit interface has no labels. namespace SystemAlgebra.Interface -open Classical CategoryTheory +open Classical def assocAlphabet {I J K : Type} (F : I → Type) (G : J → Type) (H : K → Type) : (Σ l, Sum.rec (Sum.rec F G) H l) ≃ (Σ l, Sum.rec F (Sum.rec G H) l) where @@ -173,17 +172,4 @@ lemma parallelDomain_unit_right (A : Interface) · exact e.elim rwa [hm] at he -noncomputable def associator (A B C : Interface) : - tensor (tensor A B) C ≅ tensor A (tensor B C) := - isoOf (Equiv.sumAssoc A.I B.I C.I) (assocAlphabet A.X B.X C.X) (assocAlphabet A.Y B.Y C.Y) - (assocAlphabet_fst A.X B.X C.X) (assocAlphabet_fst A.Y B.Y C.Y) (parallelDomain_assoc A B C) - -noncomputable def leftUnitor (A : Interface) : tensor unit A ≅ A := - isoOf (Equiv.emptySum Empty A.I) (leftUnitAlphabet A.X) (leftUnitAlphabet A.Y) - (leftUnitAlphabet_fst A.X) (leftUnitAlphabet_fst A.Y) (parallelDomain_unit_left A) - -noncomputable def rightUnitor (A : Interface) : tensor A unit ≅ A := - isoOf (Equiv.sumEmpty A.I Empty) (rightUnitAlphabet A.X) (rightUnitAlphabet A.Y) - (rightUnitAlphabet_fst A.X) (rightUnitAlphabet_fst A.Y) (parallelDomain_unit_right A) - end SystemAlgebra.Interface diff --git a/src/ConstructiveCryptography/Memoryless.lean b/src/RandomSystems/Typed/Memoryless.lean similarity index 90% rename from src/ConstructiveCryptography/Memoryless.lean rename to src/RandomSystems/Typed/Memoryless.lean index af4b169..ee447e5 100644 --- a/src/ConstructiveCryptography/Memoryless.lean +++ b/src/RandomSystems/Typed/Memoryless.lean @@ -1,5 +1,5 @@ -import ConstructiveCryptography.DSL.Converters -import ConstructiveCryptography.Context +import RandomSystems.Typed.DSL.Converters +import RandomSystems.Typed.Context import RandomSystems.System.Memoryless /-! @@ -17,18 +17,18 @@ beside its inside interface: ────────────────►│ P │ ◄────────────────┤ │ ── k(()) ──► T, memoryless with ν' (the converter's own randomness) o ⇒ v └───┘ - (P ≫ rightContext B T) • R = mem(κ), κ = P's reply law against ν, ν' + comp P (rightContext B T) • R = mem(κ), κ = P's reply law against ν, ν' ``` Statements about typed systems are equalities of their random systems (`.1`). ## Main results -* `Interface.source_eq_memoryless`: a source of independent samples of `law` is memoryless -* `Interface.parallel_eq_memoryless`: memoryless systems side by side are memoryless -* `Interface.Converter.ofProgram_smul_memoryless`, - `Interface.Converter.ofPreservingProgram_smul_memoryless`, - `Interface.Converter.ofPreservingProgram_comp_rightContext_smul_memoryless`: the composition law +* `TypedSystem.source_eq_memoryless`: a source of independent samples of `law` is memoryless +* `TypedSystem.parallel_eq_memoryless`: memoryless systems side by side are memoryless +* `TypedConverter.ofProgram_smul_memoryless`, + `TypedConverter.ofPreservingProgram_smul_memoryless`, + `TypedConverter.ofPreservingProgram_comp_rightContext_smul_memoryless`: the composition law `P • mem(ν) = mem(κ)` for the converters of programs ## References @@ -36,14 +36,16 @@ Statements about typed systems are equalities of their random systems (`.1`). 1. U. Maurer. *Cryptography Foundations*. Lecture notes, ETH Zurich, Spring 2018. -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra -open Probability Probability.Distribution CategoryTheory RandomSystem +open Probability Probability.Distribution RandomSystem Interface + +namespace TypedSystem /-- **A source of independent samples is memoryless** [1, Definition 3.1]: the source of `q` samples of `law` replies to each trigger with a fresh sample of `law`. -/ lemma source_eq_memoryless {Z : Type} [Fintype Z] (law : ProbDist Z) (q : ℕ) : - (Resource.source law q).1 = + (TypedSystem.source law q).1 = memoryless (Interface.source Z q).inputDomain (portLaw fun _ _ => law) := by -- Plan: -- 1. The typed source's random system is presented by a table `t ← law^q` of independent @@ -69,12 +71,13 @@ lemma source_eq_memoryless {Z : Type} [Fintype Z] (law : ProbDist Z) (q : ℕ) : let event : List ((Σ _ : Unit, Unit) × (Σ _ : Unit, Z)) → (Fin q → Z) → Prop := fun h t => Replies (filterDom (Interface.source Z q).domain (automatonSystem (sourceStep law) (t, 0))) (h.map Prod.fst) (h.map Prod.snd) - have hmass : ∀ h, (Resource.source law q).1 h = (pi fun _ : Fin q => law.1).mass (event h) := by + have hmass : ∀ h, + (TypedSystem.source law q).1 h = (pi fun _ : Fin q => law.1).mass (event h) := by intro h -- The source is the automaton `sourceStep` started in `(t, 0)` (table `t`, counter `0`) -- for `t ← law^q`: a transcript has the mass of the initial states, hence of the tables, -- from which the automaton gives it. - rw [Resource.source, Resource.ofAutomaton_mass, mass_fTransform] + rw [TypedSystem.source, ofAutomaton_mass, mass_fTransform] -- Step 2: one more trigger reads the next entry of the table. -- One more exchange: the table also gives `h · ((), z)` when the domain admits one more query -- and its entry `h.length` is `z`. @@ -140,7 +143,7 @@ lemma source_eq_memoryless {Z : Type} [Fintype Z] (law : ProbDist Z) (q : ℕ) : law of the left system, one at a right port the reply law of the right system. The typed parallel composition is the systems-level one, `RandomSystem.parallel_memoryless`, with the ports of the two interfaces relabelled as the ports of their tensor. -/ -lemma parallel_eq_memoryless {A B : Interface} {R : Resource A} {T : Resource B} +lemma parallel_eq_memoryless {A B : Interface} {R : TypedSystem A} {T : TypedSystem B} {ν₁ : ∀ i, A.X i → ProbDist (A.Y i)} {ν₂ : ∀ j, B.X j → ProbDist (B.Y j)} (hR : R.1 = memoryless A.inputDomain (portLaw ν₁)) (hT : T.1 = memoryless B.inputDomain (portLaw ν₂)) : @@ -226,7 +229,9 @@ lemma parallel_eq_memoryless {A B : Interface} {R : Resource A} {T : Resource B} · simp only [twoLaw] rw [portLaw_apply_of_ne _ (by simpa using hl), portLaw_apply_of_ne _ (by simpa using hl)] -namespace Converter +end TypedSystem + +namespace TypedConverter variable {A B : Interface} {S : Type} @@ -235,7 +240,7 @@ reply law `ν`, the converter of a program whose reply law against `ν` is `κ` the memoryless system with the reply law `κ`. -/ lemma ofProgram_smul_memoryless (s : S) (P : Program S A.I B.I A.X A.Y B.X B.Y) {b : ℕ} (hb : P.Bounded b) (hB : ∀ xs, xs ≠ [] → xs.length ≤ b * A.bound → B.domain xs) - {R : Resource B} {ν : ∀ j, B.X j → ProbDist (B.Y j)} {κ : ∀ o, A.X o → ProbDist (A.Y o)} + {R : TypedSystem B} {ν : ∀ j, B.X j → ProbDist (B.Y j)} {κ : ∀ o, A.X o → ProbDist (A.Y o)} (hR : R.1 = memoryless B.inputDomain (portLaw ν)) (hκ : ∀ s' o u, P.replyLaw ν s' o u b [] = (κ o u).1) : (ofProgram s P hb hB • R).1 = memoryless A.inputDomain (portLaw κ) := @@ -259,7 +264,7 @@ lemma ofPreservingProgram_smul_memoryless (s : S) (P : Program S A.I B.I A.X A.Y (hA : ∀ xs, A.domain xs → ∀ o, (SystemAlgebra.restrict o xs).length ≤ q o) (hB : ∀ ys, ys ≠ [] → ys.length ≤ b * A.bound → (∀ o j, ι o = some j → (SystemAlgebra.restrict j ys).length ≤ q o) → B.domain ys) - {R : Resource B} {ν : ∀ j, B.X j → ProbDist (B.Y j)} {κ : ∀ o, A.X o → ProbDist (A.Y o)} + {R : TypedSystem B} {ν : ∀ j, B.X j → ProbDist (B.Y j)} {κ : ∀ o, A.X o → ProbDist (A.Y o)} (hR : R.1 = memoryless B.inputDomain (portLaw ν)) (hκ : ∀ s' o u, P.replyLaw ν s' o u b [] = (κ o u).1) : (ofPreservingProgram s P hb ι hι q hA hB • R).1 = memoryless A.inputDomain (portLaw κ) := @@ -269,7 +274,7 @@ lemma ofPreservingProgram_smul_memoryless (s : S) (P : Program S A.I B.I A.X A.Y R.2 /-- **The composition law** for the converter of a port-preserving program with a memoryless -system `T` beside its inside interface (its own randomness, `≫ rightContext B T`): the program +system `T` beside its inside interface (its own randomness, `rightContext B T`): the program is run against the side-by-side reply laws of `R` and `T`. -/ lemma ofPreservingProgram_comp_rightContext_smul_memoryless {C : Interface} (s : S) (P : Program S A.I (tensor B C).I A.X A.Y (tensor B C).X (tensor B C).Y) {b : ℕ} @@ -277,21 +282,22 @@ lemma ofPreservingProgram_comp_rightContext_smul_memoryless {C : Interface} (s : (q : A.I → ℕ) (hA : ∀ xs, A.domain xs → ∀ o, (SystemAlgebra.restrict o xs).length ≤ q o) (hB : ∀ ys, ys ≠ [] → ys.length ≤ b * A.bound → (∀ o j, ι o = some j → (SystemAlgebra.restrict j ys).length ≤ q o) → (tensor B C).domain ys) - {R : Resource B} {T : Resource C} {ν : ∀ j, B.X j → ProbDist (B.Y j)} + {R : TypedSystem B} {T : TypedSystem C} {ν : ∀ j, B.X j → ProbDist (B.Y j)} {ν' : ∀ k, C.X k → ProbDist (C.Y k)} {κ : ∀ o, A.X o → ProbDist (A.Y o)} (hR : R.1 = memoryless B.inputDomain (portLaw ν)) (hT : T.1 = memoryless C.inputDomain (portLaw ν')) (hκ : ∀ s' o u, P.replyLaw (parallelLaw ν ν') s' o u b [] = (κ o u).1) : - ((ofPreservingProgram s P hb ι hι q hA hB ≫ rightContext B T) • R).1 = + (comp (ofPreservingProgram s P hb ι hι q hA hB) (rightContext B T) • R).1 = memoryless A.inputDomain (portLaw κ) := by -- Attaching `rightContext B T` places `T` beside `R` ... - -- (`Interface.comp_smul`: `(P ≫ K) • R = P • (K • R)`; `attach_rightContext`: + -- (`comp_smul`: `comp P K • R = P • (K • R)`; `attach_rightContext`: -- `rightContext B T • R = parallel R T`.) - rw [Interface.comp_smul, attach_rightContext] + rw [comp_smul, attach_rightContext] -- ... a memoryless system with the side-by-side law, to which the program is attached. -- `parallel_eq_memoryless`: `parallel R T` is the memoryless system of `parallelLaw ν ν'`. - exact ofPreservingProgram_smul_memoryless s P hb ι hι q hA hB (parallel_eq_memoryless hR hT) hκ + exact ofPreservingProgram_smul_memoryless s P hb ι hι q hA hB + (TypedSystem.parallel_eq_memoryless hR hT) hκ -end Converter +end TypedConverter -end SystemAlgebra.Interface +end SystemAlgebra diff --git a/src/ConstructiveCryptography/InterfaceParallel.lean b/src/RandomSystems/Typed/Parallel.lean similarity index 87% rename from src/ConstructiveCryptography/InterfaceParallel.lean rename to src/RandomSystems/Typed/Parallel.lean index 5d1950a..75ae5b0 100644 --- a/src/ConstructiveCryptography/InterfaceParallel.lean +++ b/src/RandomSystems/Typed/Parallel.lean @@ -1,25 +1,25 @@ -import ConstructiveCryptography.Interface +import RandomSystems.Typed.Interface import RandomSystems.Converter.ConverterTensor /-! -# Parallel interfaces and parallel resources +# Parallel interfaces and parallel typed systems The parallel interface of `A` and `B` has both label sets, the parallel domain of the two -domains, and the sum of the two bounds. The parallel composition of two resources is the +domains, and the sum of the two bounds. The parallel composition of two typed systems is the parallel composition of their random systems, with the component tag moved into the -interface label. The parallel composition of two converters is the parallel composition +interface label. The parallel composition of two typed converters is the parallel composition of their PDC behaviors. ## Main definitions * `Interface.parallelDomain A B`: the parallel domain of two interfaces * `Interface.tensor A B`: the parallel interface -* `Interface.parallel R S`: the parallel composition of resources -* `Interface.parallelConverter α β`: the parallel composition of converters +* `TypedSystem.parallel R S`: the parallel composition of typed systems +* `TypedConverter.parallel α β`: the parallel composition of typed converters ## Main results -* `Interface.parallel_admits_iff`: on possible histories, the parallel domain of the random +* `TypedSystem.parallel_admits_iff`: on possible histories, the parallel domain of the random systems is the domain of the parallel interface -/ @@ -42,7 +42,7 @@ end SystemAlgebra.RandomSystem namespace SystemAlgebra -open Classical Probability CategoryTheory +open Classical Probability namespace Interface @@ -91,7 +91,13 @@ abbrev tensor (A B : Interface) : Interface where bound := A.bound + B.bound length_le := parallelInputs_length_le A.length_le B.length_le -lemma Resource.possible_domain {A : Interface} (R : Resource A) +end Interface + +namespace TypedSystem + +open Interface + +lemma possible_domain {A : Interface} (R : TypedSystem A) {h : List ((Σ i, A.X i) × (Σ i, A.Y i))} (hp : R.1 h ≠ 0) : h.map Prod.fst = [] ∨ A.domain (h.map Prod.fst) := by rcases List.eq_nil_or_concat h with rfl | ⟨h, ⟨x, y⟩, rfl⟩ @@ -101,7 +107,7 @@ lemma Resource.possible_domain {A : Interface} (R : Resource A) by_contra hd exact hp (R.1.mass_eq_zero_of_not_admitted hd y) -lemma parallel_admits_iff (A B : Interface) (R : Resource A) (S : Resource B) +lemma parallel_admits_iff (A B : Interface) (R : TypedSystem A) (S : TypedSystem B) (h : List (Two (Σ i, A.X i) (Σ j, B.X j) × Two (Σ i, A.Y i) (Σ j, B.Y j))) (hp : RandomSystem.parallel R.1 S.1 h ≠ 0) (x : Two (Σ i, A.X i) (Σ j, B.X j)) : @@ -142,10 +148,10 @@ lemma parallel_admits_iff (A B : Interface) (R : Resource A) (S : Resource B) · have hla' : (RandomSystem.parallelLeft h).length ≤ A.inputDomain.bound := hla simp [Domain.parallel, hh, hla', ha, RandomSystem.parallelRight_queries hh] -/-- Parallel resources use the product cumulative behavior. The two domain +/-- Parallel typed systems use the product cumulative behavior. The two domain descriptions agree on every possible history, including rejected next queries. -/ -noncomputable def parallel {A B : Interface} (R : Resource A) (S : Resource B) : - Resource (tensor A B) := by +noncomputable def parallel {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) : + TypedSystem (tensor A B) := by let eX := sumAlphabet (Sum.rec A.X B.X) let eY := sumAlphabet (Sum.rec A.Y B.Y) let T := (RandomSystem.parallel R.1 S.1).relabel eX eY @@ -192,16 +198,17 @@ noncomputable def parallel {A B : Interface} (R : Resource A) (S : Resource B) : List.append_nil] using mul_eq_zero.mpr (Or.inr hs) · rfl -lemma parallel_mass {A B : Interface} (R : Resource A) (S : Resource B) +lemma parallel_mass {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) (h : List ((Σ i, (tensor A B).X i) × (Σ i, (tensor A B).Y i))) : (parallel R S).1 h = RandomSystem.parallel R.1 S.1 (h.map ((sumAlphabet (Sum.rec A.X B.X)).symm.prodCongr (sumAlphabet (Sum.rec A.Y B.Y)).symm)) := rfl -/-- **Parallel converters**: the parallel composition of the two PDC behaviors. -/ -noncomputable def parallelConverter {A B C D : Interface} (α : A ⟶ B) (β : C ⟶ D) : - tensor A C ⟶ tensor B D := +end TypedSystem + +/-- **Parallel typed converters**: the parallel composition of the two PDC behaviors. -/ +noncomputable def TypedConverter.parallel {A B C D : Interface} (α : TypedConverter A B) + (β : TypedConverter C D) : TypedConverter (Interface.tensor A C) (Interface.tensor B D) := PDCBehavior.tensor α β -end Interface end SystemAlgebra diff --git a/src/RandomSystems/Typed/ParallelAttachment.lean b/src/RandomSystems/Typed/ParallelAttachment.lean new file mode 100644 index 0000000..f484b62 --- /dev/null +++ b/src/RandomSystems/Typed/ParallelAttachment.lean @@ -0,0 +1,61 @@ +import RandomSystems.Typed.SystemParallel + +/-! +# Locality of independent attachment + +Attaching parallel typed converters to parallel typed systems is attachment component by +component: `(α ⊗ β)(R ∥ S) = αR ∥ βS`. With presentations of the two converters and the two +systems, both sides are mixtures over the same four independent samples. + +## Main results + +* `TypedConverter.parallel_attach`: locality of attachment +-/ + +namespace SystemAlgebra.TypedConverter + +open Classical Probability Interface + +variable {A B C D : Interface} + +/-- **Locality**: parallel typed converters act on parallel typed systems component by +component. -/ +lemma parallel_attach (α : TypedConverter A B) (β : TypedConverter C D) (R : TypedSystem B) + (S : TypedSystem D) : + (parallel α β • TypedSystem.parallel R S : TypedSystem (tensor A C)) = + TypedSystem.parallel (α • R : TypedSystem A) (β • S : TypedSystem C) := by + obtain ⟨ba, P, hP⟩ := α.2 + obtain ⟨bb, Q, hQ⟩ := β.2 + obtain ⟨T, rfl⟩ := R.exists_ofPDS + obtain ⟨U, rfl⟩ := S.exists_ofPDS + have hαT : (α • TypedSystem.ofPDS T : TypedSystem A) = + TypedSystem.ofPDS (attachPDS A.nonempty_prefix P T) := + Subtype.ext (RandomSystem.ext fun h => + PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix α (TypedSystem.ofPDS T).1 + (TypedSystem.ofPDS T).2 P T hP (fun _ => rfl) h) + have hβU : (β • TypedSystem.ofPDS U : TypedSystem C) = + TypedSystem.ofPDS (attachPDS C.nonempty_prefix Q U) := + Subtype.ext (RandomSystem.ext fun h => + PDCBehavior.attach_presents D.nonempty_prefix C.nonempty_prefix β (TypedSystem.ofPDS U).1 + (TypedSystem.ofPDS U).2 Q U hQ (fun _ => rfl) h) + have hαβ := fun h => (PDCBehavior.tensor_presents α β P Q hP hQ h).symm + rw [hαT, hβU, TypedSystem.parallel_ofPDS, TypedSystem.parallel_ofPDS] + apply Subtype.ext + apply RandomSystem.ext + intro h + rw [smul_val, PDCBehavior.attach_presents (tensor B D).nonempty_prefix + (tensor A C).nonempty_prefix (parallel α β) + (TypedSystem.ofPDS (A := tensor B D) (parallelPDS T U)).1 + (TypedSystem.ofPDS (A := tensor B D) (parallelPDS T U)).2 _ (parallelPDS T U) hαβ + (fun _ => rfl) h, + behaviorMass_attachPDS] + change _ = behaviorMass _ _ _ + simp only [behaviorMass, tensorPDC, parallelPDS, attachPDS, Distribution.mass_fTransform, + Distribution.fTransform_prod_left, Distribution.fTransform_prod_right] + rw [← Distribution.independent_product_middle P.1 Q.1 T.1 U.1, Distribution.mass_fTransform] + apply Distribution.mass_congr + intro p + exact iff_of_eq (congrArg (fun t => Replies t (h.map Prod.fst) (h.map Prod.snd)) + (trim_apply_tensorL_pair p.1.1.2.isDDC p.1.2.2.isDDC p.2.1.2.2.1 p.2.2.2.2.1)) + +end SystemAlgebra.TypedConverter diff --git a/src/RandomSystems/Typed/PresentedGame.lean b/src/RandomSystems/Typed/PresentedGame.lean new file mode 100644 index 0000000..b4b47b6 --- /dev/null +++ b/src/RandomSystems/Typed/PresentedGame.lean @@ -0,0 +1,169 @@ +import RandomSystems.Game.FunctionGame +import RandomSystems.Typed.Game +import RandomSystems.Typed.Functional + +/-! +# Typed games presented by discrete games + +A probabilistic discrete game whose visible systems present a typed system `R` presents a typed +game on the interface of `R`, the behavior of its deterministic games with the MBO, and the +visible typed system of that game is `R`. A single-label sampled function with a hidden +condition presents a typed game on its interface, conditionally equivalent to the typed system +sampling the ideal function once the answers with the condition unset factor through the ideal +answers. + +## Main definitions + +* `TypedGame.ofPDG`: the typed game a probabilistic discrete game presents +* `TypedGame.ofSingleFunction`: the typed game of a single-label sampled function + +## Main results + +* `TypedGame.visible_ofPDG`: its visible typed system is the presented typed system +* `TypedSystem.sample_ofFunction_eq_behavior`: the typed system sampling a single-label function + is presented by the sampled-function game +* `TypedGame.ofSingleFunction_conditionallyEquivalent`: a single-label sampled-function game is + conditionally equivalent to the typed system sampling the ideal function, from the + fixed-query factorization +-/ + +namespace SystemAlgebra + +open Probability + +namespace TypedGame + +variable {A : Interface} + +/-- **The typed game a probabilistic discrete game presents**: when the visible systems of `G` +present the typed system `R`, the behavior of its deterministic games with the MBO is a typed game +on the interface of `R`. -/ +noncomputable def ofPDG (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) (hG : G.isProbDist) + {R : TypedSystem A} + (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) : TypedGame A := + -- The random system is the behavior of `G` with the MBO. It replies at the queried interface + -- because its visible system, `R`, does, and its MBO once set stays set. + ⟨⟨G.behavior hG, PDG.repliesAtQueriedInterface_behavior hG (visible ▸ R.2)⟩, + PDG.monotoneMBO_behavior hG⟩ + +/-- The visible typed system of the typed game a probabilistic discrete game presents is the +typed system its visible systems present. -/ +lemma visible_ofPDG (G : PDG (Σ i, A.X i) (Σ i, A.Y i) A.inputDomain) (hG : G.isProbDist) + {R : TypedSystem A} + (visible : R.1 = PDS.behavior G.underlying (PDG.underlying_probability hG)) : + (ofPDG G hG visible).visible = R := + -- The visible system of the behavior of `G` is the behavior of its visible systems + -- (`PDG.visible_behavior`), which is `R`. + Subtype.ext ((PDG.visible_behavior hG).trans visible.symm) + +end TypedGame + +/-- **The typed system sampling a single-label function** is the behavior of the visible systems +of the sampled-function game. -/ +lemma TypedSystem.sample_ofFunction_eq_behavior {I K X Y : Type} [Unique I] [Fintype X] + [Fintype Y] (D : List (Σ _ : I, X) → Prop) + (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) (bound : ℕ) + (hb : ∀ h, D h → h.length ≤ bound) (P : Distribution K) [Distribution.IsProbability P] + (f : K → X → Y) (bad : K → MC X) : + (TypedSystem.sample (A := ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩) P + (fun k => TypedSystem.ofFunction (fun _ => f k))).1 = + PDS.behavior (PDG.ofSingleFunction D hD bound hb P f bad).underlying + (PDG.underlying_probability (PDG.ofFunction_isProbDist D hD bound hb + (Distribution.IsProbability.isProbDist P) _ _)) := by + -- Compare the two random systems transcript by transcript. + apply RandomSystem.ext + intro h + -- The typed system sampling the function gives `h` the probability that the DDS answering + -- with the sampled function replies with `h`. + rw [TypedSystem.sample_ofFunction_mass] + change _ = behaviorMass _ _ _ + -- The visible systems of the sampled-function game are the sampled function + -- (`PDG.ofFunction_underlying`), with its answers tagged with the single label. + rw [PDG.ofSingleFunction, PDG.ofFunction_underlying] + -- Both sides are the probability, over `k ∼ P`, that the DDS of `f k` replies with `h`. + simp only [behaviorMass, PDS.ofFunction, Distribution.mass_fTransform] + +/-- **The typed game of a single-label sampled function** with a hidden condition: the typed game +it presents on its interface, whose visible typed system samples the function. -/ +noncomputable def TypedGame.ofSingleFunction {I K X Y : Type} [Unique I] [Fintype X] [Fintype Y] + (D : List (Σ _ : I, X) → Prop) (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) + (bound : ℕ) (hb : ∀ h, D h → h.length ≤ bound) (P : Distribution K) + [Distribution.IsProbability P] (f : K → X → Y) (bad : K → MC X) : + TypedGame ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩ := + TypedGame.ofPDG (PDG.ofSingleFunction D hD bound hb P f bad) + (PDG.ofFunction_isProbDist D hD bound hb (Distribution.IsProbability.isProbDist P) _ _) + (TypedSystem.sample_ofFunction_eq_behavior D hD bound hb P f bad) + +open Classical in +/-- **A single-label sampled-function game is conditionally equivalent to the typed system +sampling the ideal function** when, on every fixed query sequence, the answers jointly with the +unset condition factor through the ideal answers. -/ +lemma TypedGame.ofSingleFunction_conditionallyEquivalent {I K X Y : Type} [Unique I] [Fintype X] + [Fintype Y] (D : List (Σ _ : I, X) → Prop) + (hD : ¬ D [] ∧ ∀ {p h}, p <+: h → p ≠ [] → D h → D p) (bound : ℕ) + (hb : ∀ h, D h → h.length ≤ bound) + (P : Distribution K) [Distribution.IsProbability P] + (f : K → X → Y) (bad : K → MC X) + (Q : Distribution (X → Y)) [Distribution.IsProbability Q] + (factor : ∀ xs (answers : X → Y), + P.mass (fun k => (∀ x ∈ xs, f k x = answers x) ∧ ¬ (bad k).1 xs) = + Q.mass (fun g => ∀ x ∈ xs, g x = answers x) * + P.mass (fun k => ¬ (bad k).1 xs)) : + (TypedGame.ofSingleFunction D hD bound hb P f bad).1.1.ConditionallyEquivalent + (TypedSystem.sample (A := ⟨I, fun _ => X, fun _ => Y, D, hD, bound, hb⟩) + Q (fun g => TypedSystem.ofFunction (fun _ => g))).1 := by + -- Plan: + -- 1. The typed game's random system is the behavior of the sampled-function game. + -- 2. Apply the systems-level `PDG.ofFunction_conditionallyEquivalent` with the ideal law + -- `taggedLaw` (`Q`, its answers tagged with the single label); its factorization + -- hypothesis follows from `factor`. + -- 3. Identify the ideal random system of step 2 with the typed system sampling `Q`. + -- + -- Step 1: the typed game's random system is the behavior of the sampled-function game. + change ((PDG.ofSingleFunction D hD bound hb P f bad).behavior + (PDG.ofFunction_isProbDist D hD bound hb (Distribution.IsProbability.isProbDist P) _ _) + ).ConditionallyEquivalent _ + unfold PDG.ofSingleFunction + -- Step 2: a function `X → Y` as a function on the single interface, and the ideal law. + let tagged := fun g : X → Y => fun x : Σ _ : I, X => (⟨x.1, g x.2⟩ : Σ _ : I, Y) + let taggedLaw := Distribution.fTransform tagged Q + have hQ := Distribution.IsProbability.isProbDist taggedLaw + have hP := Distribution.IsProbability.isProbDist P + -- The sampled-function game, its condition read on the values of the queries, is + -- conditionally equivalent to the function sampled from `taggedLaw`. + have equiv := PDG.ofFunction_conditionallyEquivalent D hD bound hb P (fun k => tagged (f k)) + (fun k => ⟨fun xs => (bad k).1 (xs.map Sigma.snd), + fun {_ _} hp => (bad k).2 (hp.map Sigma.snd)⟩) + (hG := by exact PDG.ofFunction_isProbDist D hD bound hb hP _ _) taggedLaw hQ (by + -- The factorization on a fixed query sequence `xs`, with `xs' = xs.map Sigma.snd`: + -- + -- P[f k = answers on xs' ∧ ¬ bad k xs'] + -- = Q[g = answers on xs'] · P[¬ bad k xs'] (`factor`) + -- = (1 - P[bad k xs']) · Q[g = answers on xs'] (complement, commute) + intro xs answers + -- The mass of `taggedLaw` is the `Q`-mass of the tagged event. + dsimp only [taggedLaw] + rw [Distribution.mass_fTransform] + -- At the single label, a tagged reply equals an answer exactly when its value does. + simp only [tagged, single_interface_answers_iff] + have he := factor (xs.map Sigma.snd) (fun x => (answers ⟨default, x⟩).2) + -- P[bad] + P[¬ bad] = 1, since `P` is a probability distribution. + have complement := Distribution.mass_add_compl P + (fun k => (bad k).1 (xs.map Sigma.snd)) + rw [Distribution.IsProbability.weight_eq_one (X := P)] at complement + have good : P.mass (fun k => ¬ (bad k).1 (xs.map Sigma.snd)) = + 1 - P.mass (fun k => (bad k).1 (xs.map Sigma.snd)) := by linarith + -- Rewrite `factor` into the required form. + rw [good, mul_comm] at he + exact he) + -- Step 3: on each transcript `h`, the game sides agree by definition; it remains to show + -- that the typed system sampling `Q` is the behavior of the PDS sampling from `taggedLaw`. + intro h + convert equiv h using 2 + rw [TypedSystem.sample_ofFunction_mass] + change _ = behaviorMass _ _ _ + -- Both are the `Q`-probability that the DDS of the tagged function replies with `h`. + simp only [behaviorMass, PDS.ofFunction, taggedLaw, Distribution.mass_fTransform] + rfl + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/InterfaceRelabel.lean b/src/RandomSystems/Typed/Relabel.lean similarity index 75% rename from src/ConstructiveCryptography/InterfaceRelabel.lean rename to src/RandomSystems/Typed/Relabel.lean index ef946c9..0430be8 100644 --- a/src/ConstructiveCryptography/InterfaceRelabel.lean +++ b/src/RandomSystems/Typed/Relabel.lean @@ -1,17 +1,28 @@ import RandomSystems.Converter.ConverterRelabel -import ConstructiveCryptography.InterfaceParallel +import RandomSystems.Typed.Parallel /-! # Renaming heterogeneous interfaces -A bijection of interfaces that keeps each message's label and transports the domain gives an -arrow: the identity of the inside interface, with its outside relabeled. Renamings compose, -the renaming by the identity is the identity, and each renaming is an isomorphism. +A bijection of interfaces that keeps each message's label and transports the domain gives a +typed converter: the identity of the inside interface, with its outside relabeled. Renamings +compose, and the renaming by the identity is the identity. + +## Main definitions + +* `TypedConverter.rename e f g`: the renaming converter of a label-preserving bijection + +## Main results + +* `TypedConverter.rename_refl`: the renaming by the identity is the identity +* `TypedConverter.rename_comp`: renamings compose -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra + +open Classical -open Classical CategoryTheory +namespace Interface lemma alphabet_symm_label {I J : Type} {X : I → Type} {Y : J → Type} (e : I ≃ J) (f : (Σ i, X i) ≃ (Σ j, Y j)) @@ -20,23 +31,29 @@ lemma alphabet_symm_label {I J : Type} {X : I → Type} {Y : J → Type} have he := congrArg e.symm (hf (f.symm y)) simpa only [f.apply_symm_apply, e.symm_apply_apply] using he.symm -/-- The forwarding arrow for a label-preserving bijection of alphabets and domains: the +/-- The identity filter lies below the forwarding converter. -/ +lemma filter_mem {A : Interface} {h y} + (hy : y ∈ (DDC.filter (Y := A.Y) (fun h => h = [] ∨ A.domain h) + (prefix_or_nil A.nonempty_prefix.2)).1 h) : y ∈ idConverter A.I A.X A.Y h := + ((filterDom_mem_iff _ _ h y).mp hy).2 + +end Interface + +namespace TypedConverter + +open Interface + +/-- The forwarding converter for a label-preserving bijection of alphabets and domains: the identity of `B`, with its outside relabeled to `A`. -/ noncomputable def rename {A B : Interface} (e : A.I ≃ B.I) (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) (hf : ∀ x, (f x).1 = e x.1) (hg : ∀ y, (g y).1 = e y.1) - (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) : A ⟶ B := + (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) : TypedConverter A B := ofDDC (relabel (DDC.filter (Y := B.Y) (fun h => h = [] ∨ B.domain h) (prefix_or_nil B.nonempty_prefix.2)).1 (outsideMap f) (outsideMap g.symm)) ((isDDCFrom_filter B.nonempty_prefix).relabelOutside e f g.symm hf (alphabet_symm_label e g hg) hd) -/-- The identity filter lies below the forwarding converter. -/ -lemma filter_mem {A : Interface} {h y} - (hy : y ∈ (DDC.filter (Y := A.Y) (fun h => h = [] ∨ A.domain h) - (prefix_or_nil A.nonempty_prefix.2)).1 h) : y ∈ idConverter A.I A.X A.Y h := - ((filterDom_mem_iff _ _ h y).mp hy).2 - /-- A renaming is the behavior of a DDC below the renaming converter. -/ lemma exists_rename_eq_ofDDC {A B : Interface} (e : A.I ≃ B.I) (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) @@ -50,7 +67,7 @@ lemma exists_rename_eq_ofDDC {A B : Interface} (e : A.I ≃ B.I) lemma rename_refl (A : Interface) : rename (Equiv.refl A.I) (Equiv.refl (Σ i, A.X i)) (Equiv.refl (Σ i, A.Y i)) (fun _ => rfl) (fun _ => rfl) - (fun h => (congrArg A.domain (List.map_id h)).to_iff) = 𝟙 A := by + (fun h => (congrArg A.domain (List.map_id h)).to_iff) = TypedConverter.id A := by have he : relabel (DDC.filter (Y := A.Y) (fun h => h = [] ∨ A.domain h) (prefix_or_nil A.nonempty_prefix.2)).1 (outsideMap (Equiv.refl (Σ i, A.X i))) (outsideMap (Equiv.refl (Σ i, A.Y i)).symm) = @@ -67,7 +84,7 @@ lemma rename_comp {A B C : Interface} (e' : B.I ≃ C.I) (f' : (Σ i, B.X i) ≃ (Σ j, C.X j)) (g' : (Σ i, B.Y i) ≃ (Σ j, C.Y j)) (hf' : ∀ x, (f' x).1 = e' x.1) (hg' : ∀ y, (g' y).1 = e' y.1) (hd' : ∀ h, C.domain (h.map f') ↔ B.domain h) : - rename e f g hf hg hd ≫ rename e' f' g' hf' hg' hd' = + comp (rename e f g hf hg hd) (rename e' f' g' hf' hg' hd') = rename (e.trans e') (f.trans f') (g.trans g') (fun x => (hf' (f x)).trans (congrArg e' (hf x))) (fun y => (hg' (g y)).trans (congrArg e' (hg y))) @@ -93,21 +110,6 @@ lemma rename_comp {A B C : Interface} · intro xs ys hr exact hr.mono (relabel_mono (fun _ _ hy => filter_mem hy) _ _) -/-- A bijection of interfaces is an isomorphism of the existing converter category. -/ -noncomputable def isoOf {A B : Interface} (e : A.I ≃ B.I) - (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) - (hf : ∀ x, (f x).1 = e x.1) (hg : ∀ y, (g y).1 = e y.1) - (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) : A ≅ B where - hom := rename e f g hf hg hd - inv := rename e.symm f.symm g.symm (alphabet_symm_label e f hf) (alphabet_symm_label e g hg) - (fun h => by - have he := (hd (h.map f.symm)).symm - simpa only [List.map_map, Equiv.self_comp_symm, List.map_id] using he) - hom_inv_id := by - rw [rename_comp] - simpa only [Equiv.self_trans_symm] using rename_refl A - inv_hom_id := by - rw [rename_comp] - simpa only [Equiv.symm_trans_self] using rename_refl B - -end SystemAlgebra.Interface +end TypedConverter + +end SystemAlgebra diff --git a/src/ConstructiveCryptography/Source.lean b/src/RandomSystems/Typed/Source.lean similarity index 83% rename from src/ConstructiveCryptography/Source.lean rename to src/RandomSystems/Typed/Source.lean index 634c82b..b8f85de 100644 --- a/src/ConstructiveCryptography/Source.lean +++ b/src/RandomSystems/Typed/Source.lean @@ -1,11 +1,11 @@ -import ConstructiveCryptography.Automaton +import RandomSystems.Typed.Automaton /-! # Sources of fresh samples A source answers each query with a fresh sample from its law (Maurer 2002, Definition 1: an `X`-source is a sequence of random variables in `X`; here they are independent and identically -distributed). It is the primitive randomness resource: randomness enters a system only through +distributed). It is the primitive source of randomness: randomness enters a system only through sources. It is the automaton that draws a table of `q` independent samples as its initial state and answers the `k`-th query with the `k`-th entry. @@ -13,7 +13,7 @@ and answers the `k`-th query with the `k`-th entry. * `Interface.source X q`: a single port with no input and outputs in `X`, at most `q` queries * `Interface.sourceStep law`: the `k`-th query receives the `k`-th entry of the table -* `Interface.Resource.source law q`: the source of fresh samples from `law` +* `TypedSystem.source law q`: the source of fresh samples from `law` ## Main results @@ -24,10 +24,10 @@ namespace SystemAlgebra open Probability -namespace Interface - variable {X : Type} +namespace Interface + /-- A source interface: a single port with no input and outputs in `X`, at most `q` queries. -/ abbrev source (X : Type) [Fintype X] (q : ℕ) : Interface := queryBudget Unit (fun _ => Unit) (fun _ => X) q @@ -44,14 +44,14 @@ lemma stateAfter_sourceStep {q : ℕ} (law : Distribution.ProbDist X) (t : Fin q | nil => rfl | append_singleton h x ih => rw [stateAfter_snoc, ih]; simp [sourceStep] +end Interface + /-- **The source of fresh samples from `law`**: the automaton reading its answers from a table of `q` independent samples. -/ -noncomputable def Resource.source [Fintype X] (law : Distribution.ProbDist X) (q : ℕ) : - Resource (Interface.source X q) := - Resource.ofAutomaton (Interface.source X q) (sourceStep law) +noncomputable def TypedSystem.source [Fintype X] (law : Distribution.ProbDist X) (q : ℕ) : + TypedSystem (Interface.source X q) := + TypedSystem.ofAutomaton (Interface.source X q) (Interface.sourceStep law) ⟨Distribution.fTransform (fun t => (t, 0)) (Distribution.pi fun _ : Fin q => law.1), Distribution.fTransform_isProbDist _ (Distribution.pi_isProbDist fun _ => law.2)⟩ -end Interface - end SystemAlgebra diff --git a/src/ConstructiveCryptography/ResourceCoherence.lean b/src/RandomSystems/Typed/SystemCoherence.lean similarity index 70% rename from src/ConstructiveCryptography/ResourceCoherence.lean rename to src/RandomSystems/Typed/SystemCoherence.lean index 75e05be..fcb7858 100644 --- a/src/ConstructiveCryptography/ResourceCoherence.lean +++ b/src/RandomSystems/Typed/SystemCoherence.lean @@ -1,43 +1,31 @@ -import ConstructiveCryptography.ResourceParallel +import RandomSystems.Typed.SystemParallel /-! -# Regrouping parallel resources +# Regrouping parallel typed systems -Regrouping three parallel resources leaves each component history unchanged, so by -independence the probabilities agree. The dummy resource, on the unit interface, has only -its empty transcript and is the unit of parallel composition. Parallel composition is -commutative up to the swap of the two interfaces. +Regrouping three parallel typed systems leaves each component history unchanged, so by +independence the probabilities agree. The dummy system, on the unit interface, has only its +empty transcript, so beside a typed system it leaves the probabilities unchanged. Exchanging the +two components of a parallel composition exchanges the labels of its transcripts. ## Main definitions -* `Interface.dummy`: the resource on the unit interface -* `Interface.swap`: exchanging two parallel interfaces +* `TypedSystem.dummy`: the typed system on the unit interface ## Main results -* `Interface.parallel_assoc`: parallel composition is associative through the associator -* `Interface.parallel_dummy_left`, `Interface.parallel_dummy_right`: the dummy is a unit -* `Interface.parallel_swap`: parallel composition is commutative through the swap +* `TypedSystem.parallel_assoc_mass`: regrouping three parallel typed systems keeps the + probabilities of the regrouped transcripts +* `TypedSystem.parallel_unit_left_mass`, `TypedSystem.parallel_unit_right_mass`: the dummy + system beside a typed system keeps its probabilities +* `TypedSystem.parallel_swap_mass`: exchanging the two components exchanges the labels -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra -open Classical Probability CategoryTheory +open Classical Probability Interface -lemma parallel_mass_of_presentations_raw {A B : Interface} {ι κ : Type} - (R : Resource A) (S : Resource B) (P : Distribution ι) (Q : Distribution κ) - (s : ι → InterfaceSystem A.I A.X A.Y) (t : κ → InterfaceSystem B.I B.X B.Y) - (hR : ∀ h, R.1 h = P.mass (fun i => Replies (s i) (h.map Prod.fst) (h.map Prod.snd))) - (hS : ∀ h, S.1 h = Q.mass (fun i => Replies (t i) (h.map Prod.fst) (h.map Prod.snd))) - (h : List ((Σ i, (tensor A B).X i) × (Σ i, (tensor A B).Y i))) : - (parallel R S).1 h = (Distribution.prod P Q).mass (fun st => - Replies (relabel (pair (s st.1) (t st.2)) - (sumAlphabet (Sum.rec A.X B.X)).symm (sumAlphabet (Sum.rec A.Y B.Y))) - (h.map Prod.fst) (h.map Prod.snd)) := by - rw [parallel_mass_of_presentations R S P Q s t hR hS] - exact Distribution.mass_congr _ (fun _ => by rw [replies_relabel_iff, replies_relabel_iff, replies_trim_iff]) - -lemma parallel_system_assoc {A B C : Interface} +lemma Interface.parallel_system_assoc {A B C : Interface} (a : InterfaceSystem A.I A.X A.Y) (b : InterfaceSystem B.I B.X B.Y) (c : InterfaceSystem C.I C.X C.Y) : relabel (pair (relabel (pair a b) (sumAlphabet (Sum.rec A.X B.X)).symm (sumAlphabet (Sum.rec A.Y B.Y))) c) @@ -58,8 +46,24 @@ lemma parallel_system_assoc {A B C : Interface} · rfl · rcases z with ⟨(_ | ⟨⟨⟩⟩), z⟩ <;> rfl +namespace TypedSystem + +lemma parallel_mass_of_presentations_raw {A B : Interface} {ι κ : Type} + (R : TypedSystem A) (S : TypedSystem B) (P : Distribution ι) (Q : Distribution κ) + (s : ι → InterfaceSystem A.I A.X A.Y) (t : κ → InterfaceSystem B.I B.X B.Y) + (hR : ∀ h, R.1 h = P.mass (fun i => Replies (s i) (h.map Prod.fst) (h.map Prod.snd))) + (hS : ∀ h, S.1 h = Q.mass (fun i => Replies (t i) (h.map Prod.fst) (h.map Prod.snd))) + (h : List ((Σ i, (tensor A B).X i) × (Σ i, (tensor A B).Y i))) : + (parallel R S).1 h = (Distribution.prod P Q).mass (fun st => + Replies (relabel (pair (s st.1) (t st.2)) + (sumAlphabet (Sum.rec A.X B.X)).symm (sumAlphabet (Sum.rec A.Y B.Y))) + (h.map Prod.fst) (h.map Prod.snd)) := by + rw [parallel_mass_of_presentations R S P Q s t hR hS] + exact Distribution.mass_congr _ + (fun _ => by rw [replies_relabel_iff, replies_relabel_iff, replies_trim_iff]) + lemma parallel_assoc_mass_of_presentations {A B C : Interface} {ι κ ν : Type} - (R : Resource A) (S : Resource B) (T : Resource C) + (R : TypedSystem A) (S : TypedSystem B) (T : TypedSystem C) (P : Distribution ι) (Q : Distribution κ) (U : Distribution ν) (s : ι → InterfaceSystem A.I A.X A.Y) (t : κ → InterfaceSystem B.I B.X B.Y) (u : ν → InterfaceSystem C.I C.X C.Y) (hR : ∀ h, R.1 h = P.mass (fun i => Replies (s i) (h.map Prod.fst) (h.map Prod.snd))) @@ -78,7 +82,8 @@ lemma parallel_assoc_mass_of_presentations {A B C : Interface} {ι κ ν : Type} rw [parallel_system_assoc, replies_relabel_iff] rfl -lemma parallel_assoc_mass {A B C : Interface} (R : Resource A) (S : Resource B) (T : Resource C) +lemma parallel_assoc_mass {A B C : Interface} (R : TypedSystem A) (S : TypedSystem B) + (T : TypedSystem C) (h : List ((Σ i, (tensor (tensor A B) C).X i) × (Σ i, (tensor (tensor A B) C).Y i))) : (parallel (parallel R S) T).1 h = (parallel R (parallel S T)).1 (h.map ((assocAlphabet A.X B.X C.X).prodCongr (assocAlphabet A.Y B.Y C.Y))) := by @@ -88,24 +93,14 @@ lemma parallel_assoc_mass {A B C : Interface} (R : Resource A) (S : Resource B) exact parallel_assoc_mass_of_presentations _ _ _ P.1 Q.1 U.1 Subtype.val Subtype.val Subtype.val (fun _ => rfl) (fun _ => rfl) (fun _ => rfl) h -lemma parallel_assoc {A B C : Interface} (R : Resource A) (S : Resource B) (T : Resource C) : - ((associator A B C).inv • parallel (parallel R S) T : Resource (tensor A (tensor B C))) = - parallel R (parallel S T) := by - apply Subtype.ext - apply RandomSystem.ext - intro h - simp only [associator, isoOf] - rw [rename_mass, parallel_assoc_mass] - simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id] - /-- The empty interface family has no possible input or output. -/ -noncomputable def dummy : Resource unit := +noncomputable def dummy : TypedSystem unit := ofDeterministic (fun _ => Part.none) ⟨⟨Part.not_none_dom, fun _ _ _ _ h => (Part.not_none_dom h).elim⟩, fun _ _ _ h => (Part.not_none_dom h.1).elim, fun _ => iff_of_false Part.not_none_dom id⟩ -lemma parallel_unit_left_mass {A : Interface} (R : Resource A) +lemma parallel_unit_left_mass {A : Interface} (R : TypedSystem A) (h : List ((Σ i, (tensor unit A).X i) × (Σ i, (tensor unit A).Y i))) : (parallel dummy R).1 h = R.1 (h.map ((leftUnitAlphabet A.X).prodCongr (leftUnitAlphabet A.Y))) := by @@ -130,7 +125,7 @@ lemma parallel_unit_left_mass {A : Interface} (R : Resource A) change RandomSystem.parallel dummy.1 R.1 k = _ rw [RandomSystem.parallel_mass, if_pos hp.1, hp.2.1, hp.2.2, dummy.1.mass_nil, one_mul] -lemma parallel_unit_right_mass {A : Interface} (R : Resource A) +lemma parallel_unit_right_mass {A : Interface} (R : TypedSystem A) (h : List ((Σ i, (tensor A unit).X i) × (Σ i, (tensor A unit).Y i))) : (parallel R dummy).1 h = R.1 (h.map ((rightUnitAlphabet A.X).prodCongr (rightUnitAlphabet A.Y))) := by @@ -155,31 +150,7 @@ lemma parallel_unit_right_mass {A : Interface} (R : Resource A) change RandomSystem.parallel R.1 dummy.1 k = _ rw [RandomSystem.parallel_mass, if_pos hp.1, hp.2.1, hp.2.2, dummy.1.mass_nil, mul_one] -lemma parallel_dummy_left {A : Interface} (R : Resource A) : - ((leftUnitor A).inv • parallel dummy R : Resource A) = R := by - apply Subtype.ext - apply RandomSystem.ext - intro h - simp only [leftUnitor, isoOf] - rw [rename_mass, parallel_unit_left_mass] - simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id] - -lemma parallel_dummy_right {A : Interface} (R : Resource A) : - ((rightUnitor A).inv • parallel R dummy : Resource A) = R := by - apply Subtype.ext - apply RandomSystem.ext - intro h - simp only [rightUnitor, isoOf] - rw [rename_mass, parallel_unit_right_mass] - simp only [← Equiv.prodCongr_symm, List.map_map, Equiv.self_comp_symm, List.map_id] - -/-- Exchange the two interface families without changing their message values. -/ -noncomputable def swap (A B : Interface) : tensor A B ≅ tensor B A := - isoOf (Equiv.sumComm A.I B.I) (swapAlphabet A.X B.X) (swapAlphabet A.Y B.Y) - (by rintro ⟨(i | j), x⟩ <;> rfl) (by rintro ⟨(i | j), y⟩ <;> rfl) - (parallelDomain_swap A B) - -lemma parallel_swap_mass {A B : Interface} (R : Resource A) (S : Resource B) +lemma parallel_swap_mass {A B : Interface} (R : TypedSystem A) (S : TypedSystem B) (h : List ((Σ i, (tensor A B).X i) × (Σ i, (tensor A B).Y i))) : (parallel S R).1 (h.map ((swapAlphabet A.X B.X).prodCongr (swapAlphabet A.Y B.Y))) = (parallel R S).1 h := by @@ -208,12 +179,6 @@ lemma parallel_swap_mass {A B : Interface} (R : Resource A) (S : Resource B) · exact mul_comm _ _ · rfl -lemma parallel_swap {A B : Interface} (R : Resource A) (S : Resource B) : - ((swap A B).hom • parallel S R : Resource (tensor A B)) = parallel R S := by - apply Subtype.ext - apply RandomSystem.ext - intro h - simp only [swap, isoOf] - rw [rename_mass, parallel_swap_mass] +end TypedSystem -end SystemAlgebra.Interface +end SystemAlgebra diff --git a/src/ConstructiveCryptography/ResourceParallel.lean b/src/RandomSystems/Typed/SystemParallel.lean similarity index 66% rename from src/ConstructiveCryptography/ResourceParallel.lean rename to src/RandomSystems/Typed/SystemParallel.lean index 12de699..ba3b2af 100644 --- a/src/ConstructiveCryptography/ResourceParallel.lean +++ b/src/RandomSystems/Typed/SystemParallel.lean @@ -1,25 +1,27 @@ -import ConstructiveCryptography.InterfaceCoherence +import RandomSystems.Typed.InterfaceCoherence import RandomSystems.Converter.ParallelPDS /-! -# Presentations of parallel resources +# Presentations of parallel typed systems -The parallel composition of two resources presented by PDSs is presented by their parallel -composition `parallelPDS`. Attaching a renaming relabels a resource. +The parallel composition of two typed systems presented by PDSs is presented by their parallel +composition `parallelPDS`. Attaching a renaming relabels a typed system. ## Main results -* `Interface.parallel_mass_of_presentations`, `Interface.parallel_ofPDS`: parallel +* `TypedSystem.parallel_mass_of_presentations`, `TypedSystem.parallel_ofPDS`: parallel composition of presentations -* `Interface.rename_mass`: attaching a renaming relabels the transcripts +* `TypedConverter.rename_mass`: attaching a renaming relabels the transcripts -/ -namespace SystemAlgebra.Interface +namespace SystemAlgebra -open Classical Probability CategoryTheory +open Classical Probability Interface + +namespace TypedSystem lemma parallel_mass_of_presentations {A B : Interface} {ι κ : Type} - (R : Resource A) (S : Resource B) (P : Distribution ι) (Q : Distribution κ) + (R : TypedSystem A) (S : TypedSystem B) (P : Distribution ι) (Q : Distribution κ) (s : ι → InterfaceSystem A.I A.X A.Y) (t : κ → InterfaceSystem B.I B.X B.Y) (hR : ∀ h, R.1 h = P.mass (fun i => Replies (s i) (h.map Prod.fst) (h.map Prod.snd))) (hS : ∀ h, S.1 h = Q.mass (fun i => Replies (t i) (h.map Prod.fst) (h.map Prod.snd))) @@ -38,7 +40,7 @@ lemma parallel_ofPDS {A B : Interface} IsDDS s ∧ RepliesAtQueriedInterface s ∧ ∀ h, (s h).Dom ↔ A.domain h}) (Q : Distribution.ProbDist {t : InterfaceSystem B.I B.X B.Y // IsDDS t ∧ RepliesAtQueriedInterface t ∧ ∀ h, (t h).Dom ↔ B.domain h}) : - parallel (Resource.ofPDS P) (Resource.ofPDS Q) = Resource.ofPDS (parallelPDS P Q) := by + parallel (TypedSystem.ofPDS P) (TypedSystem.ofPDS Q) = TypedSystem.ofPDS (parallelPDS P Q) := by apply Subtype.ext apply RandomSystem.ext intro h @@ -47,17 +49,22 @@ lemma parallel_ofPDS {A B : Interface} change _ = behaviorMass _ _ _ simp only [behaviorMass, parallelPDS, Distribution.mass_fTransform] +end TypedSystem + /-- A forwarding converter only renames the cumulative transcript. -/ -lemma rename_mass {A B : Interface} (e : A.I ≃ B.I) +lemma TypedConverter.rename_mass {A B : Interface} (e : A.I ≃ B.I) (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) (hf : ∀ x, (f x).1 = e x.1) (hg : ∀ y, (g y).1 = e y.1) - (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) (R : Resource B) + (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) (R : TypedSystem B) (h : List ((Σ i, A.X i) × (Σ i, A.Y i))) : - ((rename e f g hf hg hd) • R : Resource A).1 h = R.1 (h.map (f.prodCongr g)) := by - obtain ⟨r, hr, hre, hrle⟩ := exists_rename_eq_ofDDC e f g hf hg hd + (TypedConverter.rename e f g hf hg hd • R : TypedSystem A).1 h = + R.1 (h.map (f.prodCongr g)) := by + obtain ⟨r, hr, hre, hrle⟩ := TypedConverter.exists_rename_eq_ofDDC e f g hf hg hd obtain ⟨Q, rfl⟩ := R.exists_ofPDS - rw [hre, smul_val, PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix _ _ _ - ⟨Finsupp.single ⟨r, hr⟩ 1, Distribution.isProbDist_single _⟩ Q (fun _ => rfl) (fun _ => rfl) h, + rw [hre, TypedConverter.smul_val, + PDCBehavior.attach_presents B.nonempty_prefix A.nonempty_prefix _ _ _ + ⟨Finsupp.single ⟨r, hr⟩ 1, Distribution.isProbDist_single _⟩ Q (fun _ => rfl) (fun _ => rfl) + h, behaviorMass_attachPDS, Distribution.prod_single_left, Distribution.mass_fTransform] change _ = behaviorMass Q.1 _ _ apply Distribution.mass_congr @@ -73,4 +80,4 @@ lemma rename_mass {A B : Interface} (e : A.I ≃ B.I) · rw [replies_relabel_iff] rfl -end SystemAlgebra.Interface +end SystemAlgebra diff --git a/src/ConstructiveCryptography/InterfaceTensorRename.lean b/src/RandomSystems/Typed/TensorRename.lean similarity index 94% rename from src/ConstructiveCryptography/InterfaceTensorRename.lean rename to src/RandomSystems/Typed/TensorRename.lean index ebc9d29..7b52235 100644 --- a/src/ConstructiveCryptography/InterfaceTensorRename.lean +++ b/src/RandomSystems/Typed/TensorRename.lean @@ -1,4 +1,4 @@ -import ConstructiveCryptography.DDCCoherence +import RandomSystems.Typed.DDCCoherence /-! # Parallel renaming @@ -13,13 +13,13 @@ Renaming two disjoint interface families independently is renaming their union. * `Interface.tensorL_renameConverter`: parallel renaming converters are the renaming converter of the union -* `Interface.parallelConverter_rename`: the parallel composition of two renamings is the - renaming of the union +* `TypedConverter.parallel_rename`: the parallel composition of two renamings is the renaming + of the union -/ namespace SystemAlgebra.Interface -open Classical CategoryTheory +open Classical def sumEquiv {I J K L : Type} {U : I → Type} {V : J → Type} {X : K → Type} {Y : L → Type} (f : (Σ i, U i) ≃ (Σ j, V j)) (g : (Σ k, X k) ≃ (Σ l, Y l)) : @@ -121,18 +121,18 @@ lemma tensorL_renameConverter : end SystemAlgebra.Interface -namespace SystemAlgebra.Interface +namespace SystemAlgebra.TypedConverter -open Classical CategoryTheory +open Classical Interface -lemma parallelConverter_rename {A B C D : Interface} +lemma parallel_rename {A B C D : Interface} (e : A.I ≃ B.I) (f : (Σ i, A.X i) ≃ (Σ j, B.X j)) (g : (Σ i, A.Y i) ≃ (Σ j, B.Y j)) (hf : ∀ x, (f x).1 = e x.1) (hg : ∀ y, (g y).1 = e y.1) (hd : ∀ h, B.domain (h.map f) ↔ A.domain h) (e' : C.I ≃ D.I) (f' : (Σ i, C.X i) ≃ (Σ j, D.X j)) (g' : (Σ i, C.Y i) ≃ (Σ j, D.Y j)) (hf' : ∀ x, (f' x).1 = e' x.1) (hg' : ∀ y, (g' y).1 = e' y.1) (hd' : ∀ h, D.domain (h.map f') ↔ C.domain h) : - parallelConverter (rename e f g hf hg hd) (rename e' f' g' hf' hg' hd') = + parallel (rename e f g hf hg hd) (rename e' f' g' hf' hg' hd') = rename (Equiv.sumCongr e e') (sumEquiv f f') (sumEquiv g g') (sumEquiv_label e e' f f' hf hf') (by rintro ⟨(i | j), y⟩; exact congrArg Sum.inl (hg ⟨i, y⟩); exact congrArg Sum.inr (hg' ⟨j, y⟩)) @@ -154,4 +154,4 @@ lemma parallelConverter_rename {A B C D : Interface} rw [← tensorL_renameConverter e f g hf hg e' f' g' hf' hg'] at hs exact hs.mono fun h y hy => canon_mem hy -end SystemAlgebra.Interface +end SystemAlgebra.TypedConverter diff --git a/src/Tests/AuthenticatedEncryption.lean b/src/Tests/AuthenticatedEncryption.lean index 6ffca6b..92d611f 100644 --- a/src/Tests/AuthenticatedEncryption.lean +++ b/src/Tests/AuthenticatedEncryption.lean @@ -28,7 +28,7 @@ noncomputable def oneTimePad : SymmetricEncryption Bool Bool Bool where /-- The collision step on the one-time pad: within `q_e² / 2`. -/ lemma oneTimePad_hybrid_ideal (q : AE.Port → ℕ) : Δ (Hybrid oneTimePad q) (AE.Ideal.perPort Bool Bool (budget := q) • - Encryption.Real.perPort oneTimePad : Interface.Resource (AE.perPort Bool Bool q)) ≤ + Encryption.Real.perPort oneTimePad : TypedSystem (AE.perPort Bool Bool q)) ≤ ((q .enc) ^ 2 / 2 : ℝ≥0) := by simpa using hybrid_ideal_distance_le oneTimePad q @@ -37,7 +37,7 @@ within `q_e² / 2`. -/ lemma oneTimePad_hybrid_ideal_advantage (q : AE.Port → ℕ) {s} (hs : s ∈ DistinctionGames.solvers (AE.perPort Bool Bool q)) : |s.1 (Hybrid oneTimePad q) - s.1 (AE.Ideal.perPort Bool Bool (budget := q) • - Encryption.Real.perPort oneTimePad : Interface.Resource (AE.perPort Bool Bool q))| ≤ + Encryption.Real.perPort oneTimePad : TypedSystem (AE.perPort Bool Bool q))| ≤ (q .enc : ℝ) ^ 2 / 2 := by simpa using GameExamples.hybrid_ideal_advantage_le oneTimePad q hs diff --git a/src/Tests/Axioms/CC.lean b/src/Tests/Axioms/CC.lean index a1cdd0a..4704efd 100644 --- a/src/Tests/Axioms/CC.lean +++ b/src/Tests/Axioms/CC.lean @@ -3,16 +3,10 @@ import ConstructiveCryptography /-! # Axioms of the Constructive Cryptography layer -Interfaces, resources and converters, their instances of the Constructive Cryptography -classes, and the abstract results of those classes depend only on `propext`, -`Classical.choice` and `Quot.sound`. +The abstract results of the Constructive Cryptography classes, and the instances of those classes +on interfaces, depend only on `propext`, `Classical.choice` and `Quot.sound`. -/ --- ConstructiveCryptography.Automaton -#print axioms SystemAlgebra.Interface.Resource.ofAutomaton -#print axioms SystemAlgebra.Interface.Resource.ofAutomaton_mass -#print axioms SystemAlgebra.Interface.parallel_ofAutomaton - -- ConstructiveCryptography.CryptographicAlgebra.Basic #print axioms ConstructiveCryptography.CryptographicAlgebra.attach_parallel #print axioms ConstructiveCryptography.CryptographicAlgebra.parallel_assoc @@ -39,20 +33,6 @@ classes, and the abstract results of those classes depend only on `propext`, #print axioms ConstructiveCryptography.CryptographicAlgebra.Specification.star_idem #print axioms ConstructiveCryptography.CryptographicAlgebra.Specification.Constructs.star - --- ConstructiveCryptography.PresentedGame -#print axioms SystemAlgebra.Interface.Game.visible_ofPDG -#print axioms SystemAlgebra.Interface.Resource.sample_ofFunction_eq_behavior -#print axioms SystemAlgebra.Interface.ofSingleFunction_conditionallyEquivalent -#print axioms SystemAlgebra.Interface.game_dist_le -#print axioms SystemAlgebra.Interface.game_dist_ofSingleFunction_le - --- ConstructiveCryptography.Interface -#print axioms SystemAlgebra.Interface.category -#print axioms SystemAlgebra.Interface.identity_attach -#print axioms SystemAlgebra.Interface.comp_smul -#print axioms SystemAlgebra.Interface.Resource.exists_ofPDS - -- ConstructiveCryptography.InterfaceAlgebra #print axioms SystemAlgebra.Interface.resourcesLaxMonoidal #print axioms SystemAlgebra.Interface.cc_parallel_eq @@ -69,50 +49,29 @@ classes, and the abstract results of those classes depend only on `propext`, #print axioms SystemAlgebra.Interface.substitutesWithin_attach #print axioms SystemAlgebra.Interface.AdmissibleDistinguishers.substitutesWithin_attach #print axioms SystemAlgebra.Interface.AdmissibleDistinguishers.substitutesWithin_context -#print axioms SystemAlgebra.Interface.absorb_comp #print axioms SystemAlgebra.Interface.distinguisherAdvantage_le_distance +#print axioms SystemAlgebra.Interface.parallel_assoc +#print axioms SystemAlgebra.Interface.parallel_dummy_left +#print axioms SystemAlgebra.Interface.parallel_dummy_right +#print axioms SystemAlgebra.Interface.parallel_swap --- ConstructiveCryptography.InterfaceFilter -#print axioms SystemAlgebra.Interface.filter -#print axioms SystemAlgebra.Interface.restrict -#print axioms SystemAlgebra.Interface.filter_smul -#print axioms SystemAlgebra.Interface.filter_comp_filter_smul +-- ConstructiveCryptography.InterfaceCategory +#print axioms SystemAlgebra.Interface.category +#print axioms SystemAlgebra.Interface.identity_attach +#print axioms SystemAlgebra.Interface.comp_smul -- ConstructiveCryptography.InterfaceGame #print axioms SystemAlgebra.Interface.games #print axioms SystemAlgebra.Interface.distinctionGames #print axioms SystemAlgebra.Interface.win_le #print axioms SystemAlgebra.Interface.dist_visible_le +#print axioms SystemAlgebra.Interface.game_dist_le +#print axioms SystemAlgebra.Interface.game_dist_ofSingleFunction_le -- ConstructiveCryptography.InterfaceMonoidal #print axioms SystemAlgebra.Interface.monoidal --- ConstructiveCryptography.InterfaceParallel -#print axioms SystemAlgebra.Interface.parallel -#print axioms SystemAlgebra.Interface.parallelConverter - --- ConstructiveCryptography.Memoryless -#print axioms SystemAlgebra.Interface.source_eq_memoryless -#print axioms SystemAlgebra.Interface.parallel_eq_memoryless -#print axioms SystemAlgebra.Interface.Converter.ofProgram_smul_memoryless -#print axioms SystemAlgebra.Interface.Converter.ofPreservingProgram_smul_memoryless -#print axioms - SystemAlgebra.Interface.Converter.ofPreservingProgram_comp_rightContext_smul_memoryless - -- ConstructiveCryptography.Notation #print axioms SystemAlgebra.Interface.distance_triangle #print axioms SystemAlgebra.Interface.tensor_smul #print axioms SystemAlgebra.Interface.distance_parallel_le - --- ConstructiveCryptography.ResourceCoherence -#print axioms SystemAlgebra.Interface.parallel_assoc -#print axioms SystemAlgebra.Interface.parallel_dummy_left -#print axioms SystemAlgebra.Interface.parallel_dummy_right -#print axioms SystemAlgebra.Interface.parallel_swap - --- ConstructiveCryptography.ResourceParallel -#print axioms SystemAlgebra.Interface.rename_mass -#print axioms SystemAlgebra.Interface.parallel_ofPDS - --- ConstructiveCryptography.ResourceParallelAttachment -#print axioms SystemAlgebra.Interface.parallel_attach diff --git a/src/Tests/Axioms/Systems.lean b/src/Tests/Axioms/Systems.lean index 7ef5f56..a94a2f5 100644 --- a/src/Tests/Axioms/Systems.lean +++ b/src/Tests/Axioms/Systems.lean @@ -5,9 +5,9 @@ import Tests.Counterexamples # Axioms of the systems layer The laws of random systems, deterministic and probabilistic converters, attachment, parallel -composition, probabilistic automata, memoryless systems, distance and games, and the -counterexamples, depend only on `propext`, `Classical.choice` and `Quot.sound`. Comments name the -laws of `papers/SYSTEM_ALGEBRA_SPEC.md`. +composition, probabilistic automata, memoryless systems, distance and games, typed systems and +typed converters, and the counterexamples, depend only on `propext`, `Classical.choice` and +`Quot.sound`. Comments name the laws of `papers/SYSTEM_ALGEBRA_SPEC.md`. -/ -- RandomSystems.Converter.ConverterAttachment @@ -287,6 +287,46 @@ laws of `papers/SYSTEM_ALGEBRA_SPEC.md`. -- RandomSystems.System.Replies #print axioms SystemAlgebra.replies_trim_iff +-- RandomSystems.Typed.Automaton +#print axioms SystemAlgebra.TypedSystem.ofAutomaton +#print axioms SystemAlgebra.TypedSystem.ofAutomaton_mass +#print axioms SystemAlgebra.TypedSystem.parallel_ofAutomaton + +-- RandomSystems.Typed.Filter +#print axioms SystemAlgebra.TypedConverter.filter +#print axioms SystemAlgebra.Interface.restrict +#print axioms SystemAlgebra.TypedConverter.filter_smul +#print axioms SystemAlgebra.TypedConverter.filter_comp_filter_smul + +-- RandomSystems.Typed.Interface +#print axioms SystemAlgebra.TypedSystem.exists_ofPDS +#print axioms SystemAlgebra.TypedConverter.identity_attach +#print axioms SystemAlgebra.TypedConverter.comp_smul + +-- RandomSystems.Typed.Memoryless +#print axioms SystemAlgebra.TypedSystem.source_eq_memoryless +#print axioms SystemAlgebra.TypedSystem.parallel_eq_memoryless +#print axioms SystemAlgebra.TypedConverter.ofProgram_smul_memoryless +#print axioms SystemAlgebra.TypedConverter.ofPreservingProgram_smul_memoryless +#print axioms + SystemAlgebra.TypedConverter.ofPreservingProgram_comp_rightContext_smul_memoryless + +-- RandomSystems.Typed.Parallel +#print axioms SystemAlgebra.TypedSystem.parallel +#print axioms SystemAlgebra.TypedConverter.parallel + +-- RandomSystems.Typed.ParallelAttachment +#print axioms SystemAlgebra.TypedConverter.parallel_attach + +-- RandomSystems.Typed.PresentedGame +#print axioms SystemAlgebra.TypedGame.visible_ofPDG +#print axioms SystemAlgebra.TypedSystem.sample_ofFunction_eq_behavior +#print axioms SystemAlgebra.TypedGame.ofSingleFunction_conditionallyEquivalent + +-- RandomSystems.Typed.SystemParallel +#print axioms SystemAlgebra.TypedConverter.rename_mass +#print axioms SystemAlgebra.TypedSystem.parallel_ofPDS + -- Tests.Counterexamples #print axioms SystemAlgebra.Counterexamples.locality_fails_without_termination #print axioms SystemAlgebra.Counterexamples.identity_fails_without_reactivity diff --git a/src/Tests/DSL/Axioms.lean b/src/Tests/DSL/Axioms.lean index 0e08375..1e0c5dc 100644 --- a/src/Tests/DSL/Axioms.lean +++ b/src/Tests/DSL/Axioms.lean @@ -15,34 +15,34 @@ checks depend only on `propext`, `Classical.choice` and `Quot.sound`. #print axioms SystemAlgebra.DDC.ofProgramOn_isDDCFrom #print axioms SystemAlgebra.DDC.insideQueries_length_le_of_budget #print axioms SystemAlgebra.DDC.insideQueries_length_le_of_costs -#print axioms SystemAlgebra.Interface.Converter.ofProgram -#print axioms SystemAlgebra.Interface.Converter.ofCostedProgram +#print axioms SystemAlgebra.TypedConverter.ofProgram +#print axioms SystemAlgebra.TypedConverter.ofCostedProgram #print axioms SystemAlgebra.DDC.insideQueries_restrict_length_le -#print axioms SystemAlgebra.Interface.Converter.ofPreservingProgram +#print axioms SystemAlgebra.TypedConverter.ofPreservingProgram #print axioms SystemAlgebra.Interface.perPort_tensor_admits --- Inlining: attaching a program runs its body against the resource. +-- Inlining: attaching a program runs its body against the typed system. #print axioms SystemAlgebra.Program.apply_ofProgram #print axioms SystemAlgebra.Program.trim_apply_ofProgram #print axioms SystemAlgebra.Program.trim_apply_ofProgramOn #print axioms SystemAlgebra.apply_filterDom_outside #print axioms SystemAlgebra.PDCBehavior.ofDDC_apply -#print axioms SystemAlgebra.Interface.ofDDC_apply -#print axioms SystemAlgebra.Interface.ofDDC_ofProgramOn_smul_ofPDS +#print axioms SystemAlgebra.TypedConverter.ofDDC_apply +#print axioms SystemAlgebra.TypedConverter.ofDDC_ofProgramOn_smul_ofPDS #print axioms SystemAlgebra.Program.inline_automatonSystem #print axioms SystemAlgebra.Program.trim_apply_ofProgramOn_automaton #print axioms SystemAlgebra.Program.combine_eq_of_invoke #print axioms SystemAlgebra.Program.combine_congr -#print axioms SystemAlgebra.Interface.ofDDC_ofProgramOn_smul_ofAutomaton -#print axioms SystemAlgebra.Interface.Converter.ofProgram_smul_ofAutomaton -#print axioms SystemAlgebra.Interface.Converter.ofPreservingProgram_smul_ofAutomaton +#print axioms SystemAlgebra.TypedConverter.ofDDC_ofProgramOn_smul_ofAutomaton +#print axioms SystemAlgebra.TypedConverter.ofProgram_smul_ofAutomaton +#print axioms SystemAlgebra.TypedConverter.ofPreservingProgram_smul_ofAutomaton -- Sources, contexts and automata. -#print axioms SystemAlgebra.Interface.Resource.source +#print axioms SystemAlgebra.TypedSystem.source #print axioms SystemAlgebra.Interface.stateAfter_sourceStep -#print axioms SystemAlgebra.Interface.rightContext -#print axioms SystemAlgebra.Interface.attach_rightContext -#print axioms SystemAlgebra.Interface.filter +#print axioms SystemAlgebra.TypedConverter.rightContext +#print axioms SystemAlgebra.TypedConverter.attach_rightContext +#print axioms SystemAlgebra.TypedConverter.filter -- Obligation lemmas. #print axioms SystemAlgebra.DSL.sampleWitness diff --git a/src/Tests/DSL/Semantics.lean b/src/Tests/DSL/Semantics.lean index 78c3fea..1953355 100644 --- a/src/Tests/DSL/Semantics.lean +++ b/src/Tests/DSL/Semantics.lean @@ -104,8 +104,8 @@ lemma freshBits_independent {q : ℕ} (bs : List Bool) (hq : bs.length ≤ q) : have hb : 1 ≤ FreshBits.bound := FreshBits.bound_spec none .bit () [] ⟨(), ()⟩ (Program.consistent_nil FreshBits.body none _ _) (by simp [FreshBits.body, callProg]) have hK : bs.length ≤ FreshBits.bound * q := hq.trans (Nat.le_mul_of_pos_left q hb) - rw [FreshBits, FreshBits.randomness, FreshBits.program, Resource.source, - Converter.ofProgram_smul_ofAutomaton, Resource.ofAutomaton_mass, + rw [FreshBits, FreshBits.randomness, FreshBits.program, TypedSystem.source, + TypedConverter.ofProgram_smul_ofAutomaton, TypedSystem.ofAutomaton_mass, Distribution.mass_fTransform, Distribution.mass_fTransform, ← mass_prefix bs hK] refine Distribution.mass_congr _ fun t => ?_ simp only [List.map_map, Function.comp_def] @@ -129,8 +129,8 @@ lemma secretBit_combine_later {K : ℕ} (v : Bool) (r : (Fin K → Bool) × ℕ) /-- Sampling at initialization retains the same bit on later calls, at every budget. -/ lemma secretBit_retained (q : ℕ) (b : Bool) : (SecretBit (budget := q)).1 [(⟨.bit, ()⟩, ⟨.bit, b⟩), (⟨.bit, ()⟩, ⟨.bit, !b⟩)] = 0 := by - rw [SecretBit, SecretBit.randomness, SecretBit.program, Resource.source, - Converter.ofProgram_smul_ofAutomaton, Resource.ofAutomaton_mass, + rw [SecretBit, SecretBit.randomness, SecretBit.program, TypedSystem.source, + TypedConverter.ofProgram_smul_ofAutomaton, TypedSystem.ofAutomaton_mass, Distribution.mass_fTransform, Distribution.mass_fTransform] refine Distribution.mass_eq_zero_of_forall_not _ fun t hr => ?_ have hr := replies_filterDom _ _ hr @@ -149,7 +149,7 @@ lemma secretBit_retained (q : ℕ) (b : Bool) : lemma counter_interleaving {q : ℕ} (hq : 3 ≤ q) : (Counter (budget := q)).1 [(⟨.next, ()⟩, ⟨.next, 1⟩), (⟨.read, ()⟩, ⟨.read, 1⟩), (⟨.next, ()⟩, ⟨.next, 2⟩)] = 1 := by - rw [Counter, Interface.Resource.ofAutomaton_mass] + rw [Counter, TypedSystem.ofAutomaton_mass] refine (Distribution.mass_single _ _ _).trans (if_pos ?_) change Replies _ ([] ++ [(⟨.next, ()⟩ : Sigma Counter.Input)] ++ [⟨.read, ()⟩] ++ [⟨.next, ()⟩]) ([] ++ [(⟨.next, 1⟩ : Sigma Counter.Output)] ++ [⟨.read, 1⟩] ++ [⟨.next, 2⟩]) @@ -165,7 +165,7 @@ def counterBudget : Counter.Port → ℕ lemma counter_perPort_interleaving : (Counter.perPort (budget := counterBudget)).1 [(⟨.next, ()⟩, ⟨.next, 1⟩), (⟨.read, ()⟩, ⟨.read, 1⟩), (⟨.next, ()⟩, ⟨.next, 2⟩)] = 1 := by - rw [Counter.perPort, Interface.Resource.ofAutomaton_mass] + rw [Counter.perPort, TypedSystem.ofAutomaton_mass] refine (Distribution.mass_single _ _ _).trans (if_pos ?_) change Replies _ ([] ++ [(⟨.next, ()⟩ : Sigma Counter.Input)] ++ [⟨.read, ()⟩] ++ [⟨.next, ()⟩]) ([] ++ [(⟨.next, 1⟩ : Sigma Counter.Output)] ++ [⟨.read, 1⟩] ++ [⟨.next, 2⟩]) @@ -177,7 +177,7 @@ lemma counter_perPort_interleaving : lemma counter_perPort_exceeded (n m : Fin 16) : (Counter.perPort (budget := counterBudget)).1 [(⟨.read, ()⟩, ⟨.read, n⟩), (⟨.read, ()⟩, ⟨.read, m⟩)] = 0 := by - rw [Counter.perPort, Interface.Resource.ofAutomaton_mass] + rw [Counter.perPort, TypedSystem.ofAutomaton_mass] refine (Distribution.mass_single _ _ _).trans (if_neg fun hr => ?_) change Replies _ ([] ++ [(⟨.read, ()⟩ : Sigma Counter.Input)] ++ [⟨.read, ()⟩]) ([] ++ [(⟨.read, n⟩ : Sigma Counter.Output)] ++ [⟨.read, m⟩]) at hr diff --git a/src/Tests/ResourceSpecification.lean b/src/Tests/ResourceSpecification.lean index e975cac..c047c83 100644 --- a/src/Tests/ResourceSpecification.lean +++ b/src/Tests/ResourceSpecification.lean @@ -15,23 +15,23 @@ open SystemAlgebra variable {A B C D : Interface} /-- Serial construction. -/ -example {α : A ⟶ B} {β : B ⟶ C} {R : Specification (Interface.Resource C)} - {S : Specification (Interface.Resource B)} {T : Specification (Interface.Resource A)} +example {α : A ⟶ B} {β : B ⟶ C} {R : Specification (TypedSystem C)} + {S : Specification (TypedSystem B)} {T : Specification (TypedSystem A)} (inner : Constructs β R S) (outer : Constructs α S T) : Constructs (α ≫ β) R T := inner.serial outer /-- Relaxing both endpoints by the same error. -/ -example {α : A ⟶ B} {R : Specification (Interface.Resource B)} - {S : Specification (Interface.Resource A)} +example {α : A ⟶ B} {R : Specification (TypedSystem B)} + {S : Specification (TypedSystem A)} (construction : Constructs α R S) (ε : ENNReal) : Constructs α (epsilonRelaxation ε R) (epsilonRelaxation ε S) := construction.epsilonRelaxation ε /-- Approximate serial construction adds the errors. -/ -example {α : A ⟶ B} {β : B ⟶ C} {R : Specification (Interface.Resource C)} - {S : Specification (Interface.Resource B)} {T : Specification (Interface.Resource A)} +example {α : A ⟶ B} {β : B ⟶ C} {R : Specification (TypedSystem C)} + {S : Specification (TypedSystem B)} {T : Specification (TypedSystem A)} {ε δ : ENNReal} (inner : ConstructsWithin β R S ε) (outer : ConstructsWithin α S T δ) : @@ -39,9 +39,9 @@ example {α : A ⟶ B} {β : B ⟶ C} {R : Specification (Interface.Resource C)} inner.serial outer /-- Parallel construction. -/ -example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (Interface.Resource B)} - {S : Specification (Interface.Resource A)} {T : Specification (Interface.Resource D)} - {U : Specification (Interface.Resource C)} +example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (TypedSystem B)} + {S : Specification (TypedSystem A)} {T : Specification (TypedSystem D)} + {U : Specification (TypedSystem C)} (left : Constructs α R S) (right : Constructs β T U) : Constructs (α ⊗ₘ β) (Specification.parallel R T) @@ -49,9 +49,9 @@ example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (Interface.Resource B)} left.parallel right /-- Approximate parallel construction adds the errors. -/ -example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (Interface.Resource B)} - {S : Specification (Interface.Resource A)} {T : Specification (Interface.Resource D)} - {U : Specification (Interface.Resource C)} {ε δ : ENNReal} +example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (TypedSystem B)} + {S : Specification (TypedSystem A)} {T : Specification (TypedSystem D)} + {U : Specification (TypedSystem C)} {ε δ : ENNReal} (left : ConstructsWithin α R S ε) (right : ConstructsWithin β T U δ) : ConstructsWithin (α ⊗ₘ β) (Specification.parallel R T) @@ -59,8 +59,8 @@ example {α : A ⟶ B} {β : C ⟶ D} {R : Specification (Interface.Resource B)} left.parallel right /-- Closure under a class of converters that commute with the constructing one. -/ -example {π : End A} {converters : EndoFamily A} {R S : Specification (Interface.Resource A)} - (commutes : ∀ σ : End A, σ.op ∈ converters → ∀ T : Interface.Resource A, +example {π : End A} {converters : EndoFamily A} {R S : Specification (TypedSystem A)} + (commutes : ∀ σ : End A, σ.op ∈ converters → ∀ T : TypedSystem A, attach π (attach σ T) = attach σ (attach π T)) (construction : Constructs π R S) : @@ -68,9 +68,9 @@ example {π : End A} {converters : EndoFamily A} {R S : Specification (Interface Constructs.star commutes construction /-- Approximate construction is preserved by the same closure. -/ -example {π : End A} {converters : EndoFamily A} {R S : Specification (Interface.Resource A)} +example {π : End A} {converters : EndoFamily A} {R S : Specification (TypedSystem A)} {ε : ENNReal} - (commutes : ∀ σ : End A, σ.op ∈ converters → ∀ T : Interface.Resource A, + (commutes : ∀ σ : End A, σ.op ∈ converters → ∀ T : TypedSystem A, attach π (attach σ T) = attach σ (attach π T)) (construction : ConstructsWithin π R S ε) : diff --git a/src/Tests/Substitution/Axioms.lean b/src/Tests/Substitution/Axioms.lean index dc9c27b..29d2fd3 100644 --- a/src/Tests/Substitution/Axioms.lean +++ b/src/Tests/Substitution/Axioms.lean @@ -45,11 +45,11 @@ open SystemAlgebra SystemAlgebra.Substitution #print axioms resourceDDC_isDDCFrom #print axioms apply_resourceDDC #print axioms discardSystem_isDDCFrom -#print axioms SystemAlgebra.Interface.attach_resourceConverter -#print axioms SystemAlgebra.Interface.resource_empty_eq -#print axioms SystemAlgebra.Interface.attach_constant -#print axioms SystemAlgebra.Interface.attach_rightContext -#print axioms SystemAlgebra.Interface.attach_leftContext +#print axioms SystemAlgebra.TypedConverter.attach_ofSystem +#print axioms SystemAlgebra.TypedSystem.empty_eq +#print axioms SystemAlgebra.TypedConverter.attach_constant +#print axioms SystemAlgebra.TypedConverter.attach_rightContext +#print axioms SystemAlgebra.TypedConverter.attach_leftContext #print axioms singleSubstitutionRelaxation_parallelCompatible #print axioms SubstitutionExamples.unrestricted_diagonal