-
Notifications
You must be signed in to change notification settings - Fork 239
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 new Bool
action on a RawMonoid
plus properties
#2450
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 |
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 false
is 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
.
_∧_ : 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 )
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
IdempotentCommutativeMonoid
s, but are yet more instances of a(Raw)MonoidAction
cf. #2348 / #2350 by analogy with the corresponding actions in the normal form semantics forCommutativeMonoid
s.NB
Could be left as DRAFT, pending further work cf. #2351 , but worth inviting review now, I think.
NB. possible issues:
x + n × y
as well asn × x + y
etc.Algebra.Solver.*Monoid
etc.Algebra.Definitions.RawMonoid._×_
operation etc. possible as well?