2
votes

To determine the animal is bulldog, I have the following predicates:

bulldog(X):-
    body(X,muscular),
    weight(X,heavy),
    face(X,wrinkled),
    nose(X,pushed-in).

If I had a dog, call him "fifi", and the following facts:

body(fifi,muscular).
weight(fifi,heavy).
face(fifi,wrinkled).
nose(fifi,pushed-in).

When I enter the following statement:

bulldog(fifi).

it will return true.

Lets now say I had another bulldog "fofo" and following predicate:

bulldog(fofo).

When I ask something like

body(fofo,muscular). / weight(fofo,heavy).

then it will return false. What can I do to let Prolog recognize the characteristic of the bulldog, and return true?

2

2 Answers

1
votes

You'll have to add extra facts about fofo to the knowledge base. Prolog makes a closed-world assumption, meaning anything not provable from the facts/rules listed in the program is simply false.

1
votes

what you wrote is that something is a bulldog IF it's muscular, heavy, wrinkled and pushed-in but no that if something is a bulldog then it would be muscular, heavy, wrinkled in pushed-in.

to do that you could write:

body(X,muscular):-
   bulldog(X).

etc...

However, if you have:

body(X,muscular):-
   bulldog(X).

bulldog(X):-
  body(X,muscular),
  ....

you will get stuck in a infinite loop. you could solve it by using different predicate names:

body(X,muscular):-
   bulldog(X).

is_bulldog(X):-
  body(X,muscular),
  ....

or somehow detect the loop and stop it (some prolog versions like XSB support tabling)