MAD…..Math_C

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).
cat(harry).
dog(fred). large(fred).
cat(henry). large(henry).
cat(bill).
cat(steve). large(steve).
large(jim).
large(mike).
large_dog(X):- dog(X),large(X).
small_animal(A):- dog(A),small(A).
small_animal(B):- cat(B),small(B).
chases(X,Y):-
large_dog(X),small_animal(Y),
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….
1)
Step 1 : Make your new rule in Notepad like this one…
step_1
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…

step3

Same things, right….🙂

2)

step1 : You must make rule like this…

untitled

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:

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: