, , .
1. .
2. , .
3. .
1 - . , , 15. . , . 16.1, , . , ; , .
16.1. . [170]. "askable" , . ":: ", i f, then, and, or , 16.3
% I- { 100, xfx, (has, gives, 'does not', eats, lays, isa]).:- op£ 100, xfr [ swims, flies]).
rulel:: if
Animal has hair
or
Animal gives milk
then
Animal isa mammal.
rule2;: if
Animal has feathers
or Animal flies and Animal lays eggs then
Animal isa bird.
rule3:: if
Animal isa mammal and
(Animal eats meat or Animal has 'pointed teeth' and Animal has claws and Animal has "forward pointing eyes') then
Animal isa carnivore.
rule4:; if
Animal isa carnivore and
Animal has 'tawny color' and
Animal has 'dark spots'
then
Animal isa cheetah.
rules:: if
Animal isa carnivore and Animal has 'tawny color' and Animal has 'black stripes' then
Animal isa tiger.
rule6:: if
Animal isa bird and Animal 'does not' fly and Animal swims then
Animal isa penguin,
Eule7:: if
Animal isa bird and Animal' isa 'good flyer1
then
Animal isa albatross.
358 II. Prolog
fact:: X isa animal:-member{ X, [cheetah, tiger, penguin, albatross]).
askablet _ gives _, 'Animal' gives 'What')-
askablet _ flies, -Animal' flies).
askablet _ lays eggs, 'Animal' lays eggs).
askable; _ eats _, 'Animal' eats 'What").
askable(_ has _, 'Animal' has 'Something').
askablet _ 'does nor.' _, 'Animal' 'does not' fly).
askablet _ swims, 'Animal' swims).
askablet isa 'good flyer1, "Animal' isa 'good flyer')
: RuleKame:: if Condition then Conclusion.
Condition () - , and or, a Conclusion () , . , not, , Prolog (. 16.1) Prolog. and , or, .
|
|
, , . , . , . . 16.1. : if
light 1 is on and % 1
lightl is not working and % 1
fusel is proved intact % , 1 ,
then
lightl is proved broken. 1 , 1
. i f
heater is working % ,
then
fusel is proved intact. % , 1
( ), lightl fusel, lightl heater . . , Prolog, , . : , -
16.
, . : broken rule:: if Device is on and
not [ Device is working) and
Device is connected to Fuse and
Fuse is proved intact then
Device is proved broken.
, , 16.2.
-
light!
fusel
-
1ight2
heater
,
Iighl3
fuse2
.
Iight4
. 16.1.
16.2. , . 16.1
" """
% , , %
broken rule:: if _
on(Device) and device! Device) and (not working(Device)) and connected(Device, Fuse) and
proved(intact! Fuse)) then
proved! broken! Device)).
%
,
fuse ok rule::
if
connected! Device, Fusel and
working! Device) then
|
|
proved! intact(Fuse))
II. Prolog
% ) , * , . : !
fused rule::
if
connected< Devicel, Fuse) and onf Devicel) and [not working! Devicel)) and samefuse [ Device2, Devicelj and pn (Device2) and [not working< Device2)) then
proved! failed(Fuse)).
same_fuse_rule::
if
connected; Devicel, Fuse) and connected; Device2, Fuse) and different! Devicel, Device2) then satnefuset Devicel, Device2).
device on rule::
if
working(Device) then
on(Device).
fact;: different! X, Y)
fact:: device(heater).
fact:: device! lightl).
fact:: device! lightZ).
fact:: device! light3).
fact:: device! lights).
: -
not (X - Y)
fact fact fact fact fact
:
::
:
::
:
connected! lightl, fusel). connected! lightZ, fusel). connected! heater, fusel). connected! Iight3, fuse2). connected!' lights fuse2).
askable(on[D), on('Device*))-
askable! working ID), working!'Device'])