首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Prolog中长度/2的逻辑推论数(swi-pl)

Prolog中长度/2的逻辑推论数(swi-pl)
EN

Stack Overflow用户
提问于 2016-05-07 13:11:55
回答 1查看 146关注 0票数 4

我期望内置长度/2谓词在逻辑推理的数量上是线性的。然而,它似乎是不变的:

代码语言:javascript
复制
?- length(L,10),time(length(L,X)).
% 2 inferences, 0.000 CPU in 0.000 seconds (63% CPU, 142857 Lips)

?- length(L,20),time(length(L,X)).
% 2 inferences, 0.000 CPU in 0.000 seconds (62% CPU, 153846 Lips)

?- length(L,30),time(length(L,X)).
% 2 inferences, 0.000 CPU in 0.000 seconds (65% CPU, 111111 Lips)

这是因为这个过程被委托给C吗?我在SWIPL代码库中找不到相关的代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-07 14:58:46

在init.pl中,length/2在第3230行附近有一个浅而强大的界面。在这里,它称'$skip_list'(Length0, List, Tail)为list C界面的“瑞士刀”。

您可以在src/pl-prims.c第2377行和以下内容中找到它:

代码语言:javascript
复制
/** '$skip_list'(-Length, +Xs0, -Xs) is det.

Xs0, Xs is a pair of list differences. Xs0   is the input list and Xs is
the minimal remaining list. Examination of   Xs  permits to classify the
list Xs0:

        Xs        | list type of Xs0   | Length
        []    ... | well formed        | length
        Var   ... | partial            | elements skipped
        [_|_] ... | infinite           | upper bound for cycle
        Term  ... | malformed          | elements skipped
*/
PRED_IMPL("$skip_list", 3, skip_list, 0)
...
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37088981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档