Hi guys :) I have encountered problem during programming in prolog. I have partial order defined as facts, and I have defined maximal and greatest element as predicates. We can think of partial order like greater or equal, so le(6,7) is something like 6 <= 7.
le(6,7).
le(4,4).
le(6,6).
le(5,6).
le(5,5).
le(4,5).
le(4,4).
maximal(X) :-
not((le(X,Z) , X\=Z)).
greatest(X) :-
not(le(X,_)).
minimal(X) :-
not((le(Z,X) , X\=Z)).
smallest(X) :-
not(le(_,X)).
When I have typed query like maximal(7) the prolog output is true, and when I ask prolog to find the solution like maximal(X) it gives mi fail. I am beginner prolog programmer, so sorry if the question is too trivial, but I couldn't find the solution on my own.
notso much, if possible. Prolog can't "generate" a solution often times when there's negation involved unless it knows what the "universe of choices" is. For example, if you had a trivial predicate,is_seven(X) :- X = 7, you could queryis_seven(X)and getX = 7. However, if you haveis_not_seven(X) :- X \= 7.(oris_not_seven(X) :- not(X = 7).)` A query likeis_not_seven(X)fails because Prolog doesn't know what possible values ofXto consider. - lurkermaximal(7)succeeds, so doesmaximal(8). So that's a problem, right? Also part of the "universe of choices" issues. - lurkerle(X,_)or( le(X,_) ; le(_,X) )outside the negation, to get the numbers. - Tomas By