Selasa, 22 Desember 2009

Final Project Expert System

So, our final project expert system has done.

We often find students of senior high school feel confuse about university’s majors that they will take. According to our survey, 3 of 5 students of senior high school in the third grade still don’t decide what kind of major that they will choose. It is because they are lack of information about kind of majors, what subject that they will learn in those majors, and which universities that provide those majors. From that problem, we make a simple expert system by using prolog that helps them identifying the subject that they will learn if they choose a certain major. And more information in which universities that provide the majors.

Here is the link of our report:

http://www.4shared.com/file/179094754/a1e42b66/Report_FP_matdis_Irine_Rizqi_B.html

Source code:

http://www.4shared.com/file/179101122/f2d925c0/aaaaaaaaaaaaaa.html

Senin, 14 Desember 2009

Testing

Development of our simple EXPERT SYSTEM
1. Firstly, we made a notepad that contain of the facts, or we can say it as characteristic of each major. We still develop it in a simple way. We divided the characteristic into 3 parts (major in senior high school, faculty, major in university). Then we save it in .pl type.




















2. Then we opened SWI Prolog and consult the notepad. We entered an example instruction like this: jurusan(ipa,_,A). Press enter, and ';' for the next result. It will show the possibility of major if we choose IPA as favourite subject.

our next development will show another characteristic to specify the suitable major ^_^

Selasa, 08 Desember 2009

Summary for chapter 6

Introduction

Most conventional programming languages have a looping facility that enables a set of instructions to be executed repeatedly either a fixed number of times or until a given condition is met.

Prolog has no looping facilities, similar effects can be obtained that enable a sequence of goals to be evaluated repeatedly. This can be done in a variety of ways, using backtracking, recursion, built-in predicates, or a combination of these.

Looping a Fixed Number of Times

Many programming languages provide 'for loops' which enable a set of instructions to be executed a fixed number of times. No such facility is available in Prolog (directly), but a similar effect can be obtained using recursion.

Looping Until a Condition Is Satisfied

Many languages have an 'until loop' which enables a set of instructions to be executed repeatedly until a given condition is met. Again, no such facility is available directly in Prolog, but a similar effect can be obtained in several ways.

Recursion
The first example below shows the use of recursion to read terms entered by the user from the keyboard and output them to the screen, until end is encountered.

go:-loop(start). /* start is a dummy value used to get
the looping process started.*/
loop(end).
loop(X):-X\=end,write('Type end to end'),read(Word),
write('Input was '),write(Word),nl,loop(Word).

?- go.
Type end to end: university.
Input was university
Type end to end: of.
Input was of
Type end to end: portsmouth.
Input was portsmouth
Type end to end: end
Input was end
Yes

Using the 'repeat' Predicate
Although it can often be used to great effect, recursion is not always the easiest
way to provide the types of looping required in Prolog programs. Another method
that is often used is based on the built-in predicate repeat.
The goal repeat does not
repeat anything; it merely succeeds whenever it is called. The great value of repeat
is that it also succeeds (as many times as necessary) on backtracking. The effect of
this, as for any other goal succeeding, is to change the order of evaluating goals
from 'right to left' (i.e. backtracking) back to 'left-to-right'.

Backtracking with Failure

As the name implies, the predicate fail always fails, whether on 'standard' evaluation left-to-right or on backtracking. Advantage can be taken of this, combined with Prolog's automatic backtracking, to search through the database to find all the clauses with a specified property.

Finding Multiple Solutions
Backtracking with failure can also be used to find all the ways of satisfying a goal. Suppose that a predicate findroute(Town1,Town2,Route) finds a route Route between two towns Town1 and Town2. The details of this predicate are irrelevant here. It may be assumed that Town1 and Town2 are atoms and that Route is a list.

Looping Exercise Page 97

(1) Define a predicate to output the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12.

pertama kita buat perintah seperti di bwah ini di notepad, kemudian disimpan dengan tipe .pl












kemudian kita mengetikkan perintah outsquare(6,12). Lalu tekan enter








(2) Define and test a predicate to read in a series of characters input by the user and
output all of those before the first new line or ? character.
pertama-tama buat rule seperti notepade berikut. Kemudian save dengan tipe .pl








Kemudian dari swi prolog consult rule tadi. Lalu kita masukkan perintah go.









(3) Using the person clauses given in Section 6.3.1, find the professions of all
those over 40.
pertama-tama buat rule seperti berikut, dan simpan dengan tipe .pl

lalu dari swi prolog kita consult file tadi. kemudian kita ketikkan perintah find.

Rabu, 25 November 2009

Input and Output in ProLog

TUTORIAL 4
INPUT AND OUTPUT

Outputting Terms
The write/1 predicate takes a single argument, which must be a valid Prolog term. Evaluating the predicate causes the term to be written to the current output stream, which by default is the user's screen. Evaluating a nl goal causes a new line to be output to the current output stream.

