prolog - 我想用 Prolog 证明一些定理,但是,它总是返回“Out of global stack”
问题描述
我正在做证明代数群论的人工智能作业。
该定理可以表示如下:
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.
推荐阅读
- php - Laravel 动态路由参数显示错误 404
- angularjs - 将表单设置为加载后提交
- angular - 角路由器:如何在运行时/动态地操纵每个路由数据?
- dart - 5 个 TextFormField 验证器中只有 2 个在工作
- razor - 如何在 ASP.NET Core 中将 ViewComponent 拉到响应缓存控制器的操作之外
- javascript - 获取所有嵌套项的计数
- google-apps-script - UrlFetchApp 返回的响应与我在浏览器中看到的不同
- java - 如何从文本文件中获取价值并与 firebase 链接
- javascript - 需要一些 Javascript ASP.NET 建议
- file - 如何在 Rust 中异步计算硬盘上文件的校验和?