diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b10f1a54e..4e7c3f333d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,6 +186,10 @@ New modules Additions to existing modules ----------------------------- +* In `Algebra.Properties.Monoid` adding consequences for identity for monoids + +* In `Algebra.Properties.Semigroup` adding consequences for associativity for semigroups + * In `Algebra.Consequences.Base`: ```agda module Congruence (_≈_ : Rel A ℓ) (cong : Congruent₂ _≈_ _∙_) (refl : Reflexive _≈_) diff --git a/src/Algebra/Properties/Monoid.agda b/src/Algebra/Properties/Monoid.agda new file mode 100644 index 0000000000..0f54092c51 --- /dev/null +++ b/src/Algebra/Properties/Monoid.agda @@ -0,0 +1,70 @@ +------------------------------------------------------------------------ +-- The Agda standard library +-- +-- Equational reasoning for monoids +-- (Utilities for identity and cancellation reasoning, extending semigroup reasoning) +------------------------------------------------------------------------ + +{-# OPTIONS --cubical-compatible --safe #-} + +open import Algebra.Bundles using (Monoid) +open import Function using (_∘_) + +module Algebra.Properties.Monoid {o ℓ} (M : Monoid o ℓ) where + +open Monoid M + using (Carrier; _∙_; _≈_; setoid; isMagma; semigroup; ε; sym; identityˡ + ; identityʳ ; ∙-cong; refl; assoc; ∙-congˡ; ∙-congʳ; trans) +open import Relation.Binary.Reasoning.Setoid setoid + +open import Algebra.Properties.Semigroup semigroup public + +private + variable + a b c d : Carrier + +id-unique : ∀ a → (∀ b → b ∙ a ≈ b) → a ≈ ε +id-unique a b∙a≈b = trans (sym (identityˡ a)) (b∙a≈b ε) + +id-comm : ∀ a → a ∙ ε ≈ ε ∙ a +id-comm a = trans (identityʳ a) (sym (identityˡ a)) + +id-comm-sym : ∀ a → ε ∙ a ≈ a ∙ ε +id-comm-sym = sym ∘ id-comm + +module _ (a≈ε : a ≈ ε) where + elimʳ : ∀ b → b ∙ a ≈ b + elimʳ = trans (∙-congˡ a≈ε) ∘ identityʳ + + elimˡ : ∀ b → a ∙ b ≈ b + elimˡ = trans (∙-congʳ a≈ε) ∘ identityˡ + + introʳ : ∀ b → b ≈ b ∙ a + introʳ = sym ∘ elimʳ + + introˡ : ∀ b → b ≈ a ∙ b + introˡ = sym ∘ elimˡ + + introcenter : ∀ c → b ∙ c ≈ b ∙ (a ∙ c) + introcenter c = trans (∙-congˡ (sym (identityˡ c))) (∙-congˡ (∙-congʳ (sym a≈ε))) + +module _ (inv : a ∙ c ≈ ε) where + + cancelʳ : ∀ b → (b ∙ a) ∙ c ≈ b + cancelʳ b = trans (uv≈w⇒xu∙v≈xw inv b) (identityʳ b) + + cancelˡ : ∀ b → a ∙ (c ∙ b) ≈ b + cancelˡ b = trans (uv≈w⇒u∙vx≈wx inv b) (identityˡ b) + + insertˡ : ∀ b → b ≈ a ∙ (c ∙ b) + insertˡ = sym ∘ cancelˡ + + insertʳ : ∀ b → b ≈ (b ∙ a) ∙ c + insertʳ = sym ∘ cancelʳ + + cancelInner : ∀ b d → (b ∙ a) ∙ (c ∙ d) ≈ b ∙ d + cancelInner b d = trans (uv≈w⇒xu∙vy≈x∙wy inv b d) (∙-congˡ (identityˡ d)) + + insertInner : ∀ b d → b ∙ d ≈ (b ∙ a) ∙ (c ∙ d) + insertInner = λ b d → sym (cancelInner b d) +