users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gprolog member/2 error ?!


From: Nicolas Pelletier
Subject: Gprolog member/2 error ?!
Date: Fri, 27 Aug 2010 11:04:41 +0900

Hello,

Pedro Fialho wrote:
> I get the result:
>
> [[[]-sing-[]-A-[],def-sing-[]-B-[],def-sing-[]-C-[],qual-sing-[]-D-[]]-
> ['conclusao'(A),'diagnostico'(B),paciente(C),
> nome(C,'Rita Ambrosio'),rel(de,A,B),rel(para,A,C)]-
> [ser(D,a:A)]|_]
>
> Which clearly doesn't fulfill the aux1/2 constraint, although the [R-C-P|Ls]
> contains the correct result (above stated).

Okay, I think I now understand what you are trying to do. You have a
list of what looks like parse results and would like to select from
them only those who verify an additional contraint involving the
comparison of variable instances, right? Then something like the
following will do it for you:

filterDRS(Ls, Ls1) :-
        findall(
            R-C-P,
            (   member(R-C-P, Ls1),
                aux1(C, P)
            ),
            Ls
        ).

aux1(C, P):-
        memberchk(rel(de,X,Y), C),
        memberchk(rel(para,Y0,_), C),
        Y == Y0,
        nth(1,P,Z),
        arg(2, Z, _:X).

Here is a trace of what I get:

