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

RFC: Arithmetics #32

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

RFC: Arithmetics #32

wants to merge 4 commits into from

Conversation

dcz-self
Copy link

@dcz-self dcz-self commented Dec 3, 2024

I gave it a try and added some arithmetics that are going to be required by my use case.

Unlike the existing ones, those I added are all predicates. They all require full instantiation, apart from IsNeg, which will negate an integer if not out of bounds.

Initially I wanted to make the predicates fill in variables with matching values, but that quickly leads to i64-sized loops.

While I don't expect logru to support clp(fd), I think there's a continuum of ways to make arithmetics resolve to something useful. With one variable, the syntax could look like:

is(Var, and(condition, ...)).

where the resolver could look at all conditions to see if they are bounded before proceeding.

Does that sound like anything desireable?


Another thing is the lack of messages when there's a variable which is not instantiated enough. I epect that to be the main thing driving people away. I could give it a shot and change impl Resolver to return an error message, and pass it all the way to the user. Interested?

dcz added 4 commits December 1, 2024 16:04
Prettification of terms is typically related to some particular query rather than a naked Universe, so add a convenience type for that.
@fatho
Copy link
Owner

fatho commented Dec 6, 2024

Initially I wanted to make the predicates fill in variables with matching values, but that quickly leads to i64-sized loops.

Yeah, I don't think that's feasible. For the core Arithmetic resolver, I'd like to stick to deterministic evaluation, just like is in prolog (if I remember that part correctly).

While I don't expect logru to support clp(fd), I think there's a continuum of ways to make arithmetics resolve to something useful. With one variable, the syntax could look like:

is(Var, and(condition, ...)).

where the resolver could look at all conditions to see if they are bounded before proceeding.

Does that sound like anything desireable?

That does sound interesting. So essentially you'd restrict the domain of a variable through various conditions, and then it allows iteration over the remaining values?
I'd probably have to see it to say if it's something I'd like to maintain in this library 😅 But in any case, I think it should be best implemented as its own resolver extending the basic Arithmetic one (and keeping that one limited to simple, deterministic operations).
And since the solver core is reasonably open, such more specialized extensions could also be published as a separate crate if needed.

Another thing is the lack of messages when there's a variable which is not instantiated enough. I epect that to be the main thing driving people away. I could give it a shot and change impl Resolver to return an error message, and pass it all the way to the user. Interested?

A better way of reporting errors than just failing a goal is definitely something that's on my roadmap. I'm not sure yet what the best way to do this is. If you have a concrete idea, feel free to put it in an issue to discuss, or make a PR (depending on how much work it is, though if it's invasive, first discussing the idea might be better before you sink to much work into it).

@dcz-self
Copy link
Author

dcz-self commented Dec 8, 2024

more specialized extensions could also be published as a separate crate if needed.

Agreed, I'll be doing testing in my own sandbox for now.

If you have a concrete idea,

I'd just go bottom-up by putting errors in the places where they are found and let the bubble up until they are visible to the user.

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