我正在做代数中证明群论的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
请帮帮我,非常感谢!
A51和A52子句是左递归的,这会导致堆栈外错误。处理Prolog中左递归的规范解决方案是使用支持制表的系统(例如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.