Modules

categorical-crypto

  • Prelude

CategoricalCrypto

  • CategoricalCrypto
  • Abstract
  • Abstract2
  • Abstract2.Equivalence
  • Abstract2.Morphism
  • Abstract2.OAPEmulation
  • Abstract2.WideSubcategory
  • Channel.Category
  • Channel.Core
  • Channel.Selection
  • Examples.Basic
  • Examples.Commitment
  • Examples.RelSetup
  • Examples.Signatures
  • FamilyCategory
  • Machine.Constraints
  • Machine.Core
  • MachineAxioms
  • RandomOracle
  • RandomOracle2
  • SFunM
  • Standard
  • Standard2
  • Standard2.Morphism
  • StandardTV
  • UCSetup
  • UCSetup.Morphism
  • VanishingTV

Categories

  • Actegory
  • Actegory.Underlying
  • Category.EquivClosureHelper
  • Coherence.Monoidal
  • Coherence.Monoidal.Compare
  • Coherence.Monoidal.Diagram
  • Coherence.Monoidal.Frontend
  • Coherence.Monoidal.Frontend.Core
  • Coherence.Monoidal.Frontend.Sigma
  • Coherence.Monoidal.MacLane
  • Coherence.Monoidal.Normalize
  • Coherence.Monoidal.Reflect
  • Coherence.Monoidal.Sigma
  • Coherence.Monoidal.Test.Frontend
  • Coherence.Monoidal.Test.InterchangeStress
  • Coherence.Monoidal.Test.Limitations
  • Coherence.Monoidal.Test.SigmaFrontend
  • Coherence.Monoidal.WireCoherence
  • CoherenceIsos
  • Diagram.Coend.Ext.Setoids
  • Discrete
  • FreeMonoidal
  • FreeStrictMonoidal
  • Functor.Monoidal.CurriedTensor
  • Functor.Monoidal.CurriedTensor.Properties
  • Functor.Monoidal.Properties.Ext
  • Functor.Presheaf.Morphism
  • GradedKleisli
  • GradedKleisli.Functorial
  • GradedKleisli.Functorial.Category
  • GradedKleisli.Regrade
  • KernelCongruence
  • KernelCongruence.Reindex
  • LocallyGraded
  • LocallyGraded.FreeActegory
  • LocallyGraded.FreeActegory.Kleisli
  • LocallyGraded.Kleisli
  • Monad.Graded.Ext
  • Monad.Graded.Morphism
  • Monad.Graded.Pullback
  • Monad.Graded.Uncurried
  • Morphism.Reasoning.Ext
  • NaturalTransformationHelper
  • Properties

Class

  • Monad.Ext

Data

  • List.Properties.Ext
  • Maybe.Ext
  • Nat.Poly

LibExt

  • LibExt
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
------------------------------------------------------------------------
-- The Agda standard library
--
-- Maybes where one of the elements satisfies a given property
------------------------------------------------------------------------
 
{-# OPTIONS --cubical-compatible --safe #-}
 
module Data.Maybe.Relation.Unary.Any where
 
open import Data.Maybe.Base using (Maybe; just; nothing)
open import Data.Product.Base as Product using (∃; _,_; -,_)
open import Function.Base using (id)
open import Function.Bundles using (_⇔_; mk⇔)
open import Level using (Level; _⊔_)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; cong)
open import Relation.Unary
using (Pred; _⊆_; _∩_; Decidable; Irrelevant; Satisfiable)
open import Relation.Nullary.Decidable as Dec using (Dec; yes; no)
 
------------------------------------------------------------------------
-- Definition
 
data Any {a p} {A : Set a} (P : Pred A p) : Pred (Maybe A) (a ⊔ p) where
just : ∀ {x} → P x → Any P (just x)
 
------------------------------------------------------------------------
-- Basic operations
 
module _ {a p} {A : Set a} {P : Pred A p} where
 
drop-just : ∀ {x} → Any P (just x) → P x
drop-just (just px) = px
 
just-equivalence : ∀ {x} → P x ⇔ Any P (just x)
just-equivalence = mk⇔ just drop-just
 
map : ∀ {q} {Q : Pred A q} → P ⊆ Q → Any P ⊆ Any Q
map f (just px) = just (f px)
 
satisfied : ∀ {x} → Any P x → ∃ P
satisfied (just p) = -, p
 
------------------------------------------------------------------------
-- (un/)zip(/With)
 
module _ {a p q r} {A : Set a} {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
 
zipWith : P ∩ Q ⊆ R → Any P ∩ Any Q ⊆ Any R
zipWith f (just px , just qx) = just (f (px , qx))
 
unzipWith : P ⊆ Q ∩ R → Any P ⊆ Any Q ∩ Any R
unzipWith f (just px) = Product.map just just (f px)
 
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
 
zip : Any P ∩ Any Q ⊆ Any (P ∩ Q)
zip = zipWith id
 
unzip : Any (P ∩ Q) ⊆ Any P ∩ Any Q
unzip = unzipWith id
 
------------------------------------------------------------------------
-- Seeing Any as a predicate transformer
 
module _ {a p} {A : Set a} {P : Pred A p} where
 
dec : Decidable P → Decidable (Any P)
dec P-dec nothing = no λ ()
dec P-dec (just x) = Dec.map just-equivalence (P-dec x)
 
irrelevant : Irrelevant P → Irrelevant (Any P)
irrelevant P-irrelevant (just p) (just q) = cong just (P-irrelevant p q)
 
satisfiable : Satisfiable P → Satisfiable (Any P)
satisfiable P-satisfiable = Product.map just just P-satisfiable