Question

I am trying to understand how prolog represent first order logic. how can I represent for example, in a list of types of animals:

dog(spot).

cat(nyny).

fly(harry)

that all animals are mammals or insect?

Was it helpful?

Solution

I think what you're referring to is just the following:

mammal(X) :- dog(X).
mammal(X) :- cat(X).
insect(X) :- fly(X).

That is, a mammal is either something that is a dog or a cat. You have to explicitly specify the categories that fall into that mammal category. Same for insects.

Connecting this with your first-order logic question, the first entries of mammal would read: for every X where X is a dog, X is also a mammal (same for cat), and so on.

OTHER TIPS

I've extended @ Diego Sevilla's answer to include the original question of what an animal is, and added the execution.

% Your original facts
dog(spot).
cat(nyny).
fly(harry).

% @ Diego Sevilla's predicates
mammal(X) :- dog(X).
mammal(X) :- cat(X).
insect(X) :- fly(X).

% Defining what an animal is - either insect or (;) mammal
animal(X) :- insect(X) ; mammal(X). 

% Running it, to get the names of all animals
?- animal(X).
X = harry ;
X = spot ;
X = nyny.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top