# First order logic and prologue

I am trying to understand how the prologue represents first order logic. as I can imagine, for example in a list of animal types:

dog (spot).

cat (nyny).

flies (harry)

that all animals are mammals or insects?

+3

source to share

I think you only mean the following:

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

```

That is, a mammal is what is a dog or a cat. You must explicitly indicate the categories that belong to this category of mammals. The same goes for insects.

Combining this with your first-order boolean question, the first entries `mammal`

will read: for each X, where X is a dog, X is also a mammal (same for cat), etc.

+4

source

I expanded on @ Diego Sevilla's answer to include the original question about what an animal is and added execution.

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

% @ Diego Sevilla 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.
```

```
+4

source

All Articles