Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0fc076f
Adds reasonig combinator for semigroup
jmougeot Apr 1, 2025
3399c61
Adds reasonig combinator for semigroup
jmougeot Apr 1, 2025
90fe273
Adds reasonig combinator for semigroup
jmougeot Apr 1, 2025
ef3282f
Adds reasonig combinator for semigroup
jmougeot Apr 1, 2025
63e88cc
Add some more missing reasoning combinators
jmougeot Apr 1, 2025
bb7ce15
add module Extends
jmougeot Apr 1, 2025
885d7a0
rename SemiGroup to Semigroup
jmougeot Apr 1, 2025
ad54a5b
fix-whitespace
jmougeot Apr 1, 2025
2b511c2
Update CHANGELOG.md
jmougeot Apr 2, 2025
8151123
New names
jmougeot Apr 3, 2025
2361b40
improve syntx
jmougeot Apr 3, 2025
503c693
fix-whitespace
jmougeot Apr 3, 2025
0d5c9ed
Name changes
jmougeot Apr 7, 2025
1a67eb9
Names change
jmougeot Apr 7, 2025
002cfad
Space
jmougeot Apr 7, 2025
a47bcc5
Proof of assoc with PUshes and Pulles
jmougeot Apr 8, 2025
ca9f576
Proof of assoc with PUshes and Pulles
jmougeot Apr 8, 2025
e07f81b
white space
jmougeot Apr 9, 2025
86b06e0
Update src/Algebra/Properties/Semigroup/Reasoning.agda
jmougeot Apr 10, 2025
7b72ff2
Reasoning to Semigroup and explicit variables
jmougeot Apr 11, 2025
13b5f0e
fix bug
jmougeot Apr 11, 2025
f58aceb
space
jmougeot Apr 11, 2025
74607d5
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
e3b2550
Update CHANGELOG.md
jmougeot Apr 14, 2025
e63afbd
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
b2bfa03
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
14224b9
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
76b6637
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
06af327
Update src/Algebra/Properties/Semigroup.agda
jmougeot Apr 14, 2025
a22f97d
variables
jmougeot Apr 14, 2025
1283b57
update CHANGELOG
jmougeot Apr 16, 2025
e1304da
Explicit varaibles
jmougeot Apr 29, 2025
a8c515f
remove white space
jmougeot May 26, 2025
f290a2a
update Changelog and minor improvments
jmougeot Jun 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ New modules

* `Data.Sign.Show` to show a sign

* `Algebra.Reasoning.Semigroup` adding reasoning combinators for semigroups

Additions to existing modules
-----------------------------

Expand Down
157 changes: 157 additions & 0 deletions src/Algebra/Reasoning/Semigroup.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Equational reasoning for semigroups
-- (Utilities for associativity reasoning, pulling and pushing operations)
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

open import Algebra using (Semigroup)

module Algebra.Reasoning.Semigroup {o ℓ} (S : Semigroup o ℓ) where

open Semigroup S
using (Carrier; _∙_; _≈_; setoid; trans ; refl; sym; assoc; ∙-cong)
open import Relation.Binary.Reasoning.Setoid setoid

private
variable
a b c d e x y z : Carrier

module Assoc4 {a b c d : Carrier} where
{-
Explanation of naming scheme:

Each successive association is given a Greek letter, from 'α' associated all
the way to the left, to 'ε' associated all the way to the right. Then,
'assoc²XY' is the proof that X is equal to Y. Explicitly:

α = ((a ∙ b) ∙ c) ∙ d
β = (a ∙ (b ∙ c)) ∙ d
γ = (a ∙ b) ∙ (c ∙ d)
δ = a ∙ ((b ∙ c) ∙ d)
ε = a ∙ (b ∙ (c ∙ d))

Only reassociations that need two assoc steps are defined here.
-}
assoc²αδ : ((a ∙ b) ∙ c) ∙ d ≈ a ∙ ((b ∙ c) ∙ d)
assoc²αδ = trans (∙-cong (assoc a b c) refl) (assoc a (b ∙ c) d)

