If I use
diophantine(2*x+3*y-5*z-77)
I receive this result.
{(t_0, -9*t_0 - 5*t_1 + 154, -5*t_0 - 3*t_1 + 77)}
Fine so far. However, on occasion one might like to constrain x, y and z to be (say) non-negative. When I use an approach like this<
reduce_inequalities([0<=t_0, 0<=-9*t_0 - 5*t_1 + 154, 0<=-5*t_0 - 3*t_1 + 77],[t_0, t_1])
I get:
NotImplementedError:
inequality has more than one symbol of interest
Does sympy, sage, prolog, haskell or some other freely available product have means for solving systems of linear inequalities that arise in this way.
Thank you!
To reason about integers in Prolog, you can use your Prolog system's CLP(FD) constraints.
The exact details differ slightly between different Prolog systems. Please see your system's manual for more information, and also clpfd for related questions.
In your case, we can start by simply posting the constraint:
In this case, and as for all pure Prolog programs, the system's answer is declaratively equivalent to the original query. This does not help a lot here: The system has only slightly rewritten the original constraint.
You can constrain this further, for example with:
As requested, this additional goal constrains the variables to non-negative integers. The system's answer still does not help a lot.
You can use
label/1
to search for concrete solutions. However, this so-called labeling requires that all domains be finite, and so we currently get:The good news (in a sense) is that we don't have time to try all possibilities in any case. So we might as well restrict ourselves to some finite part of the search space. For example:
With this query, you get concrete integers as solutions:
Since you are reasoning over linear constraints, CLP(Q) may also be worth a try.