%% address@hidden:~/tmp$ gprolog
%% GNU Prolog 1.3.0
%% By Daniel Diaz
%% Copyright (C) 1999-2007 Daniel Diaz
%% | ?- [toto].
%% compiling /home/nicolas/tmp/toto.pl for byte code...
%% /home/nicolas/tmp/toto.pl compiled, 49 lines read - 7042 bytes written, 19 ms
%%
%% yes
%% | ?- trace,do(L).
%% The debugger will first creep -- showing everything (trace)
%%       1    1  Call: do(_16) ?
%%       2    2  Call: filterDRS(_16,[[[]-sing-[]-_58-[],... - ...
-[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       3    3  Call:
findall(_277-_278-_281,(member(_277-_278-_281,[[... - ... -_58-[],...
- ... -[],... -
...,...]-[conclusao(_58),diagnostico(_70),paciente(...),...]-[ser(_94,a:_58)],[...
- ... -[],... -
...,...]-[conclusao(_157),diagnostico(...),...]-[ser(_193,a:_157)]]),aux1(_278,_281)),_16)
?
%%       4    4  Call: member(_277-_278-_281,[[[]-sing-[]-_58-[],... -
... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       4    4  Exit:
member([[]-sing-[]-_58-[],def-sing-[]-_70-[],... - ... -[]-_82-[],...
- ... -_94-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,...),rel(...,...)]-[ser(_94,a:_58)],[[[]-sing-[]-_58-[],...
- ... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       5    4  Call:
aux1([conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)],[ser(_94,a:_58)]) ?
%%       6    5  Call:
memberchk(rel(de,_367,_368),[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)]) ?
%%       6    5  Exit:
memberchk(rel(de,_58,_70),[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)]) ?
%%       7    5  Call:
memberchk(rel(para,_396,_397),[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)]) ?
%%       7    5  Exit:
memberchk(rel(para,_58,_82),[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)]) ?
%%       8    5  Call: _70==_58 ?
%%       8    5  Fail: _70==_58 ?
%%       5    4  Fail:
aux1([conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,_70),rel(para,_58,_82)],[ser(_94,a:_58)]) ?
%%       4    4  Redo:
member([[]-sing-[]-_58-[],def-sing-[]-_70-[],... - ... -[]-_82-[],...
- ... -_94-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(de,_58,...),rel(...,...)]-[ser(_94,a:_58)],[[[]-sing-[]-_58-[],...
- ... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       4    4  Exit:
member([[]-sing-[]-_157-[],def-sing-[]-_169-[],... - ...
-[]-_181-[],... - ...
-_193-[]]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,...),rel(...,...)]-[ser(_193,a:_157)],[[[]-sing-[]-_58-[],...
- ... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       5    4  Call:
aux1([conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)],[ser(_193,a:_157)])
?
%%       6    5  Call:
memberchk(rel(de,_367,_368),[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)]) ?
%%       6    5  Exit:
memberchk(rel(de,_157,_169),[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)]) ?
%%       7    5  Call:
memberchk(rel(para,_396,_397),[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)]) ?
%%       7    5  Exit:
memberchk(rel(para,_169,_181),[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)]) ?
%%       8    5  Call: _169==_169 ?
%%       8    5  Exit: _169==_169 ?
%%       9    5  Call: nth(1,[ser(_193,a:_157)],_487) ?
%%       9    5  Exit: nth(1,[ser(_193,a:_157)],ser(_193,a:_157)) ?
%%      10    5  Call: arg(2,ser(_193,a:_157),_475:_157) ?
%%      10    5  Exit: arg(2,ser(_193,a:_157),a:_157) ?
%%       5    4  Exit:
aux1([conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,_169),rel(para,_169,_181)],[ser(_193,a:_157)])
?
%%       4    4  Redo:
member([[]-sing-[]-_157-[],def-sing-[]-_169-[],... - ...
-[]-_181-[],... - ...
-_193-[]]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(_181,'Rita
Ambrosio'),rel(de,_157,...),rel(...,...)]-[ser(_193,a:_157)],[[[]-sing-[]-_58-[],...
- ... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       4    4  Fail: member(_277-_278-_281,[[[]-sing-[]-_58-[],... -
... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       3    3  Exit:
findall(_277-_278-_281,(member(_277-_278-_281,[[... - ... -_58-[],...
- ... -[],... -
...,...]-[conclusao(_58),diagnostico(_70),paciente(...),...]-[ser(_94,a:_58)],[...
- ... -[],... -
...,...]-[conclusao(_157),diagnostico(...),...]-[ser(_193,a:_157)]]),aux1(_278,_281)),[[[]-sing-[]-_338-[],...
- ... -[]-_352-[],... - ... -_366-[],... - ...
-[]]-[conclusao(_338),diagnostico(_352),paciente(_366),nome(_366,'Rita
Ambrosio'),rel(...,...),...]-[ser(_380,a:_338)]]) ?
%%       2    2  Exit: filterDRS([[[]-sing-[]-_338-[],... - ...
-[]-_352-[],... - ... -_366-[],... - ...
-[]]-[conclusao(_338),diagnostico(_352),paciente(_366),nome(_366,'Rita
Ambrosio'),rel(...,...),...]-[ser(_380,a:_338)]],[[[]-sing-[]-_58-[],...
- ... -[]-_70-[],... - ... -_82-[],... - ...
-[]]-[conclusao(_58),diagnostico(_70),paciente(_82),nome(_82,'Rita
Ambrosio'),rel(...,...),...]-[ser(_94,a:_58)],[... - ...
-[]-_157-[],... - ... -_169-[],... - ... -[],... -
...]-[conclusao(_157),diagnostico(_169),paciente(_181),nome(...,...),...]-[ser(_193,a:_157)]])
?
%%       1    1  Exit: do([[[]-sing-[]-_338-[],... - ...
-[]-_352-[],... - ... -_366-[],... - ...
-[]]-[conclusao(_338),diagnostico(_352),paciente(_366),nome(_366,'Rita
Ambrosio'),rel(...,...),...]-[ser(_380,a:_338)]]) ?
%%
%% L = 
[[[]-sing-[]-A-[],def-sing-[]-B-[],def-sing-[]-C-[],qual-sing-[]-D-[]]-[conclusao(A),diagnostico(B),paciente(C),nome(C,'Rita
Ambrosio'),rel(de,A,B),rel(para,B,C)]-[ser(D,a:A)]]
%%
%% yes
%% {trace}
%% | ?-

> Thank you very much for your help on this issue. I'm still confused in why
> the list changed...With your hint I got it done/unchanged but my
> understanding of unification still tells me the source should be alright
> (logically/mathematically speaking, the double negation shouldn't make
> difference).

You're welcome. The list changes as the result of the two following conditions:

1. your second memberchk line (not using double negation) uses the
same Y variable as the first memberchk.
2. In *both* lines, the rel/3 is matched by rel(de, X0, Y0), which is
not what you expected and causes X0 = Y0 = Y due to unification.

As for the rest, Prolog has both a declarative and an operational
semantics, and while its declarative semantics is a subset of
classical logic, its operational semantics (e.g. what the machine
really does) are not free of effects. So while it is true that X and
\+ \+ X have the same truth value from a declarative point of view,
operationally they have different _effects_; Prolog only implements an
approximation of logical negation: negation as failure (Note that some
Prologs provide additional negation operators with different
semantics).

I hope this helps you get matters sorted out.

-- 
Nicolas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]