【问题标题】:Why doesn't 'Q' unify in this PROLOG program为什么这个PROLOG程序中'Q'不统一
【发布时间】:2010-03-27 14:47:04
【问题描述】:

我正在编写一个 PROLOG 程序,其中感兴趣的变量 (Q) 拒绝统一。我已经通过一个 hacky 解决方案(包括 write 声明)解决了这个问题。但总得有办法让这个统一起来,但看在我的份上,我想不通。

非常感谢任何帮助。 提前致谢。

这是我的代码(为简洁起见,我在排除代码的地方都做了注释)

:- use_module(library(bounds)).
:- use_module(library(lists)).

solve([17],Q,_,_,_):- write(Q). %this is the hacky workaround
solve(L,Q,1,3,2) :- jump(L,Q,N,1,3,2,R), solve(N,R,S,D,M), member([S|[D|[M|[]]]],[[1, 3, 2], [1, 9, 4], [2, 10, 5] this list contains 76 items - all of which are lists of length 3. I have omitted them here for the sake of brevity]).
% there are about 75 other definitions for solve, all of which are structured exactly the same. The only difference is that the numbers in the input parameters will be different in each definition

jump(L,Q,N,S,D,M,R):- member(S,L), not(member(D,L)), member(M,L), delete(L,S,X), delete(X,M,Y), append(Y,[D],N), append(Q,[[S,D]],R).

cross_sol(Q) :- solve([5,9,10,11,17,24],Q,S,D,M), member([S,D,M], [
I have edited out this list here for the sake of brevity. It is the same list found in the definition of solve
]).

由于某种原因,Q 没有统一。请帮忙! 谢谢!

【问题讨论】:

    标签: prolog


    【解决方案1】:

    cross_sol/1 谓词似乎格式不正确。

    cross_sol(Q) :- solve([5,9,10,11,17,24],[],S,D,M), member([S,D,M], [ I have edited out this list here for the sake of brevity. It is the same list found in the definition of solve ]).

    变量 Q 是一个单例——它在正文的任何​​地方都没有被引用(除非它是您已抑制的部分)。

    【讨论】:

    • 不,Q不在我压制的部分。但是,我确实考虑了您的回答并更改了 cross_sol(Q) (如对我上面代码的编辑中所示),但这似乎并没有改变任何东西。
    • 现在我可以稍微测试一下你的代码了。 cross_sol(Q) 查询失败。失败是由于目标“成员(S,L)”上的跳转([5,9,10,11,17,24], Q, N, 1, 3, 2, R)。 S 为 1,L 为 [5,...,24]。 L中没有1。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多