Examples
?- write(26),nl.
26
yes
?- write('a string of characters'),nl.
a string of characters
yes
?- write([a,b,c,d,[x,y,z]]),nl.
[a,b,c,d,[x,y,z]]
yes
?- write(mypred(a,b,c)),nl.
mypred(a,b,c)
yes
?- write('Example of use of nl'),nl,nl,write('end of example'),nl.
Example of use of nl
end of example
yes

Note that atoms that have to be quoted on input (e.g. 'Paul', 'hello world') are not quoted when output using write. If it is important to output the quotes, the writeq/1 predicate can be used. It is identical to write/1 except that atoms that need quotes for input are output between quotes (other atoms are not).

?- writeq('a string of characters'),nl.
'a string of characters'
yes
?-writeq(dog),nl.
dog
yes
?- writeq('dog'),nl.
dog
yes


Inputting Terms
The built-in predicate read/1 is provided to input terms. It takes a single argument, which must be a variable. Evaluating it causes the next term to be read from the current input stream, which by default is the user's keyboard. In the input stream, the term must be followed by a dot ('.') and at least onewhite space character, such as space or newline. The dot and white space characters are read in but are not considered part of the term. Note that for input from the keyboard (only) a prompt character such as a colon will usually be displayed to indicate that user input is required. It may be necessaryto press the 'return' key before Prolog will accept the input. Both of these do not apply to input from files.When a read goal is evaluated, the input term is unified with the argument variable. If the variable is unbound (which is usually the case) it is bound to the input value.
?- read(X).
: jim.
X = jim
?- read(X).
: 26.
X = 26
?- read(X).
: mypred(a,b,c).
X = mypred(a,b,c)
?- read(Z).
: [a,b,mypred(p,q,r),[z,y,x]].
Z = [a,b,mypred(p,q,r),[z,y,x]]
?- read(Y).
: 'a string of characters'.
Y = 'a string of characters'

If the argument variable is already bound (which for most users is far more likely to occur by mistake than by design), the goal succeeds if and only if the input term is identical to the previously bound value.

?- X=fred,read(X).
: jim.
no
?- X=fred,read(X).
: fred.
X = fred

Input and Output Using CharactersAlthough input and output of terms is straightforward, the use of quotes and full stops can be cumbersome and is not always suitable. For example, it would be tedious to define a predicate (using read) which would read a series of characters from the keyboard and count the number of vowels. A much better approach for problems of this kind is to input a character at a time. To do this it is first necessary to know about the ASCII value of a character.All printing characters and many non-printing characters (such as space and tab) have a corresponding ASCII (American Standard Code for Information Interchange) value, which is an integer from 0 to 255.

Outputting Characters
Characters are output using the built-in predicate put/1. The predicate takes a single argument, which must be a number from 0 to 255 or an expression that evaluates to an integer in that range.Evaluating a put goal causes a single character to be output to the current output stream. This is the character corresponding to the numerical value (ASCII value) of its argument, for example
?- put(97),nl.
a
yes
?- put(122),nl.
z
yes
?- put(64),nl.
@
yes

Inputting Characters
Two built-in predicates are provided to input a single character: get0/1 and get/1.The get0 predicate takes a single argument, which must be a variable. Evaluating aget0 goal causes a character to be read from the current input stream. The variableis then unified with the ASCII value of this character.Note that for input from the keyboard (only) a prompt character such as a colonwill usually be displayed to indicate that user input is required. It may be necessaryto press the 'return' key before Prolog will accept the input. Both of these alsoapply to the get predicate described below but do not apply to input from files.Assuming the argument variable is unbound (which will usually be the case), itis bound to the ASCII value of the input character.
?- get0(N).
: a
N = 97
?- get0(N).
: Z
N = 90
74 Logic Programming With Prolog
?- get0(M).
: )M = 41

If the argument variable is already bound, the goal succeeds if and only if it has a numerical value that is equal to the ASCII value of the input character.
?- get0(X).
: a
X = 97
?- M is 41,get0(M).
: )
M = 41
?- M=dog,get0(M).
: )
no
?- M=41.001,get0(M).
: )
no

The get predicate takes a single argument, which must be a variable. Evaluatinga get goal causes the next non-white-space character (i.e. character with an ASCIIvalue less than or equal to 32) to be read from the current input stream. Thevariable is then unified with the ASCII value of this character in the same way asfor get0.
?- get(X).
: Z
X = 90
?- get(M).
: Z
M = 90

Selasa, 24 November 2009

Expert System Design

Our simple design of expert system is:
"What is your suitable major?"

Background
We often find some student that feel confuse to decide what major they will take for their next study. Sometimes they fell hesitate to ask their teacher, or some other case just like leak of information, and difficult to get information about Universities. So because of that we want to help them

Explanation
This expert system is made for senior high school student to determine what kind of major that suitable for them. We make a question about their interest, favourite subject, their dream/idea. etc. And then, after they answer the multiple choice, we show the suitable major based o our characteristic that we have determine it before.

Benefit
The benefit is to help senior high school student in order not to take wrong major. We don't want they take wrong major that not suitable for their dream. They can explore their ability if they like the major itself.

Kamis, 12 November 2009