Beruflich Dokumente
Kultur Dokumente
/* animal.pro
animal identification game.
go :- hypothesize(Animal),
write('I guess that the animal is: '),
write(Animal),
nl,
undo.
/* hypotheses to be tested */
hypothesize(cheetah) :- cheetah, !.
hypothesize(tiger) :- tiger, !.
hypothesize(giraffe) :- giraffe, !.
hypothesize(zebra) :- zebra, !.
hypothesize(ostrich) :- ostrich, !.
hypothesize(penguin) :- penguin, !.
hypothesize(albatross) :- albatross, !.
hypothesize(unknown). /* no diagnosis */
ostrich :- bird,
verify(does_not_fly),
verify(has_long_neck).
penguin :- bird,
verify(does_not_fly),
verify(swims),
verify(is_black_and_white).
albatross :- bird,
verify(appears_in_story_Ancient_Mariner),
verify(flys_well).
/* classification rules */
mammal :- verify(has_hair), !.
mammal :- verify(gives_milk).
bird :- verify(has_feathers), !.
bird :- verify(flys),
verify(lays_eggs).
carnivore :- verify(eats_meat), !.
carnivore :- verify(has_pointed_teeth),
verify(has_claws),
verify(has_forward_eyes).
ungulate :- mammal,
verify(has_hooves), !.
ungulate :- mammal,
verify(chews_cud).
:- dynamic yes/1,no/1.
The program is mainly interesting with regard to how it tries to verify certain properties that it
uses to draw conclusions, and how it asks questions and records the answers for further
reference. If a question q is asked and the answer is 'yes', then that answer is recorded by
asserting 'yes(q)' and succeeding, otherwise the answer is recorded by asserting 'no(q)' and
failing. Even 'yes' answers need to be recorded since a subsequent 'no' answer to a different
question while trying to verify the same hypothesis may cause the entire hypothesis to fail, but
that same 'yes' answer could lead to a successful verification of a different hypothesis later. This
is how the program avoids asking the same question twice. The general method of verifying a
condition q is then to check whether 'yes(q)' has been stored in memory, and succeed, or 'no(q)'
has been stored, and fail, otherwise ask(q).