indexing - 第一个参数索引

标签 indexing prolog

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

尤其是,在子句“ neck”之后的简单类型测试目标(例如integer/1)可能有助于更好地建立索引。
考虑:

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


通过此子句排序,我希望目标foo([],_)成功而不会留下任何无用的选择点。

不幸的是,SWI Prolog没有弄清楚:

?- 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实施效果更好吗?

最佳答案

YAP是另一个Prolog系统,可提供扩展的谓词从句索引:

$ 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索引功能的一些相关论文包括:


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

关于indexing - 第一个参数索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29605132/

相关文章:

prolog - 为什么我的谓词不起作用,而类似的谓词却起作用?

.net - 使用 .NET 进行 Prolog

database - 数据库索引是否反向工作?

python - 从python pandas中的列名获取列索引

python - 比较两个列表,保留重复项但删除 Python 中索引位置中的相同项

excel - excel中的数据库vlookup有什么问题

r - 使用 data.table 索引序列 block

list - 识别 DCG 中的模式

prolog - 递归 Prolog 谓词?

python - 从 python 调用序言谓词