Tuesday, November 24, 2009

Expert System for Horoscope

Our Expert system is about horoscope. It’s a simple idea but it’s more useful for our daily life. Why we choose this idea, because we know that many people don’t know about horoscope. They are just know date of born. Not the horoscope. So we choose this idea, the advantage of this idea is we can classification based on the date of born. After we know the date of born, we can conclude what the horoscope. This the classification based on date of born.

  1. If there is people has date of born 22 December -19 January we can conclude the horoscope is Capricorn.
  2. If there is people has date of born 20 January -18 February we can conclude the horoscope is Aquarius.
  3. If there is people has date of born 19 February -20 March we can conclude the horoscope is Pisces.
  4. If there is people has date of born 21 March -19 April we can conclude the horoscope is Aries.
  5. If there is people has date of born 20 April - 20 May we can conclude the horoscope is Taurus.
  6. If there is people has date of born 21 May - 21 June we can conclude the horoscope is Gemini.
  7. If there is people has date of born 22 June - 22 July we can conclude the horoscope is Cancer.
  8. If there is people has date of born 23 July - 22 August we can conclude the horoscope is Leo.
  9. If there is people has date of born 23 August -22 September we can conclude the horoscope is Virgo.
  10. If there is people has date of born 23 September-23 October we can conclude the horoscope is Libra.
  11. If there is people has date of born 24 October – 21 November we can conclude the horoscope is Scorpio.
  12. If there is people has date of born 22 November- 21 December we can conclude the horoscope is Sagittarius

Read more...

Thursday, November 12, 2009

Operator and Arithmatic Part 1 & 2

In this post, We make two tutorial.

First, We will show about how to program Prolog which will make output the animal chases another animal or not. This is the source code :

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.

It means that if user type chases(animal1,animal2) which animal1 and aimal2 is member of source, Prolog will check "Is animal1 a large dog and animal2 a small dog OR small cat OR not ?". If It's true, Prolog will make output animal1 chases animal2. And if It's false, Prolog will make output No.

But, what about if We want to use operator ?. We use this source :

?-op(150,xf,is_large).
?-op(150,xf,is_small).
?-op(150,xf,isa_large_dog).
?-op(150,xf,isa_small_animal).
?-op(150,xfy,chases).
fido isa_dog. fido is_large.
mary isa_cat. mary is_large.
rover isa_dog. rover is_small.
jane isa_cat. jane is_small.
tom isa_dog. tom is_small.
harry isa_cat.
fred isa_dog. fred is_large.
henry isa_cat. henry is_large.
bill isa_cat.
steve isa_cat. steve is_large.
jim is_large.
mike is_large.
X isa_large_dog:- X isa_dog,X is_large.
A isa_small_animal:- A isa_dog,A is_small.
B isa_small_animal:- B isa_cat,B is_small.
X chases Y:- X isa_large_dog,Y isa_small_animal,write(X),write(' chases '),write(Y),nl.

Note :
"op" is a predicate at the system prompt. 150 is the 'operator precedence', which is an integer from 0 upwards. The range of numbers used depends on the particular implementation. The lower the number, the higher the precedence. Operator precedence values are used to determine the order in which operators will be applied when more than one is used in a term. The most important practical use of this is for operators used for arithmetic, as will be explained later. In most other cases it will suffice to use an arbitrary value such as 150. The second argument should normally be one of the following three atoms: xfy meaning that the predicate is binary and is to be converted to an infix operator fy meaning that the predicate is unary and is to be converted to an prefix operator xf meaning that the predicate is unary and is to be converted to a postfix operator. The third argument specifies the name of the predicate that is to be converted to an operator.

Step 1

Type the source in the text editor (ex. notepad). This is the code of first program and second program (using operator)

Save it by extention (*.pl) or (*.pro). For example, We named it animal2.pro for the first program, and animal3.pro for the second program.

Note : Must be saved in directory My Documents\Prolog















