如果 X = f(X),Prolog 会做什么? [英] What does Prolog do if you X = f(X)?

查看:49
本文介绍了如果 X = f(X),Prolog 会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Prolog 中比较谓词和未绑定变量是什么意思?

What does it mean in Prolog comparing a predicate to an unbound variable?

推荐答案

X = f(X) 目标的结果取决于 Prolog 的实现,在某些系统中,正如 Carlo 在他的回答,结果可以由用户可设置的标志控制.统一谓词(=)/2,可以在有或没有所谓的发生检查的情况下实现.此检查验证一个操作数中的变量是否出现在另一个操作数中的子项中.当统一谓词执行此检查时,目标 X = f(X) 失败.但是,出于性能原因,统一谓词通常在没有此检查的情况下实现.ISO Prolog 标准指定了另一种统一谓词,恰当地命名为 unify_with_occurs_check/2,可在诸如此类的目标可能导致麻烦时使用.

The result of the X = f(X) goal depends on the Prolog implementation, In some systems, as Carlo pointed out in his answer, the result can be controlled by a user settable flag. The unification predicate, (=)/2, may be implemented with or without what's called the occurs check. This check verifies if a variable in one operand occurs in a sub-term in the other operand. When the unification predicate implements this check, the goal X = f(X) fails. But, for performance reasons, the unification predicate is often implemented without this check. The ISO Prolog standard specifies an alternative unification predicate, aptly named unify_with_occurs_check/2, that can be used when goals such as this one can lead to trouble.

现在,有几种实现支持循环项,也称为有理项,由诸如X = f(X)之类的目标创建代码>.其中包括 CxProlog、ECLiPSe、SICStus Prolog、SWI-Prolog 和 YAP.但是请注意,对理性术语的支持程度因系统而异.最小支持将是 (1) 能够创建有理项(没有堆栈溢出!),(2) 能够统一两个有理项,以及 (3) 能够打印包含有理项的查询绑定以一种明确的方式.使用这三个功能,您可以例如实现共归纳逻辑编程,这对几类问题很有用.

Nowadays, several implementations support the cyclic terms, also known as rational terms, that are created by goals such as X = f(X). These include CxProlog, ECLiPSe, SICStus Prolog, SWI-Prolog, and YAP. Note, however, that the level of support for rational terms varies across system. The minimal support will be (1) to be able to create rational terms (without a stack overflow!), (2) to be able to unify two rational terms, and (3) to be able to print query bindings that include rational terms in a non-ambiguous way. With these three features you can e.g. implement coinductive logic programming, which is useful for several classes of problems.

这篇关于如果 X = f(X),Prolog 会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