Equation in SWI-Prolog

I want to write a program in SWI-Prologthat solves the equations. I know GNU Prolog, and it makes me nervous ... What is wrong here?

equation(X1,X2) :-
  {
    2*X1 + 3*X2 =:= 6,
    {X1 is 0; X1 is 1},
    {X2 is 0; X2 is 1}
  }.

X1and are X2always equal to 0or 1.

+2
source share
1 answer

I have a file with

:- [library(clpq)].
eq(X1, X2) :- {2 * X1 + 3 * X2 =:= 6}.

then I compile and run, and I get:

?- eq(A,B).
{B=2-2 rdiv 3*A}.

Is this the result you expect?

change

?- eq(A,B),A=1.
A = 1,
B = 4 rdiv 3.

?- eq(A,B),B=1.
A = 3 rdiv 2,
B = 1.

A.8.3 , "". . , A B , . AFAIK , , .

+2

Source: https://habr.com/ru/post/1610946/


All Articles