Derivatives for Containers in Univalent Foundations
Cubical.Data.Sum.Base
Initializing search
    phijor/derivatives
    • Overview
    • Library
    phijor/derivatives
    • Overview
      • Derivative.Bag
      • Derivative.Adjunction
      • Derivative.Basics.Sum
      • Derivative.Basics.Unit
      • Derivative.Basics.W
      • Derivative.Basics.Decidable
      • Derivative.Basics.Embedding
      • Derivative.Basics.Equiv
      • Derivative.Basics.Maybe
      • Derivative.Basics.Sigma
      • Derivative.Category
      • Derivative.ChainRule
      • Derivative.Container
      • Derivative.Derivative
      • Derivative.Indexed.Mu
      • Derivative.Indexed.ChainRule
      • Derivative.Indexed.Container
      • Derivative.Indexed.Derivative
      • Derivative.Indexed.MuRule
      • Derivative.Indexed.Univalence
      • Derivative.Isolated.Base
      • Derivative.Isolated
      • Derivative.Isolated.S1
      • Derivative.Isolated.Sum
      • Derivative.Isolated.W
      • Derivative.Isolated.DependentGrafting
      • Derivative.Isolated.Grafting
      • Derivative.Isolated.Maybe
      • Derivative.Isolated.Sigma
      • Derivative.Prelude
      • Derivative.Properties
      • Derivative.Remove

    Cubical.Data.Sum.Base

    module Cubical.Data.Sum.Base where
    
    open import Cubical.Relation.Nullary.Base
    
    open import Cubical.Foundations.Prelude
    
    private
      variable
        ℓ ℓ' : Level
        A B C D : Type ℓ
    
    data _⊎_ (A : Type ℓ)(B : Type ℓ') : Type (ℓ-max ℓ ℓ') where
      inl : A → A ⊎ B
      inr : B → A ⊎ B
    
    rec : {C : Type ℓ} → (A → C) → (B → C) → A ⊎ B → C
    rec f _ (inl x) = f x
    rec _ g (inr y) = g y
    
    elim : {C : A ⊎ B → Type ℓ} →  ((a : A) → C (inl a)) → ((b : B) → C (inr b))
           → (x : A ⊎ B) → C x
    elim f _ (inl x) = f x
    elim _ g (inr y) = g y
    
    map : (A → C) → (B → D) → A ⊎ B → C ⊎ D
    map f _ (inl x) = inl (f x)
    map _ g (inr y) = inr (g y)
    
    _⊎?_ : {P Q : Type ℓ} → Dec P → Dec Q → Dec (P ⊎ Q)
    P? ⊎? Q? with P? | Q?
    ... | yes p | _ = yes (inl p)
    ... | no _  | yes q = yes (inr q)
    ... | no ¬p | no ¬q  = no λ
      { (inl p) → ¬p p
      ; (inr q) → ¬q q
      }
    
    Made with Material for MkDocs