-
Notifications
You must be signed in to change notification settings - Fork 256
[Add] Consequences of associativity for Semigroup
s
#2688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 3399c61
Adds reasonig combinator for semigroup
jmougeot 90fe273
Adds reasonig combinator for semigroup
jmougeot ef3282f
Adds reasonig combinator for semigroup
jmougeot 63e88cc
Add some more missing reasoning combinators
jmougeot bb7ce15
add module Extends
jmougeot 885d7a0
rename SemiGroup to Semigroup
jmougeot ad54a5b
fix-whitespace
jmougeot 2b511c2
Update CHANGELOG.md
jmougeot 8151123
New names
jmougeot 2361b40
improve syntx
jmougeot 503c693
fix-whitespace
jmougeot 0d5c9ed
Name changes
jmougeot 1a67eb9
Names change
jmougeot 002cfad
Space
jmougeot a47bcc5
Proof of assoc with PUshes and Pulles
jmougeot ca9f576
Proof of assoc with PUshes and Pulles
jmougeot e07f81b
white space
jmougeot 86b06e0
Update src/Algebra/Properties/Semigroup/Reasoning.agda
jmougeot 7b72ff2
Reasoning to Semigroup and explicit variables
jmougeot 13b5f0e
fix bug
jmougeot f58aceb
space
jmougeot 74607d5
Update src/Algebra/Properties/Semigroup.agda
jmougeot e3b2550
Update CHANGELOG.md
jmougeot e63afbd
Update src/Algebra/Properties/Semigroup.agda
jmougeot b2bfa03
Update src/Algebra/Properties/Semigroup.agda
jmougeot 14224b9
Update src/Algebra/Properties/Semigroup.agda
jmougeot 76b6637
Update src/Algebra/Properties/Semigroup.agda
jmougeot 06af327
Update src/Algebra/Properties/Semigroup.agda
jmougeot a22f97d
variables
jmougeot 1283b57
update CHANGELOG
jmougeot e1304da
Explicit varaibles
jmougeot a8c515f
remove white space
jmougeot f290a2a
update Changelog and minor improvments
jmougeot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
module Algebra.Reasoning.Semigroup {o ℓ} (S : Semigroup o ℓ) where | ||
|
||
open Semigroup S | ||
using (Carrier; _∙_; _≈_; setoid; trans ; refl; sym; assoc; ∙-cong) | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pullʳ {x = x} = begin | ||
(x ∙ a) ∙ b ≈⟨ assoc x a b ⟩ | ||
x ∙ (a ∙ b) ≈⟨ ∙-cong refl ab≡c ⟩ | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
x ∙ c ∎ | ||
|
||
pullˡ : ∀ {x} → a ∙ (b ∙ x) ≈ c ∙ x | ||
pullˡ {x = x} = begin | ||
a ∙ (b ∙ x) ≈⟨ sym (assoc a b x) ⟩ | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(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₃ʳ | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pushʳ {x = x} = begin | ||
x ∙ c ≈⟨ sym (∙-cong refl ab≡c) ⟩ | ||
x ∙ (a ∙ b) ≈⟨ sym (assoc x a b) ⟩ | ||
(x ∙ a) ∙ b ∎ | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.