2012-03-15 83 views
3

我想了解序言如何代表一阶逻辑。我怎么能代表,例如,在一个动物类型列表:一阶逻辑&序言

狗(现货)。

cat(nyny)。

fly(哈里)

所有的动物都是哺乳动物或昆虫?

回答

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.