-
Notifications
You must be signed in to change notification settings - Fork 246
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
[Add] Reasoning combinator for semigroup #2688
base: master
Are you sure you want to change the base?
Conversation
For others: the names are taken from the combinators in |
With an explicit callback/reference to #2288 ? This PR alone doesn't 'fix' that issue, but contributes a piece of the jigsaw to such a 'fix'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of comments, I'm requesting changes based on a single one, but can be summarised as:
- please give lemmas names that can be remembered without needing a lookup table or other instruction manual to explain what they are/how they behave!
- no need for a new module, we already have the
Algebra.Properties.*
sub-hierarchy...
src/Algebra/Reasoning/Semigroup.agda
Outdated
module Pulls (ab≡c : a ∙ b ≈ c) where | ||
pullʳ : ∀ {x} → (x ∙ a) ∙ b ≈ x ∙ c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere, the library would use lemma names of the form p∧q⇒r
, with square brackets for grouping sub-terms, so here:
module Pulls (x∙y≈z : x ∙ y ≈ z) where
x∙y≈z⇒[w∙x]∙y≈w∙z : (w ∙ x) ∙ y ≈ w ∙ z
NB. also: you have declared x
as a variable
, so there's no need to have the quantifier! Although here again, we have the problem that in any deployment in a concrete Semigroup
the typechecker might not be able to infer w
... so there are questions about how the quantifications should be handled.
If you can find examples in eg Data.Rational.Properties
which might be simplified by these lemmas, then you might discover whether Agda can (or not) infer the various implicits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the use of ⇒
in the lemma names would avoid the need for the submodules here to be named; they could (more) simply be anonymous module _ (hyps) where
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While x∙y≈z⇒[w∙x]∙y≈w∙z
is a logical name, it is also quite long. As these combinators that re-associate are book-keeping things, I'd like to find something shorter / less noisy.
I do hate push/pull. I'm partial to on-right
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, with my suggested notational optimisations, this would/could become...xy≈z⇒wx∙y≈wz
, which is about as short as I can make it?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for on-right
I'm really not sure what that is supposed to signify, given that the lemma is not cong
like, nor is the action obviously happening on the right? (Never mind our ongoing debates about left/right distinctions giving rise to confusion...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on-right
as in apply this equality on the right
, after a re-focus. It's very much cong
-like to me, it just has a re-association done first, to put "the right" in focus.
Co-authored-by: jamesmckinna <[email protected]>
src/Algebra/Reasoning/Semigroup.agda
Outdated
module Algebra.Reasoning.Semigroup {o ℓ} (S : Semigroup o ℓ) where | ||
|
||
open Semigroup S | ||
using (Carrier; _∙_; _≈_; setoid; trans ; refl; sym; assoc; ∙-cong) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is by 2 spaces, not 4 as you have here... see style-guide
.
using (Carrier; _∙_; _≈_; setoid; trans ; refl; sym; assoc; ∙-cong) | |
using (Carrier; _∙_; _≈_; setoid; trans ; refl; sym; assoc; ∙-cong; ∙-congˡ; ∙-congʳ) |
src/Algebra/Reasoning/Semigroup.agda
Outdated
pushʳ {x = x} = begin | ||
x ∙ c ≈⟨ sym (∙-cong refl ab≡c) ⟩ | ||
x ∙ (a ∙ b) ≈⟨ sym (assoc x a b) ⟩ | ||
(x ∙ a) ∙ b ∎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successive appeals to sym
suggest that it should be lifted out (permutation of sym
through proofs), but in fact doing so quickly reveals the following:
pushʳ {x = x} = begin | |
x ∙ c ≈⟨ sym (∙-cong refl ab≡c) ⟩ | |
x ∙ (a ∙ b) ≈⟨ sym (assoc x a b) ⟩ | |
(x ∙ a) ∙ b ∎ | |
pushʳ = sym (pullʳ ab≡c) |
OK... thanks for the recent commits, but I'm going to carry on nitpicking:
|
Also:
As with previous comments, we don't need a new module (even if it's moved location), these could all go in |
|
||
module Assoc4 {u v w x : Carrier} where | ||
[[u∙v]∙w]∙x≈u∙[[v∙w]∙x] : ((u ∙ v) ∙ w) ∙ x ≈ u ∙ ((v ∙ w) ∙ x) | ||
[[u∙v]∙w]∙x≈u∙[[v∙w]∙x] = trans (∙-congʳ (assoc u v w)) (assoc u (v ∙ w) x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strong reason to have push/pull defined before these is that they can be used here. You should indeed move those up above Assoc4
and refactor the proofs here to use push/pull.
The 'new' names in |
Again, agree to disagree. No 'clear' failure on my side, but happy to try to find a good outcome to the naming discussion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placeholder review: this will have to wait until at least the weekend before I can return to it.
But I think in the meantime there still seem to be spacing issues, the existing question of where these things should live, as well as those regarding whether explicitly-named proofs of 'symmetric' versions are really necessary.
Introduce a new module for equational reasoning in semigroups, providing utilities for associativity reasoning and operations.