prolog-dif

What is the logical 'not' in Prolog?

不羁岁月 提交于 2019-11-26 02:38:58
问题 The problem that I face, is a bit trivial. I want to use logical not in Prolog, but it seems that not/1 is not the thing that I want: course(ai). course(pl). course(os). have(X,Y) :- course(X),course(Y),not(X = Y). I query: have(X,Y), write(X-Y), nl , fail. And I do not get the result I want :( 回答1: In place of not(X = Y) you need to write \+ X = Y or X \= Y . But consider to use dif(X,Y) instead. dif/2 is present in B, SWI, YAP, SICStus. To see the difference: ?- X = b, dif(a, X). X = b. ?-

Reification of term equality/inequality

血红的双手。 提交于 2019-11-26 00:21:13
问题 Pure Prolog programs that distinguish between the equality and inequality of terms in a clean manner suffer from execution inefficiencies ; even when all terms of relevance are ground. A recent example on SO is this answer. All answers and all failures are correct in this definition. Consider: ?- Es = [E1,E2], occurrences(E, Es, Fs). Es = Fs, Fs = [E, E], E1 = E2, E2 = E ; Es = [E, E2], E1 = E, Fs = [E], dif(E, E2) ; Es = [E1, E], E2 = E, Fs = [E], dif(E, E1) ; Es = [E1, E2], Fs = [], dif(E,