assoc²αε : ((a ∙ b) ∙ c) ∙ d ≈ a ∙ (b ∙ (c ∙ d))
assoc²αε = trans (assoc (a ∙ b) c d) (assoc a b (c ∙ d))

assoc²βγ : (a ∙ (b ∙ c)) ∙ d ≈ (a ∙ b) ∙ (c ∙ d)
assoc²βγ = trans (sym (∙-cong (assoc a b c) refl)) (assoc (a ∙ b) c d)

assoc²βε : (a ∙ (b ∙ c)) ∙ d ≈ a ∙ (b ∙ (c ∙ d))
assoc²βε = trans (assoc a (b ∙ c) d) (∙-cong refl (assoc b c d))

assoc²γβ : (a ∙ b) ∙ (c ∙ d) ≈ (a ∙ (b ∙ c)) ∙ d
assoc²γβ = trans (sym (assoc (a ∙ b) c d)) (∙-cong (assoc a b c) refl)

assoc²γδ : (a ∙ b) ∙ (c ∙ d) ≈ a ∙ ((b ∙ c) ∙ d)
assoc²γδ = begin
(a ∙ b) ∙ (c ∙ d) ≈⟨ assoc a b (c ∙ d) ⟩
a ∙ (b ∙ (c ∙ d)) ≈⟨ ∙-cong refl (sym (assoc b c d)) ⟩
a ∙ ((b ∙ c) ∙ d) ∎

assoc²δα : a ∙ ((b ∙ c) ∙ d) ≈ ((a ∙ b) ∙ c) ∙ d
assoc²δα = sym (trans (∙-cong (assoc a b c) refl) (assoc a (b ∙ c) d))

assoc²δγ : a ∙ ((b ∙ c) ∙ d) ≈ (a ∙ b) ∙ (c ∙ d)
assoc²δγ = begin
a ∙ ((b ∙ c) ∙ d) ≈⟨ ∙-cong refl (assoc b c d) ⟩
a ∙ (b ∙ (c ∙ d)) ≈⟨ sym (assoc a b (c ∙ d)) ⟩
(a ∙ b) ∙ (c ∙ d) ∎

assoc²εα : a ∙ (b ∙ (c ∙ d)) ≈ ((a ∙ b) ∙ c) ∙ d
assoc²εα = sym (trans (assoc (a ∙ b) c d) (assoc a b (c ∙ d)))

assoc²εβ : a ∙ (b ∙ (c ∙ d)) ≈ (a ∙ (b ∙ c)) ∙ d
assoc²εβ = sym (trans (assoc a (b ∙ c) d) (∙-cong refl (assoc b c d)))

open Assoc4 public

module Pulls (ab≡c : a ∙ b ≈ c) where
pullʳ : ∀ {x} → (x ∙ a) ∙ b ≈ x ∙ c
pullʳ {x = x} = begin
(x ∙ a) ∙ b ≈⟨ assoc x a b ⟩
x ∙ (a ∙ b) ≈⟨ ∙-cong refl ab≡c ⟩
x ∙ c ∎

pullˡ : ∀ {x} → a ∙ (b ∙ x) ≈ c ∙ x
pullˡ {x = x} = begin
a ∙ (b ∙ x) ≈⟨ sym (assoc a b x) ⟩
(a ∙ b) ∙ x ≈⟨ ∙-cong ab≡c refl ⟩
c ∙ x ∎

pull-first : ∀ {x y} → a ∙ ((b ∙ x) ∙ y) ≈ c ∙ (x ∙ y)
pull-first {x = x} {y = y} = begin
a ∙ ((b ∙ x) ∙ y) ≈⟨ ∙-cong refl (assoc b x y) ⟩
a ∙ (b ∙ (x ∙ y)) ≈⟨ pullˡ ⟩
c ∙ (x ∙ y) ∎

