Prolog:错误:>/2:参数未充分实例化



在我的帖子结束的代码应该回答以下难题:

布朗、克拉克、琼斯和史密斯是四位有实权的公民他们的社区作为建筑师,银行家,医生和律师,虽然不是一定分别。布朗,他比布朗更保守琼斯比史密斯更自由,但他的高尔夫球打得比那些人好比他年轻,收入比他高比克拉克老。银行家挣得比建筑师多,但他既不是最年轻的也不是最年长的。

医生的高尔夫球打得比律师差,更少比建筑师保守。不出所料,最年长的人最保守,收入最高,而最年轻的人高尔夫球打得最好。每个人的职业是什么?


当我尝试启动代码时,我得到错误:

ERROR: >/2: Arguments are not sufficiently instantiated

代码是:

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% We represent each "person" with a six-tuple of the form
%
% [ name , profession , age , income , politics , golf ranking ]
%
% where name is either brown, clark, jones, or smith
%       profession is either banker, lawyer, doctor, or architect
%       age is a range 1 .. 4, with 1 being the youngest and 4 the oldest
%       income is a range 1 .. 4, with 1 being the least and 4 the most
%       politics is a range 1 .. 4, with 1 being conservative, 4 liberal
%       golf ranking is a range 1 .. 4, 1 for the best rank, 4 for the worst
%
solutions(L) :- L = [ [brown, _, _, _, _, _], [clark, _, _, _, _, _],
                      [jones, _, _, _, _, _], [smith, _, _, _, _, _] ],
                clue1(L),
                clue2(L),
                clue3(L),
                clue4(L),
                constrained_profession(L),
                constrained_age(L),
                constrained_income(L),
                constrained_politics(L),
                constrained_golf_rank(L).
%
% clue #1
% brown, who is more conservateive than jones but
% more liberal than smith, is a better golfer than
% the men who are younger than he is and has a larger
% income than the men who are older than clark
%
clue1(L) :- member(P1,L), member(P2,L), member(P3,L),
            P1 = [brown, _, A1, _, L1, G1],
            P2 = [jones, _, _, _, L2, _],
            P3 = [smith, _, _, _, L3, _],
            liberaler( P2, P1 ),
            liberaler( P1, P3 ),
            not( clue1_helper_a(L) ),
            not( clue1_helper_b(L) ).
% for all men younger than brown he is a better golfer ===>
% it is not the case that there exists a man younger than brown
% such that brown is not a better golfer than him.
% The "is not the case" is taken care of in clue1.
clue1_helper_a(L) :- member(P1,L), P1 = [brown, _, A1, _, L1, G1],
                     member(PU,L), PU = [_, _, AU, _, _, GU],
                     younger(PU,P1),
                     not(golfier(P1, PU)).
% for all men older than clark, brown makes more money than they do ===>
% it is not the case that there exists a man older than clark such that
% brown does not make more money than him.
% The "is not the case" is taken care of in clue1.
clue1_helper_b(L) :- member(P1,L), P1 = [brown, _, _, _, _, _],
                     member(P2,L), P2 = [clark, _, _, _, _, _],
                     member(PU,L), PU = [_, _, _, _, _, _],
                     younger(P2,PU),
                     not(richer(P1, PU)).
%
% clue #2
% the banker, who earns more than the archiect, is
% neither the youngest nor the oldest
%
clue2(L) :- member(P1,L), member(P2,L),
            P1 = [_, banker, A1, I1, _, _],
            P2 = [_, architect, _, I2, _, _],
            richer(P1,P2),
            not( A1 = 1 ),
            not( A1 = 4 ).
%
% clue #3
% the doctor, who is a pooer golfer than the lawyer, is
% less conservative than the architect. 
%
clue3(L) :- member(P1, L), member(P2, L), member(P3,L),
            P1 = [_,doctor, _, _, L1, G1],
            P2 = [_,lawyer, _, _, _, G2],
            P3 = [_,architect, _, _, L3, _],
            golfier(P2,P1),
            liberaler(P1,P3).
