Skip to content

Comments

[ add ] Bool action on a RawMonoid plus properties#2450

Merged
JacquesCarette merged 11 commits intoagda:masterfrom
jamesmckinna:Bool-action
Jan 30, 2026
Merged

[ add ] Bool action on a RawMonoid plus properties#2450
JacquesCarette merged 11 commits intoagda:masterfrom
jamesmckinna:Bool-action

Conversation

@jamesmckinna
Copy link
Collaborator

@jamesmckinna jamesmckinna commented Jul 31, 2024

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)MonoidAction cf. #2348 / #2350 by analogy with the corresponding actions in the normal form semantics for CommutativeMonoids.

NB

  • Nat-action arises because (Nat, +, 0) is the free commutative monoid on one generator...
  • similarly, (Bool, /, true) is, I think, the free idempotent commutative monoid on one generator?

Could be left as DRAFT, pending further work cf. #2351 , but worth inviting review now, I think.

NB. possible issues:

  • names of things: current notation is terrible, unfortunately, so suggestions welcome!
  • left-/right- symmetric versions, ie. x + n × y as well as n × x + y etc.
  • possible refactoring of the existing definitions as instances of these generalised 'affine' ones?
  • refactoring not yet applied to Algebra.Solver.*Monoid etc.
  • ... further systematisation of existing Algebra.Definitions.RawMonoid._×_ operation etc. possible as well?
  • Fairbairn threshhold?

@jamesmckinna
Copy link
Collaborator Author

jamesmckinna commented Aug 2, 2024

Ooops (mistake to try to abstract immediately over MonoidAction... the Nat case is a MagmaAction, but not a MonoidAction... the 0/1 cases don't match up right). Moving to DRAFT while I rethink this.

@jamesmckinna jamesmckinna marked this pull request as draft August 2, 2024 05:21
@gallais
Copy link
Member

gallais commented Aug 6, 2024

Conor's disembodied voice tells me we should use a non-symmetric infix symbol for this non-symmetric action.

@jamesmckinna
Copy link
Collaborator Author

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 Group operation be given a non-symmetric symbol... even if we do distinguish it as _+_ (or something else 'obviously connoting commutativity') in the AbelianGroup case.

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 Algebra.Action, is that the point of an action is that it is extending the domain of applicability of a given operation (however symbolised) to the structure on which it acts... and the generalised associativity property of a MagmaAction is precisely where the extended notation bites, visually/mnemonically at least.

You might object that the Bool action defined here, or Algebra.Definitions.RawMonoid. _×_ aren't in and of themselves 'commutative'... but that obscures the fact that their flipped counterparts are in fact extensionally equal to these definitions.

So perhaps the way out of the bottle is to tag the symbol with ˡ and ʳ annotations, and use infix symbol positions to record where the tail-recursive accumulator argument should go in the extended notation, yielding four compound symbols in all?

I guess I could live with that... modulo leaving _×_ unchanged as 'legacy' (yuk)?

Copy link
Collaborator

@MatthewDaggitt MatthewDaggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks good.

_∧_ : Bool → Carrier → Carrier
b ∧ x = if b then x else 0#

-- tail-recursive optimisation
Copy link
Collaborator

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?

Copy link
Collaborator Author

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... ;-)

Copy link
Collaborator Author

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...

Copy link
Collaborator

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!

Copy link
Collaborator Author

@jamesmckinna jamesmckinna Aug 27, 2024

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 )

@JacquesCarette
Copy link
Collaborator

What prevents this from losing its DRAFT status?

@jamesmckinna
Copy link
Collaborator Author

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 DRAFT seemed to safest way to mark "I'll come back to this (at some point)"

@jamesmckinna
Copy link
Collaborator Author

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.

@jamesmckinna
Copy link
Collaborator Author

jamesmckinna commented Jan 11, 2026

Converting back from DRAFT:

  • fixed proofs (incl. @JacquesCarette 's suggestions)
  • fixed notation to be (more like) @gallais 's suggestion (subscript-0 for the 'common' case; I don't really like the use of primes in the names for the accumulator generalisations in Algebra.Definitions.RawMonoid...)
  • fixed merge conflicts to resolve CHANGELOG problems etc.

I never quite got as far as finding a common generalisation between the Nat- and Bool-actions, I think that will need to wait until #2350 eventually (!?) lands, so for now, I think this should just stand as-is, modulo nitpicking about names, which I'd be happy to engage with!

@jamesmckinna jamesmckinna marked this pull request as ready for review January 11, 2026 19:08
@jamesmckinna jamesmckinna changed the title Add new Bool action on a RawMonoid plus properties [ add ] Bool action on a RawMonoid plus properties Jan 11, 2026
@jamesmckinna jamesmckinna added this to the v2.4 milestone Jan 12, 2026
Copy link
Collaborator

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gallais for this nice notation suggestions. I'm now happy with this PR.

@JacquesCarette
Copy link
Collaborator

Still needs a second approver...

@JacquesCarette JacquesCarette added this pull request to the merge queue Jan 30, 2026
Merged via the queue into agda:master with commit 29063bb Jan 30, 2026
12 checks passed
plt-amy pushed a commit that referenced this pull request Feb 9, 2026
* Add new `Bool` action on a `RawMonoid` plus properties

* response to review comments on draft

* reset: `CHANGELOG`

* restore: new `CHANGELOG` entries

* change: notation

* refactor: use new notation, plus add new lemma

* refactor: tweak notation

* refactor: proof following Jacques' suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants