| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Definition of algebraic structures we get from freely adding an |
| 5 |
-- identity element |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
module Algebra.Construct.Add.Identity where |
| 11 |
|
| 12 |
open import Algebra.Bundles using (Semigroup; Monoid) |
| 13 |
open import Algebra.Core using (Op₂) |
| 14 |
open import Algebra.Definitions |
| 15 |
using (Congruent₂; Associative; LeftIdentity; RightIdentity; Identity) |
| 16 |
open import Algebra.Structures using (IsMagma; IsSemigroup; IsMonoid) |
| 17 |
open import Data.Product.Base using (_,_) |
| 18 |
open import Level using (Level; _⊔_) |
| 19 |
open import Relation.Binary.Construct.Add.Point.Equality renaming (_≈∙_ to lift≈) |
| 20 |
open import Relation.Binary.Core using (Rel) |
| 21 |
open import Relation.Binary.Definitions using (Reflexive) |
| 22 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 23 |
open import Relation.Nullary.Construct.Add.Point using (Pointed; [_]; ∙) |
| 24 |
|
| 25 |
private |
| 26 |
variable |
| 27 |
a ℓ : Level |
| 28 |
A : Set a |
| 29 |
|
| 30 |
liftOp : Op₂ A → Op₂ (Pointed A) |
| 31 |
liftOp op [ p ] [ q ] = [ op p q ] |
| 32 |
liftOp _ [ p ] ∙ = [ p ] |
| 33 |
liftOp _ ∙ [ q ] = [ q ] |
| 34 |
liftOp _ ∙ ∙ = ∙ |
| 35 |
|
| 36 |
module _ {_≈_ : Rel A ℓ} {op : Op₂ A} (refl-≈ : Reflexive _≈_) where |
| 37 |
private |
| 38 |
_≈∙_ = lift≈ _≈_ |
| 39 |
op∙ = liftOp op |
| 40 |
|
| 41 |
lift-≈ : ∀ {x y : A} → x ≈ y → [ x ] ≈∙ [ y ] |
| 42 |
lift-≈ = [_] |
| 43 |
|
| 44 |
cong₂ : Congruent₂ _≈_ op → Congruent₂ _≈∙_ (op∙) |
| 45 |
cong₂ R-cong [ eq-l ] [ eq-r ] = lift-≈ (R-cong eq-l eq-r) |
| 46 |
cong₂ R-cong [ eq ] ∙≈∙ = lift-≈ eq |
| 47 |
cong₂ R-cong ∙≈∙ [ eq ] = lift-≈ eq |
| 48 |
cong₂ R-cong ∙≈∙ ∙≈∙ = ≈∙-refl _≈_ refl-≈ |
| 49 |
|
| 50 |
assoc : Associative _≈_ op → Associative _≈∙_ (op∙) |
| 51 |
assoc assoc [ p ] [ q ] [ r ] = lift-≈ (assoc p q r) |
| 52 |
assoc _ [ p ] [ q ] ∙ = ≈∙-refl _≈_ refl-≈ |
| 53 |
assoc _ [ p ] ∙ [ r ] = ≈∙-refl _≈_ refl-≈ |
| 54 |
assoc _ [ p ] ∙ ∙ = ≈∙-refl _≈_ refl-≈ |
| 55 |
assoc _ ∙ [ r ] [ q ] = ≈∙-refl _≈_ refl-≈ |
| 56 |
assoc _ ∙ [ q ] ∙ = ≈∙-refl _≈_ refl-≈ |
| 57 |
assoc _ ∙ ∙ [ r ] = ≈∙-refl _≈_ refl-≈ |
| 58 |
assoc _ ∙ ∙ ∙ = ≈∙-refl _≈_ refl-≈ |
| 59 |
|
| 60 |
identityˡ : LeftIdentity _≈∙_ ∙ (op∙) |
| 61 |
identityˡ [ p ] = ≈∙-refl _≈_ refl-≈ |
| 62 |
identityˡ ∙ = ≈∙-refl _≈_ refl-≈ |
| 63 |
|
| 64 |
identityʳ : RightIdentity _≈∙_ ∙ (op∙) |
| 65 |
identityʳ [ p ] = ≈∙-refl _≈_ refl-≈ |
| 66 |
identityʳ ∙ = ≈∙-refl _≈_ refl-≈ |
| 67 |
|
| 68 |
identity : Identity _≈∙_ ∙ (op∙) |
| 69 |
identity = identityˡ , identityʳ |
| 70 |
|
| 71 |
module _ {_≈_ : Rel A ℓ} {op : Op₂ A} where |
| 72 |
private |
| 73 |
_≈∙_ = lift≈ _≈_ |
| 74 |
op∙ = liftOp op |
| 75 |
|
| 76 |
isMagma : IsMagma _≈_ op → IsMagma _≈∙_ op∙ |
| 77 |
isMagma M = |
| 78 |
record |
| 79 |
{ isEquivalence = ≈∙-isEquivalence _≈_ M.isEquivalence |
| 80 |
; ∙-cong = cong₂ M.refl M.∙-cong |
| 81 |
} where module M = IsMagma M |
| 82 |
|
| 83 |
isSemigroup : IsSemigroup _≈_ op → IsSemigroup _≈∙_ op∙ |
| 84 |
isSemigroup S = record |
| 85 |
{ isMagma = isMagma S.isMagma |
| 86 |
; assoc = assoc S.refl S.assoc |
| 87 |
} where module S = IsSemigroup S |
| 88 |
|
| 89 |
isMonoid : IsSemigroup _≈_ op → IsMonoid _≈∙_ op∙ ∙ |
| 90 |
isMonoid S = record |
| 91 |
{ isSemigroup = isSemigroup S |
| 92 |
; identity = identity S.refl |
| 93 |
} where module S = IsSemigroup S |
| 94 |
|
| 95 |
semigroup : Semigroup a (a ⊔ ℓ) → Semigroup a (a ⊔ ℓ) |
| 96 |
semigroup S = record |
| 97 |
{ Carrier = Pointed S.Carrier |
| 98 |
; isSemigroup = isSemigroup S.isSemigroup |
| 99 |
} where module S = Semigroup S |
| 100 |
|
| 101 |
monoid : Semigroup a (a ⊔ ℓ) → Monoid a (a ⊔ ℓ) |
| 102 |
monoid S = record |
| 103 |
{ isMonoid = isMonoid S.isSemigroup |
| 104 |
} where module S = Semigroup S |
| 105 |
|