我想用 Prolog 证明一些定理,但是,它总是 returns "Out of global stack"
I want to prove some theorem using Prolog, however, it always returns "Out of global stack"
我正在做证明代数群论的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 中处理左递归的规范解决方案是使用支持 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.
我正在做证明代数群论的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 中处理左递归的规范解决方案是使用支持 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.