cub*_*rth 3 prolog first-order-logic
我试图了解 prolog 如何表示一阶逻辑。例如,我如何在动物类型列表中表示:
狗(点)。
猫(尼尼)。
飞(哈利)
所有的动物都是哺乳动物还是昆虫?
我已经扩展了@ Diego Sevilla 的答案,以包含关于动物是什么的原始问题,并添加了执行。
% 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.
Run Code Online (Sandbox Code Playgroud)