Skip to content

Commit c5538a8

Browse files
jamesmckinnaandreasabel
authored andcommitted
Pointwise Algebra (#2381)
* Pointwise `Algebra` * temporary commit * better `CHANGELOG` entry? * begin removing redundant `module` implementation * finish removing redundant `module` implementation * make `liftRel` implicitly quantified
1 parent 85d1a6b commit c5538a8

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ Deprecated names
7878
New modules
7979
-----------
8080

81+
* Pointwise lifting of algebraic structures `IsX` and bundles `X` from
82+
carrier set `C` to function space `A → C`:
83+
```
84+
Algebra.Construct.Pointwise
85+
```
86+
8187
* Raw bundles for module-like algebraic structures:
8288
```
8389
Algebra.Module.Bundles.Raw

src/Algebra/Construct/Pointwise.agda

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- For each `IsX` algebraic structure `S`, lift the structure to the
5+
-- 'pointwise' function space `A → S`: categorically, this is the
6+
-- *power* object in the relevant category of `X` objects and morphisms
7+
--
8+
-- NB the module is parametrised only wrt `A`
9+
------------------------------------------------------------------------
10+
11+
{-# OPTIONS --cubical-compatible --safe #-}
12+
13+
module Algebra.Construct.Pointwise {a} (A : Set a) where
14+
15+
open import Algebra.Bundles
16+
open import Algebra.Core using (Op₁; Op₂)
17+
open import Algebra.Structures
18+
open import Data.Product.Base using (_,_)
19+
open import Function.Base using (id; _∘′_; const)
20+
open import Level
21+
open import Relation.Binary.Core using (Rel)
22+
open import Relation.Binary.Bundles using (Setoid)
23+
open import Relation.Binary.Structures using (IsEquivalence)
24+
25+
26+
private
27+
28+
variable
29+
c ℓ : Level
30+
C : Set c
31+
_≈_ : Rel C ℓ
32+
ε 0# 1# : C
33+
_⁻¹ -_ : Op₁ C
34+
_∙_ _+_ _*_ : Op₂ C
35+
36+
lift₀ : C A C
37+
lift₀ = const
38+
39+
lift₁ : Op₁ C Op₁ (A C)
40+
lift₁ = _∘′_
41+
42+
lift₂ : Op₂ C Op₂ (A C)
43+
lift₂ _∙_ g h x = (g x) ∙ (h x)
44+
45+
liftRel : Rel C ℓ Rel (A C) (a ⊔ ℓ)
46+
liftRel _≈_ g h = {x} (g x) ≈ (h x)
47+
48+
49+
------------------------------------------------------------------------
50+
-- Setoid structure: here rather than elsewhere? (could be imported?)
51+
52+
isEquivalence : IsEquivalence _≈_ IsEquivalence (liftRel _≈_)
53+
isEquivalence isEquivalence = record
54+
{ refl = λ {f x} refl {f x}
55+
; sym = λ f≈g sym f≈g
56+
; trans = λ f≈g g≈h trans f≈g g≈h
57+
}
58+
where open IsEquivalence isEquivalence
59+
60+
------------------------------------------------------------------------
61+
-- Structures
62+
63+
isMagma : IsMagma _≈_ _∙_ IsMagma (liftRel _≈_) (lift₂ _∙_)
64+
isMagma isMagma = record
65+
{ isEquivalence = isEquivalence M.isEquivalence
66+
; ∙-cong = λ g h M.∙-cong g h
67+
}
68+
where module M = IsMagma isMagma
69+
70+
isSemigroup : IsSemigroup _≈_ _∙_ IsSemigroup (liftRel _≈_) (lift₂ _∙_)
71+
isSemigroup isSemigroup = record
72+
{ isMagma = isMagma M.isMagma
73+
; assoc = λ f g h M.assoc (f _) (g _) (h _)
74+
}
75+
where module M = IsSemigroup isSemigroup
76+
77+
isBand : IsBand _≈_ _∙_ IsBand (liftRel _≈_) (lift₂ _∙_)
78+
isBand isBand = record
79+
{ isSemigroup = isSemigroup M.isSemigroup
80+
; idem = λ f M.idem (f _)
81+
}
82+
where module M = IsBand isBand
83+
84+
isCommutativeSemigroup : IsCommutativeSemigroup _≈_ _∙_
85+
IsCommutativeSemigroup (liftRel _≈_) (lift₂ _∙_)
86+
isCommutativeSemigroup isCommutativeSemigroup = record
87+
{ isSemigroup = isSemigroup M.isSemigroup
88+
; comm = λ f g M.comm (f _) (g _)
89+
}
90+
where module M = IsCommutativeSemigroup isCommutativeSemigroup
91+
92+
isMonoid : IsMonoid _≈_ _∙_ ε IsMonoid (liftRel _≈_) (lift₂ _∙_) (lift₀ ε)
93+
isMonoid isMonoid = record
94+
{ isSemigroup = isSemigroup M.isSemigroup
95+
; identity = (λ f M.identityˡ (f _)) , λ f M.identityʳ (f _)
96+
}
97+
where module M = IsMonoid isMonoid
98+
99+
isCommutativeMonoid : IsCommutativeMonoid _≈_ _∙_ ε
100+
IsCommutativeMonoid (liftRel _≈_) (lift₂ _∙_) (lift₀ ε)
101+
isCommutativeMonoid isCommutativeMonoid = record
102+
{ isMonoid = isMonoid M.isMonoid
103+
; comm = λ f g M.comm (f _) (g _)
104+
}
105+
where module M = IsCommutativeMonoid isCommutativeMonoid
106+
107+
isGroup : IsGroup _≈_ _∙_ ε _⁻¹
108+
IsGroup (liftRel _≈_) (lift₂ _∙_) (lift₀ ε) (lift₁ _⁻¹)
109+
isGroup isGroup = record
110+
{ isMonoid = isMonoid M.isMonoid
111+
; inverse = (λ f M.inverseˡ (f _)) , λ f M.inverseʳ (f _)
112+
; ⁻¹-cong = λ f M.⁻¹-cong f
113+
}
114+
where module M = IsGroup isGroup
115+
116+
isAbelianGroup : IsAbelianGroup _≈_ _∙_ ε _⁻¹
117+
IsAbelianGroup (liftRel _≈_) (lift₂ _∙_) (lift₀ ε) (lift₁ _⁻¹)
118+
isAbelianGroup isAbelianGroup = record
119+
{ isGroup = isGroup M.isGroup
120+
; comm = λ f g M.comm (f _) (g _)
121+
}
122+
where module M = IsAbelianGroup isAbelianGroup
123+
124+
isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _≈_ _+_ _*_ 0# 1#
125+
IsSemiringWithoutAnnihilatingZero (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
126+
isSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero = record
127+
{ +-isCommutativeMonoid = isCommutativeMonoid M.+-isCommutativeMonoid
128+
; *-cong = λ g h M.*-cong g h
129+
; *-assoc = λ f g h M.*-assoc (f _) (g _) (h _)
130+
; *-identity = (λ f M.*-identityˡ (f _)) , λ f M.*-identityʳ (f _)
131+
; distrib = (λ f g h M.distribˡ (f _) (g _) (h _)) , λ f g h M.distribʳ (f _) (g _) (h _)
132+
}
133+
where module M = IsSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero
134+
135+
isSemiring : IsSemiring _≈_ _+_ _*_ 0# 1#
136+
IsSemiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
137+
isSemiring isSemiring = record
138+
{ isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero M.isSemiringWithoutAnnihilatingZero
139+
; zero = (λ f M.zeroˡ (f _)) , λ f M.zeroʳ (f _)
140+
}
141+
where module M = IsSemiring isSemiring
142+
143+
isRing : IsRing _≈_ _+_ _*_ -_ 0# 1#
144+
IsRing (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₁ -_) (lift₀ 0#) (lift₀ 1#)
145+
isRing isRing = record
146+
{ +-isAbelianGroup = isAbelianGroup M.+-isAbelianGroup
147+
; *-cong = λ g h M.*-cong g h
148+
; *-assoc = λ f g h M.*-assoc (f _) (g _) (h _)
149+
; *-identity = (λ f M.*-identityˡ (f _)) , λ f M.*-identityʳ (f _)
150+
; distrib = (λ f g h M.distribˡ (f _) (g _) (h _)) , λ f g h M.distribʳ (f _) (g _) (h _)
151+
}
152+
where module M = IsRing isRing
153+
154+
155+
------------------------------------------------------------------------
156+
-- Bundles
157+
158+
magma : Magma c ℓ Magma (a ⊔ c) (a ⊔ ℓ)
159+
magma m = record { isMagma = isMagma (Magma.isMagma m) }
160+
161+
semigroup : Semigroup c ℓ Semigroup (a ⊔ c) (a ⊔ ℓ)
162+
semigroup m = record { isSemigroup = isSemigroup (Semigroup.isSemigroup m) }
163+
164+
band : Band c ℓ Band (a ⊔ c) (a ⊔ ℓ)
165+
band m = record { isBand = isBand (Band.isBand m) }
166+
167+
commutativeSemigroup : CommutativeSemigroup c ℓ CommutativeSemigroup (a ⊔ c) (a ⊔ ℓ)
168+
commutativeSemigroup m = record { isCommutativeSemigroup = isCommutativeSemigroup (CommutativeSemigroup.isCommutativeSemigroup m) }
169+
170+
monoid : Monoid c ℓ Monoid (a ⊔ c) (a ⊔ ℓ)
171+
monoid m = record { isMonoid = isMonoid (Monoid.isMonoid m) }
172+
173+
group : Group c ℓ Group (a ⊔ c) (a ⊔ ℓ)
174+
group m = record { isGroup = isGroup (Group.isGroup m) }
175+
176+
abelianGroup : AbelianGroup c ℓ AbelianGroup (a ⊔ c) (a ⊔ ℓ)
177+
abelianGroup m = record { isAbelianGroup = isAbelianGroup (AbelianGroup.isAbelianGroup m) }
178+
179+
semiring : Semiring c ℓ Semiring (a ⊔ c) (a ⊔ ℓ)
180+
semiring m = record { isSemiring = isSemiring (Semiring.isSemiring m) }
181+
182+
ring : Ring c ℓ Ring (a ⊔ c) (a ⊔ ℓ)
183+
ring m = record { isRing = isRing (Ring.isRing m) }
184+

0 commit comments

Comments
 (0)