MAD…..Math_C

We are NOT MAD! but we are Member At Discrete Math C….

Facts, Rules, Predicates, and Variables in PROLOG

Posted by madmathc pada Oktober 21, 2009

(1) Type the following program into a file and load it into Prolog.

/* Animals Database */
animal(mammal,tiger,carnivore,stripes).
animal(mammal,hyena,carnivore,ugly).
animal(mammal,lion,carnivore,mane).
animal(mammal,zebra,herbivore,stripes).
animal(bird,eagle,carnivore,large).
animal(bird,sparrow,scavenger,small).
animal(reptile,snake,carnivore,long).
animal(reptile,lizard,scavenger,small).

Devise and test goals to find (a) all the mammals, (b) all the carnivores that are mammals, (c) all the mammals with stripes, (d) whether there is a reptile that has a mane.

(2) Type the following program into a file

/* Dating Agency Database */
person(bill,male).
person(george,male).
person(alfred,male).
person(carol,female).
person(margaret,female).
person(jane,female).

Extend the program with a rule that defines a predicate couple with two arguments, the first being the name of a man and the second the name of a woman.
Load your revised program into Prolog and test it.

Okay, guys! This is our homework for this time. So, how can we find the answer? Now, this is the solution….
Question Number 1
1. Type all words in the box in Notepad, save it and don’t forget to insert .pl at the end of your name.

Clip_5

2. Consult your saved file in PROLOG.
3. To find the answer of number 1.a, you must type this.
?- animal(mammal,X,_,_).
Then press Enter.
4. To find another answers, type ; then another answers can appear until word No appears. It means there is no answer again.

Clip_6

5. To find the answer of number 1.b, you must type this.
?- animal(mammal,Y,carnivore,_).
Then press Enter.
6. To find another answer, follow the instruction number 4.

Clip_7

7. To find the answer of number 1.c, you must type this.
?- animal(mammal,Z,_,stripes).
Then press Enter.
8. To find another answer, follow the instruction number 4.

Clip_8

9. To find the answer of number 1.d, you must type this.
?- animal(reptile,R,_,mane).
Then press Enter.
10. The answer must be No, because there is no reptile has mane in that program.

Clip_9

Question Number 2

1. Type all words in the box in Notepad.
2. We must make a rule to find all possible couples. The couple must a man and a woman, not both of them are men or women. So the correct rule for this problem is :
couple(X,Y) :- person(X,male),person(Y,female).
3. Type it and save but don’t forget to insert .pl at the end of your name.

Clip_104. Consult your saved file in PROLOG.
5. To find the answer, type this
?- couple(X,Y).
Then press Enter.
4. To find another answers, type ; then another answers can appear until word No appears. It means there is no answer again.

Clip_11
This is the end of this section. Don’t forget to give comment for our blog. Thank u. (^_^)!!

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: