Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

first order logic & prolog

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?

like image 739
cubearth Avatar asked Jul 04 '26 13:07

cubearth


2 Answers

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.
like image 198
magus Avatar answered Jul 08 '26 00:07

magus


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.

like image 37
Diego Sevilla Avatar answered Jul 07 '26 23:07

Diego Sevilla