Skip to content

Commit 7d25de8

Browse files
committed
Add Monoid (and related) for Construct.Add.Point (agda#845)
1 parent 6a0baaa commit 7d25de8

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ Deprecated names
772772
New modules
773773
-----------
774774

775+
* Algebraic structures when freely adding an identity element:
776+
```
777+
Algebra.Construct.Add.Identity
778+
```
779+
775780
* Operations for module-like algebraic structures:
776781
```
777782
Algebra.Module.Core
@@ -942,6 +947,11 @@ New modules
942947
Other minor changes
943948
-------------------
944949

950+
* Added new proof to `Data.Maybe.Properties`
951+
```agda
952+
<∣>-idem : Idempotent _<∣>_
953+
```
954+
945955
* The module `Algebra` now publicly re-exports the contents of
946956
`Algebra.Structures.Biased`.
947957

@@ -1939,4 +1949,4 @@ This is a full list of proofs that have changed form to use irrelevant instance
19391949
```agda
19401950
Inverse⇒Injection : Inverse S T → Injection S T
19411951
↔⇒↣ : A ↔ B → A ↣ B
1942-
```
1952+
```
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 --without-K --safe #-}
9+
10+
module Algebra.Construct.Add.Identity where
11+
12+
open import Algebra.Bundles
13+
open import Algebra.Core using (Op₂)
14+
open import Algebra.Definitions
15+
open import Algebra.Structures
16+
open import Data.Maybe.Relation.Binary.Pointwise
17+
open import Relation.Binary.Construct.Add.Point.Equality renaming (_≈∙_ to lift≈)
18+
open import Data.Product using (_,_)
19+
open import Level using (Level; _⊔_)
20+
open import Relation.Binary.Core
21+
open import Relation.Binary.Definitions
22+
open import Relation.Binary.Structures
23+
open import Relation.Nullary.Construct.Add.Point
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

0 commit comments

Comments
 (0)