SWI-Prolog中的方程求解器 [英] Equation solver in SWI-Prolog
本文介绍了SWI-Prolog中的方程求解器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用SWI-Prolog
编写一个解决方程式的程序.我知道GNU Prolog
,这让我感到紧张...这里出了什么问题?
I want to write a program in SWI-Prolog
that solves equations. I know GNU Prolog
and that 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}
}.
X1
和X2
始终等于0
或1
.
推荐答案
我有一个文件,
:- [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}.
这是您期望的结果吗?
编辑
?- eq(A,B),A=1.
A = 1,
B = 4 rdiv 3.
?- eq(A,B),B=1.
A = 3 rdiv 2,
B = 1.
Section A.8.3 of the documentation says that unification can hold 'outside' constraints specification. Then you can experiment freely with additional bounding. But if you impose that both A and B will bind, you should choose appropriate values. AFAIK the values you posted initially cannot satisfy the equation.
这篇关于SWI-Prolog中的方程求解器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文