(Click the image if you can't see well)

Step 2

Now, open Prolog and open the file with command consult.

Don't worry about notification from Prolog.






























(Click the image if you can't see well)

Step 3

Okay, let's check our program. For example, type chases(fido,tom). Or you can type "fido chases tom". (without quotes)

Prolog make output "fido chases tom". It's because fido is large dog and tom is small dog. So fido can chases tom.













































(Click the image if you can't see well)

Step 4

Let's check again with another name.






























(Click the image if you can't see well)


Now, this is the second tutorial.

It's about how to program Prolog which can 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).

The logic of the program is if user type number1 and number2, Prolog will calculate average, square root of their product, and the larger of average and square root of both numbers's product.

Step 1

First, make logic which Prolog can make output average of two number. Average from two number is number1 + number2 and then divide it with 2. The logic is like this "A is (X+Y)/2." A is variable which handle the result from (X+Y)/2. X and Y are number1 and number2.

Step 2

Make logic which Prolog can make output square root of both number's product. The product of two numbers is number1 * number2 or can type like this : "B is (X*Y)". B is variable which handle the result from (X*Y). X and Y is number1 and number2. And then, make square root from the result of (X*Y). The logic is like this : "C is sqrt(B)". B is variable which handle the result from (X*Y) and C is variable which handle the result from square root (X*Y).

Step 3

Make logic which Prolog can make output the larger between average and square root of both numbers's product. The logic is like this : A<C,write(C),write(' is larger than '),write(A),nl;A>C,write(A),write(' is larger than '),write(C),nl.

It's means that IF A less than C then print C and give string "is larger than" and the last print A OR (";" means OR) IF A bigger than C then print A and give string "is larger than" and the last print C.

Step 4

Okay, let's make the source code for our program. Type like this at text editor :

number(X,Y):-A is (X+Y)/2,nl,write('the average is '),write(A),nl,nl,B is (X*Y),C is sqrt(B),write('the squareroot from the product of numbers is '),write(C),nl,nl,(A<C,write(C),write(' is larger than '),write(A),nl;A>C,write(A),write(' is larger than '),write(C),nl).


This code consist of average logic, square root of both numbers's product logic, and larger output logic.
















(Click the image if you can't see well)

Step 5

Now, save it by extention (*.pl) or (*.pro). For example, We named it number.pro.
















(Click the image if you can't see well)

Step 6

Now, open Prolog and open the file with command consult.
















(Click the image if can't see well)

Step 7

This is time to check our program. First, try it by typing : number(1,2).






























(Click the image if can't see well)

Then, try it by typing : number(5,3).
















(Click the image if you can't see well)

Read more...

The Summary of chapter 4 : "Operator and Arithmetic in Prolog"

1. Operators

There is a another model to write a predicate beside default predicate that we already had been studied before.To binary predicate in which its has 2 argument can be changed as form infix operators.example:
(izzat,nganjuk)
The default predicate like in the top,can be changed to infix operator.
Izzat dari nganjuk
Then for unary predikat's form can be changed as form prefix operator or postfix is operator. Example:
Crazy of reza
that form is changed as prefix operator
reza crazy
or can also be changed as postfix operator
reza was so crazy.

2. Arithmetic

Prolog was provide to do aritmatik's extrapolation utilize kindred notation with Aribase algebra.
Study about aritmatik in prologue is divided as some part. Such as;

Arithmetic operators

a. In this case,there is variable-variable to make program using prolog. This is table below shows of the arithmetic operators and aritmatic fungtions avaible in prolog.

X+Y the sum of X and Y
X-Y the difference of X and Y
X*Y the product of X and Y
X/Y the quotient of X and Y
X//Y the 'integer quotient' of X and Y (the result is truncated to the
nearest integer between it and zero)
X^Y X to the power of Y
-X the negative of X
abs(X) the absolute value of X
sin(X) the sine of X (for X measured in degrees)
cos(X) the cosine of X (for X measured in degrees)
max(X,Y) the larger of X and Y
sqrt(X) the square root of X

b. Operator Precedence in aritmetic Expressions.

Prologue utilizes ordinary algebra algorithms in aritmathic operation.Its exampleA + B*C - D.. In ajabar c and d. is multiplied earlier then added by a. then lessened with D. AT prologue also such. exept, we stay to utilize bracket. Example: (A. + B)* (C + D.).

c. Relational Operators

Operator as =, !=, >,>=, <, =<, can be utilized at Prologue. Utilized to compare two variables.

3. Equality Operators.


This is list of Equality Operators that it used in prolog of each operator.
Arithmetic Expression Equality =:=
a.Arithmetic Expression Inequality =\=
b.Terms Identical ==
c.Terms Not Identical \==
dTerms Identical With Unification =
e Non-Unification Between Two Terms \=

4. Logical operators.


This section gives a brief description of two operators that take arguments that are
call terms, i.e. terms that can be regarded as goals.

a. The not operator

The prefix operator not can be placed before any goal to give its negation. Thenegated goal succeeds if the original goal fails and fails if the original goal succeeds. This is example of example of The not operator.
?- not dog(fido).
no
?- dog(fred).
no
?- not dog(fred).
yes
?- X=0,X is 0.
X = 0
?- X=0,not X is 0.
no

b. The disjunction Operator

The disjunction Operator is use to represent “or”.example:
?- 6<3;7 is 5+2.
yes
Operators and Artithmetic 67
?- 6*6=:=36;10=8+3.
yes

Read more...

About This Blog

This Blog created to complete Discrete Math Assignment. This Blog contain all about discrete math subject especially Prolog programming. The member of team are Fahri Reza, Izzat, Chandra and Catur. We are from Discrete Math class A at Information System Department faculty of Information Technology INSTITUT TEKNOLOGI SEPULUH NOPEMBER (ITS) Surabaya. We hope all existing posts on this blog will be useful for all people. And thanks for visiting our Blog..

Followers

  © Blogger template PingooIgloo by Ourblogtemplates.com 2009 | The Permutation Team's Blog 2009

Back to TOP