%
% clue #4
% as might be expected, the oldest man is the most
% conservative and has the largest income, and the 
% youngest man is the best golfer.
clue4(L) :- member(P1,L), member(P2,L),
            P1 = [_, _, 4, 4, 1, _],
            P2 = [_, _, 1, _, _, 1].
%
% relations
%
younger(X,Y) :- X = [_, _, AX, _, _, _], Y = [_, _, AY, _, _, _], AX < AY.
liberaler(X,Y) :- X = [_, _, _, _, LX, _], Y = [_, _, _, _, LY, _], LX > LY.
golfier(X,Y) :- X = [_, _, _, _, _, GX], Y = [_, _, _, _, _, GY], GX < GY.
richer(X,Y) :- X = [_, _, _, IX, _, _], Y = [_, _, _, IY, _, _], IX > IY.
%
% constraints
%
constrained_profession(L) :-
    member(P1,L), member(P2,L), member(P3,L), member(P4,L),
    P1 = [_, banker, _, _, _, _],
    P2 = [_, lawyer, _, _, _, _],
    P3 = [_, doctor, _, _, _, _],
    P4 = [_, architect, _, _, _, _].
constrained_age(L) :-
    member(P1,L), member(P2,L), member(P3,L), member(P4,L),
    P1 = [_, _, 1, _, _, _],
    P2 = [_, _, 2, _, _, _],
    P3 = [_, _, 3, _, _, _],
    P4 = [_, _, 4, _, _, _].
constrained_income(L) :-
    member(P1,L), member(P2,L), member(P3,L), member(P4,L),
    P1 = [_, _, _, 1, _, _],
    P2 = [_, _, _, 2, _, _],
    P3 = [_, _, _, 3, _, _],
    P4 = [_, _, _, 4, _, _].
constrained_politics(L) :-
    member(P1,L), member(P2,L), member(P3,L), member(P4,L),
    P1 = [_, _, _, _, 1, _],
    P2 = [_, _, _, _, 2, _],
    P3 = [_, _, _, _, 3, _],
    P4 = [_, _, _, _, 4, _].
constrained_golf_rank(L) :-
    member(P1,L), member(P2,L), member(P3,L), member(P4,L),
    P1 = [_, _, _, _, _, 1],
    P2 = [_, _, _, _, _, 2],
    P3 = [_, _, _, _, _, 3],
    P4 = [_, _, _, _, _, 4].
% end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

内置谓词(>)/2是一个所谓的建模的谓词。这意味着您只能在非常特定的情况下使用它。它不是一个可以在所有方向上使用的真关系。

要对整数进行更一般的推理,请使用Prolog系统的CLP(FD)约束而不是

例如,在GNU Prolog中,用(#>)/2 简单地替换(>)/2就足够了,以便更声明地对整数进行推理。

在其他Prolog系统中,当前可能需要导入专用库。例如,在SICStus Prolog中,您需要添加以下指令:

:- use_module(library(clpfd)).

到你的程序。

如果这样做,然后使用以下稍微修改过的谓词定义:

<>之前年轻的(X, Y): - X = [_, _, 斧头 , _, _, _], Y = [_, _, 唉 , _, _, _], AX # & lt;是的。自由(X, Y): - X = [_, _, _, _, LX, _), Y = [_, _, _, _, LY, _], LX #比;LY。golfier (X, Y): - X = [_, _, _, _, _, GX), Y = [_, _, _, _, _, GY) GX # & lt;GY。丰富的(X, Y): - X = [_, _, _, 第九,_,_),Y = [_, _, _, 第九IY _, _), #比;IY。之前

示例查询运行没有错误:

<>之前吗? (L)的解决方案。假。之前

然而,正如你所看到的,你的配方目前太具体了:没有找到一个解决方案。

考虑提交一个单独的问题,以查看如何调试此类问题。

相关内容

  • 没有找到相关文章

最新更新