Complete prolog beginner here.
Let's say I have a prolog knowledge base which contains food and it's price, for example:
food(banana,99).
etc.
I'm trying to write a predicate that will return true if there are two or more items in the knowledge base that have the same price. The problem I'm encountering is that the query I've written:
multiple(X) :- food( _ ,X), food( _ ,X).
will return true if there is only one item in the database with price X. I understand what the problem is (that it's finding the same item twice and returning true), but I don't understand how to write a query that will find two or more unique items from food.
I've tried writing a 'unique' rule, as follows:
multiple(X) :- food(Y,X), food(Z,X), unique(Y,Z).
unique(Y,Z) :- Y /= Z
But that doesn't seem to work.
Thanks.