Skip to content
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

Refactor Algebra.Solver.*Monoid #2407

Merged
merged 33 commits into from
Sep 3, 2024

Conversation

jamesmckinna
Copy link
Contributor

@jamesmckinna jamesmckinna commented Jun 11, 2024

Fixes #2403

NB:

  • for backwards compatibility, each module exports the Expr API publicly (but not the new API for Normal forms)
  • UPDATED: module Monoid.Solver adopts the API for *CommutativeMonoid, but maybe the Monoid.prove type should standardise on this as well?
  • misc. tweaks to existing other Solver modules

@jamesmckinna jamesmckinna marked this pull request as draft June 14, 2024 11:32
@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jun 14, 2024

Converted to DRAFT for further refactoring... and now back again.

@jamesmckinna jamesmckinna marked this pull request as ready for review June 14, 2024 11:52
@jamesmckinna jamesmckinna marked this pull request as draft June 15, 2024 12:29
@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jun 19, 2024

I'd converted back to draft with a view to more drsatic refactoring, but then lost my nerve over the knock-on consequences for deprecation/backwards-compatibility, so I'll leave those for another time a breaking PR for v3.0... ;-)

And in the meanwhile: merge conflict hell!

@jamesmckinna jamesmckinna marked this pull request as ready for review June 19, 2024 08:05
@jamesmckinna jamesmckinna added this to the v2.2 milestone Jun 19, 2024
@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jun 19, 2024

Will leave the CHANGELOG until after v2.1... and DONE: update deprecation warnings to v2.2!

@jamesmckinna jamesmckinna mentioned this pull request Jul 1, 2024
Copy link
Contributor

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

A couple of minor improvements suggested.

On a bigger scale: this seems like a lot of duplication. Feels like one could abstract over the differences between CommutativeMonoid/Normal and IdempotentCommutativeMonoid/Normal instead of this copy-pasta. But that's an easy comment for me to make!!! I should actually try it.

@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jul 28, 2024

A couple of minor improvements suggested.

On a bigger scale: this seems like a lot of duplication. Feels like one could abstract over the differences between CommutativeMonoid/Normal and IdempotentCommutativeMonoid/Normal instead of this copy-pasta. But that's an easy comment for me to make!!! I should actually try it.

For sure, the duplication was already there in the library. This PR merely refactors it to make it evident, so in that sense this PR should be regarded as 'provisional', even if mergeable. The Normal type family in each case is Vec M for M the carrier of a suitable Monoid, with the homomorphism properties being generic, so yes, with more work, I'm sure it could be made more streamlined. Your zipWith comment is very helpful in pointing the way...

The downstream refactoring alluded to in the preamble of #2403 would spruce up the homomorphism correctness proof machinery, but at the cost, again, of having to re-export stuff, now from a different, but again shared, module/record (I've experimented with this already, but fresh eyes might be welcome! UPDATED: see below), else have a heavier-weight move/rename-plus-deprecate refactoring, which I just couldn't face right now.

But happy to reconsider, and mark as DRAFT, pending further refactoring requiring a bit more intelligence/insight.

BTW, part of the purpose of this PR, ahead of tackling the more intricate complexities of Tactic.MonoidSolver and Tactic.RingSolver, is indeed to consider adding Algebra.Solver.AbelianGroup, in which the algebra of Normal forms is again that of zipWith _+_, but on vectors of integers. It seems as though this might be (part of) the missing piece of the jigsaw around Tactic.RingSolver seemingly be(hav)ing 'not quite right' when coefficients in the ring sum to zero... cf. #1116 / #1769

@JacquesCarette
Copy link
Contributor

[...] does it make sense to aim to merge this in the meantime?

As long as the additional refactor doesn't introduce compatibility issues, then yes, it makes sense to merge this in first.

@jamesmckinna
Copy link
Contributor Author

[...] does it make sense to aim to merge this in the meantime?

As long as the additional refactor doesn't introduce compatibility issues, then yes, it makes sense to merge this in first.

Well, that's a good question! I guess that the NormalAPI is nowhere exposed as such in the (existing) 'top level' Algebra.Solver.*Monoid modules, so as long as we feel free to change that API under the abstract Tactic interface, it should be OK, right?

Or not!?

@jamesmckinna
Copy link
Contributor Author

And... as for "compatibility issues", I think there won't be any arising from #2457 ... given the (relative) care taken to preserve (even if to deprecate) the v1.*/v2.1 API ...

Copy link
Contributor

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

This looks really good! Added a few small comments, many of which whose causes aren't directly introduced by you.

src/Algebra/Solver/Monoid/Tactic.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/Monoid/Tactic.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/Monoid/Tactic.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/Monoid/Tactic.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/Monoid/Tactic.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/CommutativeMonoid/Normal.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/IdempotentCommutativeMonoid.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/IdempotentCommutativeMonoid/Normal.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/IdempotentCommutativeMonoid/Normal.agda Outdated Show resolved Hide resolved
src/Algebra/Solver/Monoid.agda Outdated Show resolved Hide resolved
@MatthewDaggitt
Copy link
Contributor

After those are addressed, we should definitely merge!

@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Aug 29, 2024

@MatthewDaggitt thanks for the very detailed feedback. Summarising:

  • I've fixed the newly-introduced module exports to hopefully now not introduce new names, but the original export of module R in Algebra.Solver.Monoid is legacy, so leaving it for now.
  • I've done the suggested deprecations and updated CHANGELOG
  • I changed the Tactic module name to Solver as a pro tem measure, Proof(s) seemed ... not quite right? Implementation feels too... generic?

@JacquesCarette Against the discussion on #2457 , which I think can follow-on downstream, I still think this is worth merging now, as a refactoring-with-deprecations. The rest can follow later?

@MatthewDaggitt MatthewDaggitt added this pull request to the merge queue Sep 3, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Sep 3, 2024
@jamesmckinna
Copy link
Contributor Author

Thanks @MatthewDaggitt for resolving the merge conflict... I'd have got there once I'd woken up... ;-)

@MatthewDaggitt MatthewDaggitt added this pull request to the merge queue Sep 3, 2024
Merged via the queue into agda:master with commit ef9e3d6 Sep 3, 2024
2 checks passed
@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Sep 3, 2024

Apologies for inaccuracy in my summary of changes: it seems as though I did in fact make the breaking change of making the module R private in Algebra.Solver.Monoid.Solver, so it's not now exported publicly from Algebra.Solver.Monoid.

I've suggested on the downstream issue #2472 that we take no action on this (until eg. a release candidate for v2.2?), but advice/counter-suggestions welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DRY] Refactor Algebra.Solver.*Monoid (or deprecate entirely?)
3 participants