Just started to learn Prolog, and cannot figure out how to get the result which involves "all true", for example:
preAction(4, 3).
preAction(4, 2).
preAction(2, 1).
action(4).
action(2).
action(1).
takeAction(X) :-
action(X),
preAction(X, Y),
action(Y).
The expected result is 2, because action(2)
and action(1)
all true.
But current result is 4 and 2. However the preAction
of 4 is (3,2) and there is no action(3)
. This is not what I want.
If I tried to use negation, since 4's preAction is provable, still cannot figure out how to do it. Do you know how to do it?