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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
{-# OPTIONS --cubical-compatible #-}
module Class.Monoid.Instances where
 
open import Class.Prelude
open import Class.Setoid.Core
open import Class.Semigroup
open import Class.Monoid.Core
 
instance
Monoid-List : Monoid (List A)
Monoid-List .ε = []
 
MonoidLaws-List : MonoidLaws≡ (List A)
MonoidLaws-List .ε-identity = L.++-identityˡ , L.++-identityʳ
where import Data.List.Properties as L
 
Monoid-Vec : Monoid (∃ (Vec A))
Monoid-Vec .ε = 0 , []
 
Monoid-String : Monoid String
Monoid-String .ε = ""
 
module _ ⦃ _ : Semigroup A ⦄ ⦃ _ : Monoid A ⦄ where instance
Monoid-Maybe : Monoid (Maybe A)
Monoid-Maybe .ε = nothing
 
MonoidLaws-Maybe : ⦃ MonoidLaws≡ A ⦄ → MonoidLaws≡ (Maybe A)
MonoidLaws-Maybe .ε-identity = p , q
where open Alg≡
p = LeftIdentity ε _◇_ ∋ λ _ → refl
q = RightIdentity ε _◇_ ∋ λ where (just _) → refl; nothing → refl
 
module _ ⦃ _ : Semigroup A ⦄ ⦃ _ : Semigroup B ⦄ where instance
Monoid-× : ⦃ Monoid A ⦄ → ⦃ Monoid B ⦄ → Monoid (A × B)
Monoid-× .ε = ε , ε
 
MonoidLaws-× : ⦃ _ : Monoid A ⦄ ⦃ _ : Monoid B ⦄
→ ⦃ MonoidLaws≡ A ⦄ → ⦃ MonoidLaws≡ B ⦄
→ MonoidLaws≡ (A × B)
MonoidLaws-× = record {ε-identity = p , q}
where
open Alg≡
 
p : LeftIdentity (A × B ∋ ε) _◇_
p (a , b) rewrite ε-identityˡ≡ a | ε-identityˡ≡ b = refl
 
q : RightIdentity (A × B ∋ ε) _◇_
q (a , b) rewrite ε-identityʳ≡ a | ε-identityʳ≡ b = refl
 
-- ** natural numbers
module _ where
open import Data.Nat.Properties
module _ where
instance _ = Semigroup-ℕ-+
Monoid-ℕ-+ = Monoid ℕ ∋ λ where .ε → 0
instance _ = Monoid-ℕ-+
MonoidLaws-ℕ-+ = MonoidLaws≡ ℕ ∋ record {ε-identity = +-identityˡ , +-identityʳ}
module _ where
instance _ = Semigroup-ℕ-*
Monoid-ℕ-* = Monoid ℕ ∋ λ where .ε → 1
instance _ = Monoid-ℕ-*
MonoidLaws-ℕ-* = MonoidLaws≡ ℕ ∋ record {ε-identity = *-identityˡ , *-identityʳ}
 
-- ** natural numbers
module _ where
open import Data.Nat.Binary
open import Data.Nat.Binary.Properties
 
instance _ = Semigroup-ℕᵇ-+
Monoid-ℕᵇ-+ = Monoid ℕᵇ ∋ λ where .ε → zero
instance _ = Monoid-ℕᵇ-+
MonoidLaws-ℕᵇ-+ = MonoidLaws≡ ℕᵇ ∋ record {ε-identity = +-identityˡ , +-identityʳ}
 
-- ** integers
module _ where
open import Data.Integer.Properties
module _ where
instance _ = Semigroup-ℤ-+
Monoid-ℤ-+ = Monoid ℤ ∋ λ where .ε → 0ℤ
instance _ = Monoid-ℤ-+
MonoidLaws-ℤ-+ = MonoidLaws≡ ℤ ∋ record {ε-identity = +-identityˡ , +-identityʳ}
module _ where
instance _ = Semigroup-ℤ-*
Monoid-ℤ-* = Monoid ℤ ∋ λ where .ε → 1ℤ
instance _ = Monoid-ℤ-*
MonoidLaws-ℤ-* = MonoidLaws≡ ℤ ∋ record {ε-identity = *-identityˡ , *-identityʳ}
 
-- ** maybes
module _ ⦃ _ : Semigroup A ⦄ ⦃ _ : Monoid A ⦄ ⦃ _ : ISetoid A ⦄ ⦃ _ : MonoidLaws≡ A ⦄ (x : A) where
just-◇ˡ : ∀ (mx : Maybe A) →
just x ◇ mx ≡ just (x ◇ fromMaybe ε mx)
just-◇ˡ = λ where
(just _) → refl
nothing → cong just $ sym $ ε-identityʳ≡ x
 
just-◇ʳ : ∀ (mx : Maybe A) →
mx ◇ just x ≡ just (fromMaybe ε mx ◇ x)
just-◇ʳ = λ where
(just _) → refl
nothing → cong just $ sym $ ε-identityˡ≡ x