-
Notifications
You must be signed in to change notification settings - Fork 248
[Add] Consequences of identity for monoids
#2692
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
base: master
Are you sure you want to change the base?
Changes from 30 commits
0fc076f
3399c61
90fe273
ef3282f
63e88cc
bb7ce15
885d7a0
ad54a5b
2b511c2
8151123
2361b40
503c693
0d5c9ed
1a67eb9
002cfad
a47bcc5
ca9f576
e07f81b
86b06e0
7b72ff2
13b5f0e
f58aceb
f8ab744
4cb6076
6d6a494
0a36d34
c0ea255
b874357
6381e8d
ec1030c
74607d5
e3b2550
e63afbd
b2bfa03
14224b9
76b6637
06af327
a22f97d
c9487ef
f0e0101
9926a29
11a54eb
f1335e6
821fdf3
f964914
08688ea
9711485
a8aa378
1c788a0
bbf6645
1260c29
1ae1e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,68 @@ | ||||||||||||||||||||||
------------------------------------------------------------------------ | ||||||||||||||||||||||
-- 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) | ||||||||||||||||||||||
|
||||||||||||||||||||||
module Algebra.Properties.Monoid.Reasoning {o ℓ} (M : Monoid o ℓ) where | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As usual: these lemmas belong in By all means do initial development in that style before raising a PR, or else mark it as |
||||||||||||||||||||||
|
||||||||||||||||||||||
open Monoid M | ||||||||||||||||||||||
using (Carrier; _∙_; _≈_; setoid; isMagma; semigroup; ε; sym; identityˡ | ||||||||||||||||||||||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
; identityʳ ; ∙-cong; refl; assoc; ∙-congˡ; ∙-congʳ; trans) | ||||||||||||||||||||||
open import Relation.Binary.Reasoning.Setoid setoid | ||||||||||||||||||||||
open import Algebra.Properties.Semigroup.Reasoning semigroup public | ||||||||||||||||||||||
|
||||||||||||||||||||||
JacquesCarette marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
module Identity {a : Carrier } where | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... So that there is no need here for either the implicit module scope, the module name, or even the declaration of any module at all! |
||||||||||||||||||||||
id-unique : (∀ b → b ∙ a ≈ b) → a ≈ ε | ||||||||||||||||||||||
id-unique b∙a≈b = trans (sym (identityˡ a)) (b∙a≈b ε) | ||||||||||||||||||||||
|
||||||||||||||||||||||
id-comm : a ∙ ε ≈ ε ∙ a | ||||||||||||||||||||||
id-comm = trans (identityʳ a) (sym (identityˡ a)) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Against the above comment, this may need |
||||||||||||||||||||||
|
||||||||||||||||||||||
id-comm-sym : ε ∙ a ≈ a ∙ ε | ||||||||||||||||||||||
id-comm-sym = sym id-comm | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now think that these explicit symmetric forms are excessive/superfluous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It also happens when doing naive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, thanks for the insight. All of this seems only further evidence towards developing |
||||||||||||||||||||||
|
||||||||||||||||||||||
open Identity public | ||||||||||||||||||||||
|
||||||||||||||||||||||
module IntroElim {a b : Carrier} (a≈ε : a ≈ ε) where | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My instincts tell me:
|
||||||||||||||||||||||
elimʳ : b ∙ a ≈ b | ||||||||||||||||||||||
elimʳ = trans (∙-congˡ a≈ε) (identityʳ b) | ||||||||||||||||||||||
|
||||||||||||||||||||||
elimˡ : a ∙ b ≈ b | ||||||||||||||||||||||
elimˡ = trans (∙-congʳ a≈ε) (identityˡ b) | ||||||||||||||||||||||
|
||||||||||||||||||||||
introʳ : a ≈ ε → b ≈ b ∙ a | ||||||||||||||||||||||
introʳ a≈ε = sym elimʳ | ||||||||||||||||||||||
|
||||||||||||||||||||||
introˡ : a ≈ ε → b ≈ a ∙ b | ||||||||||||||||||||||
introˡ a≈ε = sym elimˡ | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argument
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
introcenter : ∀ c → b ∙ c ≈ b ∙ (a ∙ c) | ||||||||||||||||||||||
introcenter c = trans (∙-congˡ (sym (identityˡ c))) (∙-congˡ (∙-congʳ (sym a≈ε))) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should use a superscript There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meta: a good general point that, besides 'left' and 'right' (modulo collective mutual misunderstanding/inconsistency about what such conventions might even mean #2654 ), we don't have good heuristics about super-/sub-scripts and their intended semantics. I think I'd be happy with |
||||||||||||||||||||||
|
||||||||||||||||||||||
open IntroElim public | ||||||||||||||||||||||
|
||||||||||||||||||||||
module Cancellers {a b c : Carrier} (inv : a ∙ c ≈ ε) where | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implicits |
||||||||||||||||||||||
|
||||||||||||||||||||||
cancelʳ : (b ∙ a) ∙ c ≈ b | ||||||||||||||||||||||
cancelʳ = trans (assoc b a c) (trans (∙-congˡ inv) (identityʳ b)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
cancelˡ : a ∙ (c ∙ b) ≈ b | ||||||||||||||||||||||
cancelˡ = trans (sym (assoc a c b)) (trans (∙-congʳ inv) (identityˡ b)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
insertˡ : b ≈ a ∙ (c ∙ b) | ||||||||||||||||||||||
insertˡ = sym cancelˡ | ||||||||||||||||||||||
|
||||||||||||||||||||||
insertʳ : b ≈ (b ∙ a) ∙ c | ||||||||||||||||||||||
insertʳ = sym cancelʳ | ||||||||||||||||||||||
|
||||||||||||||||||||||
cancelInner : ∀ {g} → (b ∙ a) ∙ (c ∙ g) ≈ b ∙ g | ||||||||||||||||||||||
cancelInner {g = g} = trans (sym (assoc (b ∙ a) c g)) (∙-congʳ cancelʳ) | ||||||||||||||||||||||
|
||||||||||||||||||||||
insertInner : ∀ {g} → b ∙ g ≈ (b ∙ a) ∙ (c ∙ g) | ||||||||||||||||||||||
insertInner = sym cancelInner | ||||||||||||||||||||||
jmougeot marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,9 +10,15 @@ open import Algebra using (Semigroup) | |||||
|
||||||
module Algebra.Properties.Semigroup {a ℓ} (S : Semigroup a ℓ) where | ||||||
|
||||||
open import Data.Product.Base using (_,_) | ||||||
|
||||||
open Semigroup S | ||||||
open import Algebra.Definitions _≈_ | ||||||
open import Data.Product.Base using (_,_) | ||||||
open import Relation.Binary.Reasoning.Setoid setoid | ||||||
|
||||||
private | ||||||
variable | ||||||
u v w x y z : Carrier | ||||||
|
||||||
x∙yz≈xy∙z : ∀ x y z → x ∙ (y ∙ z) ≈ (x ∙ y) ∙ z | ||||||
x∙yz≈xy∙z x y z = sym (assoc x y z) | ||||||
|
@@ -28,3 +34,91 @@ alternative = alternativeˡ , alternativeʳ | |||||
|
||||||
flexible : Flexible _∙_ | ||||||
flexible x y = assoc x y x | ||||||
|
||||||
module _ (uv≈w : u ∙ v ≈ w) where | ||||||
uv≈w⇒xu∙v≈xw : ∀ x → (x ∙ u) ∙ v ≈ x ∙ w | ||||||
uv≈w⇒xu∙v≈xw x = trans (assoc x u v) (∙-congˡ uv≈w) | ||||||
|
||||||
uv≈w⇒u∙vx≈wx : ∀ x → u ∙ (v ∙ x) ≈ w ∙ x | ||||||
uv≈w⇒u∙vx≈wx x = trans (sym (assoc u v x)) (∙-congʳ uv≈w) | ||||||
|
||||||
uv≈w⇒u[vx∙y]≈w∙xy : ∀ x y → u ∙ ((v ∙ x) ∙ y) ≈ w ∙ (x ∙ y) | ||||||
uv≈w⇒u[vx∙y]≈w∙xy x y = trans (∙-congˡ (assoc v x y)) (uv≈w⇒u∙vx≈wx (x ∙ y)) | ||||||
|
||||||
uv≈w⇒x[uv∙y]≈x∙wy : ∀ x y → x ∙ (u ∙ (v ∙ y)) ≈ x ∙ (w ∙ y) | ||||||
uv≈w⇒x[uv∙y]≈x∙wy x y = ∙-congˡ (uv≈w⇒u∙vx≈wx y) | ||||||
|
||||||
uv≈w⇒[x∙yu]v≈x∙yw : ∀ x y → (x ∙ (y ∙ u)) ∙ v ≈ x ∙ (y ∙ w) | ||||||
uv≈w⇒[x∙yu]v≈x∙yw x y = trans (assoc x (y ∙ u) v) (∙-congˡ (uv≈w⇒xu∙v≈xw y)) | ||||||
|
||||||
uv≈w⇒[xu∙v]y≈x∙wy : ∀ x y → ((x ∙ u) ∙ v) ∙ y ≈ x ∙ (w ∙ y) | ||||||
uv≈w⇒[xu∙v]y≈x∙wy x y = trans (∙-congʳ (uv≈w⇒xu∙v≈xw x)) (assoc _ _ _) | ||||||
|
||||||
uv≈w⇒[xy∙u]v≈x∙yw : ∀ x y → ((x ∙ y) ∙ u) ∙ v ≈ x ∙ (y ∙ w) | ||||||
uv≈w⇒[xy∙u]v≈x∙yw x y = trans (∙-congʳ (assoc x y u)) (uv≈w⇒[x∙yu]v≈x∙yw x y ) | ||||||
|
||||||
module _ (uv≈w : u ∙ v ≈ w) where | ||||||
uv≈w⇒xw≈xu∙v : x ∙ w ≈ (x ∙ u) ∙ v | ||||||
uv≈w⇒xw≈xu∙v = sym (uv≈w⇒xu∙v≈xw uv≈w _) | ||||||
|
||||||
uv≈w⇒wx≈u∙vx : w ∙ x ≈ u ∙ (v ∙ x) | ||||||
uv≈w⇒wx≈u∙vx = sym (uv≈w⇒u∙vx≈wx uv≈w _) | ||||||
|
||||||
uv≈w⇒w∙xy≈u[vx∙y] : ∀ x y → w ∙ (x ∙ y) ≈ u ∙ ((v ∙ x) ∙ y) | ||||||
uv≈w⇒w∙xy≈u[vx∙y] x y = sym (uv≈w⇒u[vx∙y]≈w∙xy uv≈w x y) | ||||||
|
||||||
uv≈w⇒x∙wy≈x[u∙vy] : ∀ x y → x ∙ (w ∙ y) ≈ x ∙ (u ∙ (v ∙ y)) | ||||||
uv≈w⇒x∙wy≈x[u∙vy] x y = sym (uv≈w⇒x[uv∙y]≈x∙wy uv≈w x y) | ||||||
|
||||||
uv≈w⇒x∙yw≈[x∙yu]v : ∀ x y → x ∙ (y ∙ w) ≈ (x ∙ (y ∙ u)) ∙ v | ||||||
uv≈w⇒x∙yw≈[x∙yu]v x y = sym (uv≈w⇒[x∙yu]v≈x∙yw uv≈w x y) | ||||||
|
||||||
uv≈w⇒xu∙vy≈x∙wy : (x ∙ u) ∙ (v ∙ y) ≈ x ∙ (w ∙ y) | ||||||
uv≈w⇒xu∙vy≈x∙wy = uv≈w⇒xu∙v≈xw (uv≈w⇒u∙vx≈wx uv≈w _) _ | ||||||
|
||||||
uv≈w⇒xy≈z⇒u[vx∙y]≈wz : ∀ z → x ∙ y ≈ z → u ∙ ((v ∙ x) ∙ y) ≈ w ∙ z | ||||||
uv≈w⇒xy≈z⇒u[vx∙y]≈wz z xy≈z = trans (∙-congˡ (uv≈w⇒xu∙v≈xw xy≈z v)) (uv≈w⇒u∙vx≈wx uv≈w z) | ||||||
|
||||||
uv≈w⇒x∙wy≈x∙[u∙vy] : x ∙ (w ∙ y) ≈ x ∙ (u ∙ (v ∙ y)) | ||||||
uv≈w⇒x∙wy≈x∙[u∙vy] = sym (uv≈w⇒x[uv∙y]≈x∙wy uv≈w _ _) | ||||||
|
||||||
module _ {u v w x : Carrier} where | ||||||
[uv∙w]x≈u[vw∙x] : ((u ∙ v) ∙ w) ∙ x ≈ u ∙ ((v ∙ w) ∙ x) | ||||||
[uv∙w]x≈u[vw∙x] = uv≈w⇒[xu∙v]y≈x∙wy refl u x | ||||||
|
||||||
[uv∙w]x≈u[v∙wx] : ((u ∙ v) ∙ w) ∙ x ≈ u ∙ (v ∙ (w ∙ x)) | ||||||
[uv∙w]x≈u[v∙wx] = uv≈w⇒[xy∙u]v≈x∙yw refl u v | ||||||
|
||||||
[u∙vw]x≈uv∙wx : (u ∙ (v ∙ w)) ∙ x ≈ (u ∙ v) ∙ (w ∙ x) | ||||||
[u∙vw]x≈uv∙wx = trans (sym (∙-congʳ (assoc u v w))) (assoc (u ∙ v) w x) | ||||||
|
||||||
[u∙vw]x≈u[v∙wx] : (u ∙ (v ∙ w)) ∙ x ≈ u ∙ (v ∙ (w ∙ x)) | ||||||
[u∙vw]x≈u[v∙wx] = uv≈w⇒[x∙yu]v≈x∙yw refl u v | ||||||
|
||||||
uv∙wx≈u[vw∙x] : (u ∙ v) ∙ (w ∙ x) ≈ u ∙ ((v ∙ w) ∙ x) | ||||||
uv∙wx≈u[vw∙x] = uv≈w⇒xu∙vy≈x∙wy refl | ||||||
|
||||||
uv∙wx≈[u∙vw]x : (u ∙ v) ∙ (w ∙ x) ≈ (u ∙ (v ∙ w)) ∙ x | ||||||
uv∙wx≈[u∙vw]x = sym [u∙vw]x≈uv∙wx | ||||||
|
||||||
u[vw∙x]≈[uv∙w]x : u ∙ ((v ∙ w) ∙ x) ≈ ((u ∙ v) ∙ w) ∙ x | ||||||
u[vw∙x]≈[uv∙w]x = sym [uv∙w]x≈u[vw∙x] | ||||||
|
||||||
u[vw∙x]≈uv∙wx : u ∙ ((v ∙ w) ∙ x) ≈ (u ∙ v) ∙ (w ∙ x) | ||||||
u[vw∙x]≈uv∙wx = sym uv∙wx≈u[vw∙x] | ||||||
|
||||||
u[v∙wx]≈[uv∙w]x : u ∙ (v ∙ (w ∙ x)) ≈ ((u ∙ v) ∙ w) ∙ x | ||||||
u[v∙wx]≈[uv∙w]x = sym [uv∙w]x≈u[v∙wx] | ||||||
|
||||||
u[v∙wx]≈[u∙vw]x : u ∙ (v ∙ (w ∙ x)) ≈ (u ∙ (v ∙ w)) ∙ x | ||||||
u[v∙wx]≈[u∙vw]x = sym [u∙vw]x≈u[v∙wx] | ||||||
|
||||||
module _ {u v w x : Carrier} (uv≈wx : u ∙ v ≈ w ∙ x) where | ||||||
uv≈wx⇒yu∙v≈yw∙x : ∀ y → (y ∙ u) ∙ v ≈ (y ∙ w) ∙ x | ||||||
uv≈wx⇒yu∙v≈yw∙x y = trans (uv≈w⇒xu∙v≈xw uv≈wx y) (sym (assoc y w x)) | ||||||
|
||||||
uv≈wx⇒u∙vy≈w∙xy : ∀ y → u ∙ (v ∙ y) ≈ w ∙ (x ∙ y) | ||||||
uv≈wx⇒u∙vy≈w∙xy y = trans (uv≈w⇒u∙vx≈wx uv≈wx y) (assoc w x y) | ||||||
|
||||||
uv≈wx⇒yu∙vz≈yw∙xz : ∀ y z → (y ∙ u) ∙ (v ∙ z) ≈ (y ∙ w) ∙ (x ∙ z) | ||||||
uv≈wx⇒yu∙vz≈yw∙xz y z = trans (uv≈w⇒xu∙v≈xw (uv≈wx⇒u∙vy≈w∙xy z) y)(sym (assoc y w (x ∙ z))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space
Suggested change
|
Uh oh!
There was an error while loading. Please reload this page.