Skip to content

Commit a34b4b5

Browse files
committed
Add reasonining combinators for monoids
1 parent 490a28c commit a34b4b5

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

src/Algebra/Reasoning/Monoid.agda

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{-# OPTIONS --cubical-compatible --safe #-}
2+
3+
open import Algebra using (Monoid)
4+
5+
module Algebra.Reasoning.Monoid {o ℓ} (M : Monoid o ℓ) where
6+
7+
open Monoid M
8+
open import Relation.Binary.Reasoning.Setoid setoid
9+
open import Algebra.Reasoning.SemiGroup semigroup public
10+
11+
12+
module Identity {a : Carrier } where
13+
id-unique : ( b b ∙ a ≈ b) a ≈ ε
14+
id-unique b∙a≈b = begin
15+
a ≈⟨ sym (identityˡ a) ⟩
16+
ε ∙ a ≈⟨ b∙a≈b ε ⟩
17+
ε ∎
18+
19+
id-comm : a ∙ ε ≈ ε ∙ a
20+
id-comm = begin
21+
a ∙ ε ≈⟨ identityʳ a ⟩
22+
a ≈⟨ sym (identityˡ a)⟩
23+
ε ∙ a ∎
24+
25+
id-comm-sym : ε ∙ a ≈ a ∙ ε
26+
id-comm-sym = sym id-comm
27+
28+
open Identity public
29+
30+
module IntroElim {a b : Carrier} (a≈ε : a ≈ ε) where
31+
elimʳ : b ∙ a ≈ b
32+
elimʳ = begin
33+
b ∙ a ≈⟨ ∙-cong refl a≈ε ⟩
34+
b ∙ ε ≈⟨ identityʳ b ⟩
35+
b ∎
36+
37+
elimˡ : a ∙ b ≈ b
38+
elimˡ = begin
39+
a ∙ b ≈⟨ ∙-cong a≈ε refl ⟩
40+
ε ∙ b ≈⟨ identityˡ b ⟩
41+
b ∎
42+
43+
introʳ : a ≈ ε b ≈ b ∙ a
44+
introʳ a≈ε = sym elimʳ
45+
46+
introˡ : a ≈ ε b ≈ a ∙ b
47+
introˡ a≈ε = sym elimˡ
48+
49+
introcenter : c b ∙ c ≈ b ∙ (a ∙ c)
50+
introcenter c = begin
51+
b ∙ c ≈⟨ sym (∙-cong refl (identityˡ c)) ⟩
52+
b ∙ (ε ∙ c) ≈⟨ sym (∙-cong refl (∙-cong a≈ε refl)) ⟩
53+
b ∙ (a ∙ c) ∎
54+
55+
open IntroElim public
56+
57+
module Cancellers {a b c : Carrier} (inv : a ∙ c ≈ ε) where
58+
59+
cancelʳ : (b ∙ a) ∙ c ≈ b
60+
cancelʳ = begin
61+
(b ∙ a) ∙ c ≈⟨ assoc b a c ⟩
62+
b ∙ (a ∙ c) ≈⟨ ∙-cong refl inv ⟩
63+
b ∙ ε ≈⟨ identityʳ b ⟩
64+
b ∎
65+
66+
67+
cancelˡ : a ∙ (c ∙ b) ≈ b
68+
cancelˡ = begin
69+
a ∙ (c ∙ b) ≈⟨ sym (assoc a c b) ⟩
70+
(a ∙ c) ∙ b ≈⟨ ∙-cong inv refl ⟩
71+
ε ∙ b ≈⟨ identityˡ b ⟩
72+
b ∎
73+
74+
insertˡ : b ≈ a ∙ (c ∙ b)
75+
insertˡ = sym cancelˡ
76+
77+
insertʳ : b ≈ (b ∙ a) ∙ c
78+
insertʳ = sym cancelʳ
79+
80+
cancelInner : {g} (b ∙ a) ∙ (c ∙ g) ≈ b ∙ g
81+
cancelInner {g = g} = begin
82+
(b ∙ a) ∙ (c ∙ g) ≈⟨ sym (assoc (b ∙ a) c g) ⟩
83+
((b ∙ a) ∙ c) ∙ g ≈⟨ ∙-cong cancelʳ refl ⟩
84+
b ∙ g ∎
85+
86+
insertInner : {g} b ∙ g ≈ (b ∙ a) ∙ (c ∙ g)
87+
insertInner = sym cancelInner

0 commit comments

Comments
 (0)