Skip to content

Add ring solver#39

Merged
omelkonian merged 5 commits into
masterfrom
ring-solver
May 31, 2026
Merged

Add ring solver#39
omelkonian merged 5 commits into
masterfrom
ring-solver

Conversation

@WhatisRT

@WhatisRT WhatisRT commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Adds a practical ring solver based on the machinery on the standard library. The focus here is on something that one should expect to work by default - to that end, there's over 100 tests on various abstract & concrete scenarios. There is a documented limitation (it doesn't help solving metas) but other than that I'm not aware of any cases where you should expect a ring solver to work but this one doesn't.

There's also a comparison with reflective ring solvers that are part of the standard library in Tactic.Solver.Ring.Tests.Comparison, demonstrating the various issues and that they are fixed with this solver.

There is a lot of infrastructure here that should be generically usable for other solvers - currently it is used to deal with both commutative rings and commutative semirings automagically.

WhatisRT added 4 commits May 21, 2026 13:55
Extracts the structure-independent parts of the ring solver
(atom collection, two-pass polynomial-AST conversion, deadlock
detection, auto-quantification, reflection plumbing) into a new
generic core `Tactic.Solver.Algebra`, parameterised by a `Theory`
record that describes a particular algebraic structure.

The ring solver is now an instantiation of this core for
`CommutativeSemiring` against stdlib's
`Algebra.Solver.Ring.NaturalCoefficients.Default`.
Adds a `CommutativeRing` side to `solve-≈`, alongside the existing
`CommutativeSemiring` support. This comes at no extra cost at the call
site, and we automatically detect what ring is being used.
I dislike this fix, but I can't think of anything better right now

@omelkonian omelkonian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice one!

If I understood correctly, this is a convenient wrapper around stdlib's ring solver, doing a better job than the stdlib solve-∀, right?

As a future improvement, would it make sense to automatically discover the commRing instance / record that solve-≈ now takes explicitly?

@omelkonian omelkonian merged commit 2cfa1da into master May 31, 2026
1 check passed
@omelkonian omelkonian deleted the ring-solver branch May 31, 2026 20:34
@WhatisRT

WhatisRT commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Yes, it's purely a frontend. I'm not sure automatic discovery is possible (at least consistently). The difficult thing that this frontend does is discovering exactly what to reduce in the goal expression. And for this, the instance is an input.

I think it might be possible in certain scenarios, but e.g. if you want to solve equations over , there's no way to figure out the instance if you use the operations imported from Data.Nat, other than some dictionary lookup with a predefined list of instances.

So all in all I think it's a moderate effort with uncertain success and a relatively minor benefit if it works out. For now I think there are better things to work on.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants