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

Operator and Arithmetic ch.1

Posted by madmathc pada November 13, 2009

Hello bloggers….

Now I will show u how to solve Practical Exercise about Operator and Arithmetic in Prolog.  These are the question  :

(1) This program is based on Animals Program 3, given in Chapter 2.

dog(fido). large(fido).
cat(mary). large(mary).
dog(rover). small(rover).
cat(jane). small(jane).
dog(tom). small(tom).
dog(fred). large(fred).
cat(henry). large(henry).
cat(steve). large(steve).
large_dog(X):- dog(X),large(X).
small_animal(A):- dog(A),small(A).
small_animal(B):- cat(B),small(B).
write(X),write(‘ chases ‘),write(Y),nl.

Convert the seven predicates used to operator form and test your revised program. The output should be the same as the output from the program above. Include directives to define the operators in your program.

(2) Define and test a predicate which takes two arguments, both numbers, and calculates and outputs the following values: (a) their average, (b) the square root of their product and (c) the larger of (a) and (b).

Now, this is the answer….
Step 1 : Make your new rule in Notepad like this one…
Save it and don’t forget to type .pl at the end of your file name.

2.  Next, consult your file in Prolog. After that, type
?- X chases Y.
Then press Enter. After 1st answer, type ; to show another answer. This is the result…

gambar 4

Compare the result from the question above…


Same things, right….🙂


step1 : You must make rule like this…


Save it and don’t forget to type .pl at the end of your file name.

2.  Next, consult your file in Prolog. After that, try to type this…

?- pred(9,19).

Then press Enter. This is the result…

nomor 2

Those are the solution for this problem. For more explanation about this chapter, read Arithmetic n Operators ch. 2. This writing will be posted soon. Thank u and don’t forget to give a comment.🙂

Tinggalkan Balasan

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


You are commenting using your 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: