| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Equational reasoning for monoids |
| 5 |
-- (Utilities for identity and cancellation reasoning, extending semigroup reasoning) |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Algebra.Bundles using (Monoid) |
| 11 |
open import Function using (_∘_) |
| 12 |
|
| 13 |
module Algebra.Properties.Monoid {o ℓ} (M : Monoid o ℓ) where |
| 14 |
|
| 15 |
open Monoid M |
| 16 |
using (Carrier; _∙_; _≈_; setoid; isMagma; semigroup; ε; sym; identityˡ |
| 17 |
; identityʳ ; ∙-cong; refl; assoc; ∙-congˡ; ∙-congʳ; trans) |
| 18 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 19 |
|
| 20 |
open import Algebra.Properties.Semigroup semigroup public |
| 21 |
|
| 22 |
private |
| 23 |
variable |
| 24 |
a b c d : Carrier |
| 25 |
|
| 26 |
ε-unique : ∀ a → (∀ b → b ∙ a ≈ b) → a ≈ ε |
| 27 |
ε-unique a b∙a≈b = trans (sym (identityˡ a)) (b∙a≈b ε) |
| 28 |
|
| 29 |
ε-comm : ∀ a → a ∙ ε ≈ ε ∙ a |
| 30 |
ε-comm a = trans (identityʳ a) (sym (identityˡ a)) |
| 31 |
|
| 32 |
module _ (a≈ε : a ≈ ε) where |
| 33 |
elimʳ : ∀ b → b ∙ a ≈ b |
| 34 |
elimʳ = trans (∙-congˡ a≈ε) ∘ identityʳ |
| 35 |
|
| 36 |
elimˡ : ∀ b → a ∙ b ≈ b |
| 37 |
elimˡ = trans (∙-congʳ a≈ε) ∘ identityˡ |
| 38 |
|
| 39 |
introʳ : ∀ b → b ≈ b ∙ a |
| 40 |
introʳ = sym ∘ elimʳ |
| 41 |
|
| 42 |
introˡ : ∀ b → b ≈ a ∙ b |
| 43 |
introˡ = sym ∘ elimˡ |
| 44 |
|
| 45 |
introᶜ : ∀ c → b ∙ c ≈ b ∙ (a ∙ c) |
| 46 |
introᶜ c = trans (∙-congˡ (sym (identityˡ c))) (∙-congˡ (∙-congʳ (sym a≈ε))) |
| 47 |
|
| 48 |
module _ (inv : a ∙ c ≈ ε) where |
| 49 |
|
| 50 |
cancelʳ : ∀ b → (b ∙ a) ∙ c ≈ b |
| 51 |
cancelʳ b = trans (uv≈w⇒xu∙v≈xw inv b) (identityʳ b) |
| 52 |
|
| 53 |
cancelˡ : ∀ b → a ∙ (c ∙ b) ≈ b |
| 54 |
cancelˡ b = trans (uv≈w⇒u∙vx≈wx inv b) (identityˡ b) |
| 55 |
|
| 56 |
insertˡ : ∀ b → b ≈ a ∙ (c ∙ b) |
| 57 |
insertˡ = sym ∘ cancelˡ |
| 58 |
|
| 59 |
insertʳ : ∀ b → b ≈ (b ∙ a) ∙ c |
| 60 |
insertʳ = sym ∘ cancelʳ |
| 61 |
|
| 62 |
cancelᶜ : ∀ b d → (b ∙ a) ∙ (c ∙ d) ≈ b ∙ d |
| 63 |
cancelᶜ b d = trans (uv≈w⇒xu∙vy≈x∙wy inv b d) (∙-congˡ (identityˡ d)) |
| 64 |
|
| 65 |
insertᶜ : ∀ b d → b ∙ d ≈ (b ∙ a) ∙ (c ∙ d) |
| 66 |
insertᶜ = λ b d → sym (cancelᶜ b d) |
| 67 |
|