我正在做AI作业,以证明代数中的群论。
定理可以表示如下:
A1. i(e,X) = X (identity)
A2. i(X, e) = X (identity)
A3. i(comp(X),X) = e (complement)
A4. i(X, comp(X)) = e (complement)
A5. i(X, i(Y,Z)) = i(i(X,Y),Z) (associativity)
THEOREM: If G is a group such that for every X,
A6. i(X,X) = e,
then G is commutative, i.e., for every X; Y ,
i(X,Y) = i(Y,X):
and the commutative part can be represented as
A7. i(a, b, c) clause derived from negated conclusion
A8. -i(b, a, c) clause derived from negated conclusion
我将它们转换为Prolog格式,如下所示:
% A7
i(a, b, c).
% A1
i(e, X, X) .
%A2
i(X, e, X).
% A3
i(comp(X), X, e).
% A4
i(X, comp(X), e).
% A51
i(U, Z, W) :- i(X, Y, U), i(Y, Z, V), i(X, V, W).
% A52
i(X, V, W) :- i(X, Y, U), i(Y, Z, V), i(U, Z, W).
% A6
i(X, X, e).
然后我想证明该定理,因此我在Prolog控制台中键入了“ i(b,a,c)”,并且得到了以下错误消息:
?- i(b,a,c).
ERROR: Out of global-stack.
ERROR: No room for exception term. Aborting.
ERROR: Out of global-stack.
ERROR: No room for exception term. Aborting.
ERROR: Out of global-stack.
ERROR: No room for exception term. Aborting.
% Execution Aborted
请帮助我,非常感谢!
答案 0 :(得分:2)
A51和A52子句是 left-recursive ,这会导致栈外错误。在Prolog中处理左递归的典型解决方案是使用支持 tabling 的系统(例如XSB,YAP,SWI-Prolog,B-Prolog或Ciao)。但是您的代码中还有另一个问题。 A3和A4子句可导致创建循环项。例如,仅加载子句A3:
?- i(X, X, Y), cyclic_term(X).
X = comp(X),
Y = e.
如果注释掉A3和A4子句,并在源文件顶部添加指令:
:- table(i/3).
您将获得:
?- i(b,a,c).
true.