-
Notifications
You must be signed in to change notification settings - Fork 259
Add new Bool action on a RawMonoid plus properties
#2450
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?
Conversation
|
Ooops (mistake to try to abstract immediately over |
|
Conor's disembodied voice tells me we should use a non-symmetric infix symbol for this non-symmetric action. |
I'm genuinely torn over this. I understand, appreciate, and even largely agree with, the doctrine (prevalent in WG2.1) that non-symmetric/commutative operations should be given non-symmetric notation. Nevertheless, we don't insist that that a Nevertheless, I think we do ourselves (or else: type theory as a principled metalanguage for the prosecution of such doctrine) a disservice by taking the 'old-fashioned' CFG view of notation not coming a priori with a type attached. The case here, as more generally in the draft PR on You might object that the So perhaps the way out of the bottle is to tag the symbol with I guess I could live with that... modulo leaving |
MatthewDaggitt
left a comment
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.
Otherwise looks good.
| infixr 8 _∧_ | ||
|
|
||
| _∧_ : Bool → Carrier → Carrier | ||
| b ∧ x = if b then x else 0# |
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.
Strictly speaking, this could be defined for any Pointed structure with an apartness relation, as an action on a Pointed structure.
How is the above 'conjuction'?
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.
OK, I think that's fair... I was being pretty ad hoc in wanting to add this by analogy with the Nat action already defined there, as then these two instances of a phenomenon (eventually: wreath product) are the relevant ones for the Algebra.Solver.*CommutativeMonoid refactorings #2407 #2457 ... and I'm still unhappy about the general picture for Pointed things in the library, so don't (yet) want to reopen that can of worms...
As for it being 'conjunction', well it clearly generalises it: for Carrier being that of the Monoid structure on Bool given by _∨_ with unit false,
b ∧ x = if b then x else falseis a definition of 'conjunction'... yes!?
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.
Yes, that is the operational definition of 'conjunction' on Bool.
I guess that I was thinking along the lines of "if b is the least element then x else some-distinguished-point" as the general meaning. It feels more action-y. 'conjunction' feels like it's a coincidence when Carrier is Bool.
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.
Revisiting: maybe better thought as a 'guarded' value?
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.
Yes, I guess that this is a classic instance of (idealised) haskell's MonadZero.guard (if I've got this right; hackage seems to suggest that's not quite the case...)
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.
b ∧ x is essentially the pattern x <$ guard b which AFAIK does not have a name
but is very useful.
| _∧_ : Bool → Carrier → Carrier | ||
| b ∧ x = if b then x else 0# | ||
|
|
||
| -- tail-recursive optimisation |
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.
optimisation of what? It doesn't seem like an optimisation of the above? What am I missing?
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 with the TCOptimised forms of (monoid) sum and multiplication, the 'optimisation' lies in avoiding having to explicitly track terms of the form x + 0# when these can be computed away instead to x... But I admit I haven't quite got my story straight yet... ;-)
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 witnessed by b∧x∙y≈b∧x+y...
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.
It still feels like a stretch. I do like the optimization of an action not doing a (statically known) null operation, a lot. I'm still worried that this particular case is a coincidence rather than fundamental!
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 I think it extends to the Nat cases as well (but obscured in the current presentation, which doesn't introduce the tail-recursive forms... but see #2475 )
|
What prevents this from losing its DRAFT status? |
Off the top of my head:
All of the above are slightly beyond my capacity to think right now, so |
|
Notes to self (and any other interested parties here):
It may well be that this all needs reorganisation down the road, at which point it may be clearer (than it is to me now) what would be necessary/useful to isolate 'sensible' common abstractions. |
| ×-homo-+ x 0 n = sym (+-identityˡ (n × x)) | ||
| ×-homo-+ x (suc m) n = begin | ||
| x + (m ℕ.+ n) × x ≈⟨ +-cong refl (×-homo-+ x m n) ⟩ | ||
| x + (m ℕ.+ n) × x ≈⟨ +-congˡ (×-homo-+ x m n) ⟩ |
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.
cong followed by sym-assoc is what some of those combinators for Semigroup does in one go.
|
|
||
| * In `Algebra.Definitions.RawMonoid` action of a Boolean on a RawMonoid: | ||
| ```agda | ||
| _∧_ : Bool → Carrier → Carrier |
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.
I'm with @gallais here (and Conor too): I find this symmetric symbol quite misleading.
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.
Yes, I wonder if these things could be (appropriately) re-notated in terms of #2894 , for all its faults?
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.
Could be something like ?> by analogy to $>.
| infixr 8 _∧_ | ||
|
|
||
| _∧_ : Bool → Carrier → Carrier | ||
| b ∧ x = if b then x else 0# |
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.
Revisiting: maybe better thought as a 'guarded' value?
Prompted by @JacquesCarette 's desire to further systematise the refactoring in #2407 , this adds two operations which appear ad hoc in the normal form semantics for
IdempotentCommutativeMonoids, but are yet more instances of a(Raw)MonoidActioncf. #2348 / #2350 by analogy with the corresponding actions in the normal form semantics forCommutativeMonoids.NB
Could be left as DRAFT, pending further work cf. #2351 , but worth inviting review now, I think.
NB. possible issues:
x + n × yas well asn × x + yetc.Algebra.Solver.*Monoidetc.Algebra.Definitions.RawMonoid._×_operation etc. possible as well?