Jump to a section of this page...
terminology
Don't forget the closed-world assumption!
Carrots, broccoli, spinach, and corn are vegetables. Broccoli and spinach are green, corn is yellow, and carrots are orange. Apples, oranges, and bananas are fruit. Apples can be green, yellow, or red. Oranges are, well, orange. Bananas are yellow. Which of these foods are/can be yellow?
fraction(Num,Den). /* or fraction(_,_). */ lt(fraction(Num1,Den1),fraction(Num2,Den2)) :- Num1 * Den2 < Num2 * Den1. length([], 0). length([H|T], L) :- length(T, M), L is M + 1.
one(X,[X|_]). one(X,[_|Y]) :- one(X,Y). two([]). two([_]). two([A,B|T]) :- A =< B, two([B|T]). three([], 0). three([First|Rest], S) :- three(Rest, RS), S is First + RS.
sample database for first paragraph:
sample query for question "What are the northern east coast states?":westCoast(wa). westCoast(or). westCoast(ca). eastCoast(ri). eastCoast(ny). eastCoast(nc). eastCoast(va). northern(ri). northern(ny). northern(wa). northern(or).
northern(State), eastCoast(State).
sample database for first paragraph:
sample query for question "Which of these foods are/can be yellow?":vegetable(carrots). vegetable(broccoli). vegetable(spinach). vegetable(corn). green(broccoli). green(spinach). yellow(corn). orange(carrots). fruit(apples). fruit(oranges). fruit(bananas). green(apples). yellow(apples). red(apples). orange(oranges). yellow(bananas).
yellow(Food).
Predicate one might more appropriately be called isMember, because it is true if the first argument is an element of the list which is the second argument.
Predicate two could be called inOrder, because it is true if the given list is in sorted (increasing) order.
Predicate three could be called sumList, because it is true if the second argument is the length of the list given as the first argument.