第一个参数索引 [英] First argument indexing

查看:109
本文介绍了第一个参数索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在各种Prolog实现上如何实现智能的第一个参数索引。

I want to know how smart first argument indexing is implemented on various Prolog implementations.

特别是简单的类型测试目标,如整数/ 1 在一个条款颈部可以有助于更好的索引。
考虑:

In particular, simple type-test goals like integer/1 right after a clause "neck" could contribute to better indexing. Consider:

foo(h(X),X).
foo([],nil).
foo([_|_],cons).
foo(X,Y) :- integer(X), Y = n(X).

通过这个子句排序,我希望目标 foo([],_ )成功没有留下任何无用的选择点。

With this clause ordering I would like the goal foo([],_) to succeed without leaving any useless choicepoints.

不幸的是,SWI Prolog并没有弄明白:

Unfortunately, SWI Prolog does not figure it out:

?- length(Xs,10),
   maplist(=([]),Xs),
   statistics(trailused,T1),
   maplist(foo,Xs,Ys),
   statistics(trailused,T2).

T1 = 5792,
T2 = 5968,
Xs = [[], [], [], [], [], [], [], [], [], []],
Ys = [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] ...

其他Prolog实现做得更好吗?

Do other Prolog implementations do better?

推荐答案

YAP另一个Prolog系统提供谓词子句的扩展索引:

YAP is another Prolog system providing extending indexing of predicate clauses:

$ yap
YAP 6.3.4 (x86_64-darwin14.3.0): Wed Apr 22 22:26:34 WEST 2015
 ?- [user].
 % consulting user_input...
foo(h(X),X).
|     foo([],nil).
|     foo([_|_],cons).
|     foo(X,Y) :- integer(X), Y = n(X).
|      % consulted user_input in module user, 1 msec 0 bytes
true.
 ?- foo([],_).
true.

有关YAP索引功能的一些相关文章是:

Some relevant papers on YAP indexing features are:

  • Demand-Driven Indexing of Prolog Clauses
  • On Just in Time Indexing of Dynamic Predicates in Prolog

这篇关于第一个参数索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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