3
Q
一阶逻辑&序言
A
回答
4
我想你指的就是以下几点:
mammal(X) :- dog(X).
mammal(X) :- cat(X).
insect(X) :- fly(X).
也就是说,哺乳动物或者是东西是狗或猫。您必须明确指定属于该哺乳动物类别的类别。昆虫也一样。
与一阶逻辑问题连接这一点,mammal
第一项内容如下:为每一个X,其中X是狗,X也为哺乳动物(同为猫),依此类推。
4
我已经延长@迭戈塞维利亚的答案,包括什么是动物的原始问题,并添加了执行。
% 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.