| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Algebraic properties of sums (disjoint unions) |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Sum.Algebra where |
| 10 |
|
| 11 |
open import Algebra.Bundles |
| 12 |
using (Magma; Semigroup; Monoid; CommutativeMonoid) |
| 13 |
open import Algebra.Definitions |
| 14 |
using (Associative; LeftIdentity; RightIdentity; Identity) |
| 15 |
open import Algebra.Structures |
| 16 |
using (IsMagma; IsSemigroup; IsMonoid; IsCommutativeMonoid) |
| 17 |
open import Data.Empty.Polymorphic using (⊥) |
| 18 |
open import Data.Product.Base using (_,_) |
| 19 |
open import Data.Sum.Base using (_⊎_; inj₁; inj₂; map; [_,_]; swap; assocʳ; assocˡ) |
| 20 |
open import Data.Sum.Properties using (swap-involutive) |
| 21 |
open import Data.Unit.Polymorphic.Base using (⊤; tt) |
| 22 |
open import Function.Base using (id; _∘_) |
| 23 |
open import Function.Properties.Inverse using (↔-isEquivalence) |
| 24 |
open import Function.Bundles using (_↔_; Inverse; mk↔ₛ′) |
| 25 |
open import Level using (Level; suc) |
| 26 |
open import Relation.Binary.PropositionalEquality.Core |
| 27 |
using (_≡_; refl; cong; cong′) |
| 28 |
|
| 29 |
import Function.Definitions as FuncDef |
| 30 |
|
| 31 |
------------------------------------------------------------------------ |
| 32 |
-- Setup |
| 33 |
|
| 34 |
private |
| 35 |
variable |
| 36 |
a b c d : Level |
| 37 |
A B C D : Set a |
| 38 |
|
| 39 |
♯ : {B : ⊥ {a} → Set b} → (w : ⊥) → B w |
| 40 |
♯ () |
| 41 |
|
| 42 |
------------------------------------------------------------------------ |
| 43 |
-- Algebraic properties |
| 44 |
|
| 45 |
⊎-cong : A ↔ B → C ↔ D → (A ⊎ C) ↔ (B ⊎ D) |
| 46 |
⊎-cong i j = mk↔ₛ′ (map I.to J.to) (map I.from J.from) |
| 47 |
[ cong inj₁ ∘ I.strictlyInverseˡ , cong inj₂ ∘ J.strictlyInverseˡ ] |
| 48 |
[ cong inj₁ ∘ I.strictlyInverseʳ , cong inj₂ ∘ J.strictlyInverseʳ ] |
| 49 |
where module I = Inverse i; module J = Inverse j |
| 50 |
|
| 51 |
-- ⊎ is commutative. |
| 52 |
-- We don't use Commutative because it isn't polymorphic enough. |
| 53 |
⊎-comm : (A : Set a) (B : Set b) → (A ⊎ B) ↔ (B ⊎ A) |
| 54 |
⊎-comm _ _ = mk↔ₛ′ swap swap swap-involutive swap-involutive |
| 55 |
|
| 56 |
module _ (ℓ : Level) where |
| 57 |
|
| 58 |
-- ⊎ is associative |
| 59 |
⊎-assoc : Associative {ℓ = ℓ} _↔_ _⊎_ |
| 60 |
⊎-assoc _ _ _ = mk↔ₛ′ assocʳ assocˡ |
| 61 |
[ cong′ , [ cong′ , cong′ ] ] [ [ cong′ , cong′ ] , cong′ ] |
| 62 |
|
| 63 |
-- ⊥ is an identity for ⊎ |
| 64 |
⊎-identityˡ : LeftIdentity {ℓ = ℓ} _↔_ ⊥ _⊎_ |
| 65 |
⊎-identityˡ A = mk↔ₛ′ [ ♯ , id ] inj₂ cong′ [ ♯ , cong′ ] |
| 66 |
|
| 67 |
⊎-identityʳ : RightIdentity {ℓ = ℓ} _↔_ ⊥ _⊎_ |
| 68 |
⊎-identityʳ _ = mk↔ₛ′ [ id , ♯ ] inj₁ cong′ [ cong′ , ♯ ] |
| 69 |
|
| 70 |
⊎-identity : Identity _↔_ ⊥ _⊎_ |
| 71 |
⊎-identity = ⊎-identityˡ , ⊎-identityʳ |
| 72 |
|
| 73 |
------------------------------------------------------------------------ |
| 74 |
-- Algebraic structures |
| 75 |
|
| 76 |
⊎-isMagma : IsMagma {ℓ = ℓ} _↔_ _⊎_ |
| 77 |
⊎-isMagma = record |
| 78 |
{ isEquivalence = ↔-isEquivalence |
| 79 |
; ∙-cong = ⊎-cong |
| 80 |
} |
| 81 |
|
| 82 |
⊎-isSemigroup : IsSemigroup _↔_ _⊎_ |
| 83 |
⊎-isSemigroup = record |
| 84 |
{ isMagma = ⊎-isMagma |
| 85 |
; assoc = ⊎-assoc |
| 86 |
} |
| 87 |
|
| 88 |
⊎-isMonoid : IsMonoid _↔_ _⊎_ ⊥ |
| 89 |
⊎-isMonoid = record |
| 90 |
{ isSemigroup = ⊎-isSemigroup |
| 91 |
; identity = ⊎-identityˡ , ⊎-identityʳ |
| 92 |
} |
| 93 |
|
| 94 |
⊎-isCommutativeMonoid : IsCommutativeMonoid _↔_ _⊎_ ⊥ |
| 95 |
⊎-isCommutativeMonoid = record |
| 96 |
{ isMonoid = ⊎-isMonoid |
| 97 |
; comm = ⊎-comm |
| 98 |
} |
| 99 |
|
| 100 |
------------------------------------------------------------------------ |
| 101 |
-- Algebraic bundles |
| 102 |
|
| 103 |
⊎-magma : Magma (suc ℓ) ℓ |
| 104 |
⊎-magma = record |
| 105 |
{ isMagma = ⊎-isMagma |
| 106 |
} |
| 107 |
|
| 108 |
⊎-semigroup : Semigroup (suc ℓ) ℓ |
| 109 |
⊎-semigroup = record |
| 110 |
{ isSemigroup = ⊎-isSemigroup |
| 111 |
} |
| 112 |
|
| 113 |
⊎-monoid : Monoid (suc ℓ) ℓ |
| 114 |
⊎-monoid = record |
| 115 |
{ isMonoid = ⊎-isMonoid |
| 116 |
} |
| 117 |
|
| 118 |
⊎-commutativeMonoid : CommutativeMonoid (suc ℓ) ℓ |
| 119 |
⊎-commutativeMonoid = record |
| 120 |
{ isCommutativeMonoid = ⊎-isCommutativeMonoid |
| 121 |
} |