pull-center : ∀ {x y} → x ∙ (a ∙ (b ∙ y)) ≈ x ∙ (c ∙ y)
pull-center {x = x} {y = y} = ∙-cong refl (pullˡ)

-- could be called pull₃ʳ
pull-last : ∀ {x y} → (x ∙ (y ∙ a)) ∙ b ≈ x ∙ (y ∙ c)
pull-last {x = x} {y = y} = begin
(x ∙ (y ∙ a)) ∙ b ≈⟨ assoc x (y ∙ a) b ⟩
x ∙ ((y ∙ a) ∙ b) ≈⟨ ∙-cong refl (pullʳ {x = y}) ⟩
x ∙ (y ∙ c) ∎

open Pulls public

module Pushes (ab≡c : a ∙ b ≈ c) where
pushʳ : x ∙ c ≈ (x ∙ a) ∙ b
pushʳ {x = x} = begin
x ∙ c ≈⟨ sym (∙-cong refl ab≡c) ⟩
x ∙ (a ∙ b) ≈⟨ sym (assoc x a b) ⟩
(x ∙ a) ∙ b ∎

pushˡ : c ∙ x ≈ a ∙ (b ∙ x)
pushˡ {x = x} = begin
c ∙ x ≈⟨ sym (∙-cong ab≡c refl) ⟩
(a ∙ b) ∙ x ≈⟨ assoc a b x ⟩
a ∙ (b ∙ x) ∎
open Pushes public

-- operate in the 'center' instead (like pull/push)
center : a ∙ b ≈ c → (d ∙ a) ∙ (b ∙ e) ≈ d ∙ (c ∙ e)
center eq = pullʳ (pullˡ eq)

-- operate on the left part, then the right part
center⁻¹ : a ∙ b ≈ c → x ∙ y ≈ z → a ∙ ((b ∙ x) ∙ y) ≈ c ∙ z
center⁻¹ {a = a} {b = b} {c = c} {x = x} {y = y} {z = z} eq eq′ = begin
a ∙ ((b ∙ x) ∙ y) ≈⟨ ∙-cong refl (pullʳ eq′) ⟩
a ∙ (b ∙ z) ≈⟨ pullˡ eq ⟩
c ∙ z ∎

push-center : a ∙ b ≈ c → x ∙ (c ∙ y) ≈ x ∙ (a ∙ (b ∙ y))
push-center eq = sym (pull-center eq)

module Extends {a b c d : Carrier} (s : a ∙ b ≈ c ∙ d) where
-- rewrite (x ∙ a) ∙ b to (x ∙ c) ∙ d
extendˡ : (x ∙ a) ∙ b ≈ (x ∙ c) ∙ d
extendˡ {x = x} = begin
(x ∙ a) ∙ b ≈⟨ pullʳ s ⟩
x ∙ (c ∙ d) ≈⟨ sym (assoc x c d) ⟩
(x ∙ c) ∙ d ∎

-- rewrite a ∙ (b ∙ x) to c ∙ (d ∙ x)
extendʳ : a ∙ (b ∙ x) ≈ c ∙ (d ∙ x)
extendʳ {x = x} = begin
a ∙ (b ∙ x) ≈⟨ pullˡ s ⟩
(c ∙ d) ∙ x ≈⟨ assoc c d x ⟩
c ∙ (d ∙ x) ∎

-- rewrite (x ∙ a) ∙ (b ∙ y) to (x ∙ c) ∙ (d ∙ y)
extend² : ∀ x y → (x ∙ a) ∙ (b ∙ y) ≈ (x ∙ c) ∙ (d ∙ y)
extend² x y = begin
(x ∙ a) ∙ (b ∙ y) ≈⟨ pullʳ (extendʳ {x = y}) ⟩
x ∙ (c ∙ (d ∙ y)) ≈⟨ sym (assoc x c (d ∙ y)) ⟩
(x ∙ c) ∙ (d ∙ y) ∎

open Extends public