Daftar Blog Saya

Rabu, 23 Desember 2009

FP 8

Tugas Selesai....Meskipun telad..
silahkan download tugasnya di...


http://www.4shared.com/file/179751379/541b00e/_2__DiscreteMathematic_FP8_Rep.html

dan download file pl. nya n notepadnya di....

http://www.4shared.com/file/179752454/5e3c175a/matdis_fp_8_prolog.html

okok..???

Rabu, 16 Desember 2009

Expert System FP 8

Ada Perbaikan sedikit dalam expert sistem kami..dan berikut ini adalah perbaikannya..

Seiring dengan modernisasi manusia dituntut untuk selalu berkembang . Efisiensi waktu dalam melakukan pekerjaan sangat diperlukan . Untuk itu kami menciptakan suatu database yang memudahkan dalam pendataan pekerjaan terutama dalam mendata pasien rumah sakit . Anda tidak perlu mencari satu persatu untuk merekap data pasien tersebut , system ini akan sangat membantu anda.
berikut adalah langkah-langkah untuk mencari data nomor para pasien :
1. pertama kita membuat rule pada notepad dengan semua data para pasien .
2. pada rule tulis write info(Psn) .






3. kemudian save .pl
4. buka prolog kemudian consult file tersebut.
5. setelah itu ketik perintah info. jangan lupa untuk mengakhiri dengan tanda titik (.)
6. maka hasilnya adalah seperti berikut.









S.N.A ASSIGNMENT


Ini adalah hasil assignment menggunakan AGNA SOFTWARE.


Selasa, 15 Desember 2009

FP 2

How to list all possible combination (consisting two elements) of a set in PROLOG
The steps
1. Write the source in notepad and then save as “a.pl”, e.g.:






2. Open the SWI PROLOG and load the source “a.pl”
3.. To combine the two sets (hewan and tuan) write this command
“hewan(X),tuan(Y).”




4. To show the another result, press “;”. It will become like this


FP 6

(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.
Here is the answer :
first open your notepad and type this code

then save as loop coba4.pl ( I name it like that because before I done it, I did some experiments)
load it in prolog and here is the result

it is so simple.
(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.
this one is really the hardest of all, but thanks to some of  our friends we fnally figure it out
again, open your notepad and type this code :
save it. and load it in the prolog. here is the result

and finally number three
(3) Using the
person clauses given in Section 6.3.1, find the professions of all those over 40.
here is the source code :

and here is the result :

I’m sorry i didn’t included any explanations because i’m (the one who upload it) very tired already.  there is so many things to be done today. and tomorrow the hell is not over yet…. hahaha
and for my lecturer Mr. AM. I’m really sorry for being late to post this, it’s because there is so many things to do this day sir. I hope you could understand. thanks for reading this note.

INPUT AND OUTPUT

Chapter 6 : Loops
             This chapter discusses about how to obtain the effect of a loop in prolog. Because there is no such a built-in operator that can directly gives us the effect of loop. But there is such a way to obtain it. Here we go
Here is the explanation of th subchapters in the chapter 6, including the examples:
Subchapter 1 : Looping a Fixed Number of Times
            Explain how to obtain the effect of loop in prolog
example 1 :
The following program outputs integers from a specified value down to 1.
loop(0).loop(N):-N>0,write(‘The value is: ‘),write(N),nl, M is N-1,loop(M).
 The loop predicate is defined in terms of itself. The second clause can be thought of as: ‘to loop from N, first write the value of N, then subtract one to give M, then loop from M’. This process clearly needs to be terminated and this is achieved by the first clause: ‘when the argument is zero, do nothing (and hence stop)’. The first clause can be regarded as a terminating condition for the recursion. Here is the result:
?- loop(6).
The value is: 6
The value is: 5
The value is: 4
The value is: 3
The value is: 2
The value is: 1
yes
example 2 :
The next program outputs integers from First to Last inclusive.
/* output integers from First to Last inclusive */output_values(Last,Last):- write(Last),nl, write(‘end of example’),nl.
output_values(First,Last):-First=\=Last,write(First),
nl,N is First+1,output_values(N,Last).
Output :
?- output_values(5,12).
56789
10
11
12
end of example
example 3 :
Define a predicate to find the sum of the integers from 1 to N (say for N = 100).
/* sum the integers from 1 to N (the first argument)inclusive */ sumto(1,1).
sumto(N,S):-N>1,N1 is N-1,sumto(N1,S1),S is S1+N.
 Output :
?- sumto(100,N).
N = 5050
?- sumto(1,1).
yes
example 4 :
Define a predicate to output the squares of the first N integers, one per line.
/* output the first N squares, one per line */writesquares(1):-write(1),nl. writesquares(N):-N>1,N1 is N-1,writesquares(N1),
Nsq is N*N,write(Nsq),nl.
?- writesquares(6).
149
16
25
36
yes
subchapter 2 : Looping Until a Condition Is Satisfied
2.1. Recursive
example :
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 getthe looping process started.*/ loop(end).
loop(X):-X\=end,write(‘Type end to end’),read(Word),
write(‘Input was ‘),write(Word),nl,loop(Word).
 or
loop:-write(‘Type end to end’),read(Word),write(‘Input was ‘),write(Word),nl, (Word=end;loop).
The output is the same :
?- loop.
Type end to end: university.
Input was university
Type end to end: end.
Input was end
yes
2.2. Using the ‘repeat’ Predicate
repeat can be used to shorten the program
before:
get_answer(Ans):-write(‘Enter answer to question’),nl,get_answer2(Ans). get_answer2(Ans):-
write(‘answer yes or no’),
read(A),
((valid(A),Ans=A,write(‘Answer is ‘),
write(A),nl);get_answer2(Ans)).
valid(yes). valid(no).
 after
get_answer(Ans):-write(‘Enter answer to question’),nl, repeat,write(‘answer yes or no’),read(Ans),
valid(Ans),write(‘Answer is ‘),write(Ans),nl.
valid(yes). valid(no).
the output is the same.
Subchapter 3 : Backtracking with Failure
            How to use the advantage of the predicate fail/0
3.1. searching the prolog database
dog(fido).dog(fred). dog(jonathan).
alldogs:-dog(X),write(X),write(‘ is a dog’),nl,fail.
alldogs.
 after the alldogs predicate has succeded, the fail/0 predicate will cause it to execute the predicate alldogs until the result is no. then the alldogs/0 predicate will cause the last line is is Yes not No because it considered as succeeded. Here is the output :
?- alldogs.
fido is a dog
fred is a dog
jonathan is a dog
yes
3.2. Finding Multiple Solutions
Backtracking with failure can also be used to find all the ways of satisfying a goal.
Example :
find_all_routes(Town1,Town2):-findroute(Town1,Town2,Route), write(‘Possible route: ‘),write(Route),nl,fail.
find_all_routes(_,_).
  I’m sorry, but the output was not listed.

Input and Output (summary)

Input and Output

1. Outputting Terms
The main built-in predicate provided for outputting terms is write/1, 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. Another built-in predicate nl/0 which takes no arguments. Evaluating a nl goal causes a new line to be output to the current output stream. Example:
?- write(26),nl.
26
Yes

2. 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 one white space character, such as space or newline. The dot and white space characters are read in but are not considered part of the term. 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
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).
: fred.
X = fred

3. Input and Output Using Characters
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. Here is the table :

4. 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(64),nl.
@
Yes

5. 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 a get0 goal causes a character to be read from the current input stream. The variable is then unified with the ASCII value of this character.
Assuming the argument variable is unbound (which will usually be the case), it is bound to the ASCII value of the input character.
?- get0(N).
: a
N = 97
The get predicate takes a single argument, which must be a variable. Evaluating a get goal causes the next non-white-space character (i.e. character with an ASCII value less than or equal to 32) to be read from the current input stream. The variable is then unified with the ASCII value of this character in the same way as for get0.
?- get(X).
: Z
X = 90

6. Using Characters: Examples

The predicate readin is defined recursively. It causes a single character to be input and variable X to be bound to its (numerical) ASCII value. The action taken (the process(X) goal) depends on whether or not X has the value 42 signifying a * character. If it has, the evaluation of the goal stops. If not, the value of X is output, followed by a new line, followed by a further call to readin. This process goes on indefinitely until a * character is read. (In the example below, the ASCII values of characters P, r, o etc. are correctly shown to be 80, 114, 111 etc.)
readin:-get0(X),process(X).
process(42).
process(X):-X=\=42,write(X),nl,readin.


7. Input and Output Using Files
Prolog takes all input from the current input stream and writes all output to the current output stream. By default both of these are the stream named user, denoting the user’s terminal, i.e. keyboard for input and screen for output. The same facilities available for input and output from and to the user’s terminal either term by term or character by character are also available for input and output from and to files (e.g. files on a hard disk or a CD-ROM). The user may open and close input and output streams associated with any number of named files but there can only be one current input stream and one current output stream at any time. Note that no file can be open for both input and output at the same time (except user) and that the user input and output streams cannot be closed.

8. File Output: Changing the Current Output Stream
The current output stream can be changed using the tell/1 predicate. This takes a single argument, which  is an atom or variable representing a file name, e.g. tell(‘outfile.txt’). Evaluating a tell goal causes the named file to become the current output stream. If the file is not already open, a file with the specified name is first created (any existing file with the same name is deleted). The default current output stream is user, i.e. the  user’s terminal. This value can be restored either by using the told predicate or by tell(user). The built-in predicate told/0 takes no arguments. Evaluating a told goal causes the current output file to be closed and the current output stream to be reset to user, i.e. the user’s terminal. The built-in predicate telling/1 takes one argument, which must be a variable and will normally be unbound. Evaluating a telling goal causes the variable to be bound to the name of the current output stream.

9. File Input: Changing the Current Input Stream
current input stream can be changed using the see/1 predicate. This takes a single argument, which is an atom or variable representing a file name, e.g. see(‘myfile.txt’). Evaluating a see goal causes the named file to become the current input stream. If the file is not already open it is first opened (for read access only). If it is not  possible to open a file with the given name, an error will be generated. The default current input stream is user, i.e. the user’s terminal. This value can be restored either by using the seen predicate or by see(user). The built-in predicate seen/0 takes no arguments. Evaluating a see goal causes the current input file to be closed and the current input stream to be reset to user, i.e. the user’s terminal. The built-in predicate seeing/1 takes  one argument, which must be a variable and will normally be unbound. Evaluating a seeing goal causes the variable to be bound to the name of the current input stream.

Innovative Drinking Machine

Latar belakang:
Minuman adalah suatu yang mutlak di perlukan oleh seseorang dalam keadaan haus ataupun juga saat bersantai melepas penat dan bahkan menyembuhkan suatu penyakit. Minuman memberikan kesan tersendiri saat seeorang meminumnya, contohnya: saja coklat panas memberikan sensasi rileks pada seseorang yang meminumnya. Saat seseorang pergi ke toko banyak pilihan yang ditawarkan, tetapi belum tentu minuman tersebut memberikan sensasi yang sesuai yang dibutuhkan tubuh kita dan lingkungan kita. Oleh karena itu kami terpikirkan suatu aplikasi yang dapa membantu memberikan pilihan minuman yang memberikan sensasi yang sesuai dengan kebutuhan kita. Aplikasi ini juga dapat memberikan saran berupa obat kepada seseorang yang memberikan inputan kata yang mengindikasikan seseorang tersebut dalam keadaan sakit.
Penjelasan ide:
Mesin minuman ini mengusung aplikasi prolog di dalam pengoprasiannya. Didalam mesin ini dimasukkan bermacam macam jenis minuman dan beberapa obat. User menginputkan kondisi yang di terdapat dalam kotak dialog sehingga mesin dapat menyarankan minuman yang sesuai dengan kebutuhan. Contoh kotak dialog tersebut adalah: “Suhu lingkungan; pekerjaan yang baru saja dilakukan; dan kondisi badan”.
Manfaat:
-Mempermudah dalam memperoleh minuman yang dibutuhkan tubuh.
-Efisien dan terjangkau Karena mesin ini ada di tempat yang di butuhkan
-Menghemat waktu dalam memilih minuman.
Kesimpulan:
Jadi mesin minuman ini akan memudahkan seseorang mengembalikan kondisi tubuhnya pada keadaan yang optimal dan diinginka. Sehingga nesin ini dapat membaantu dalam mengoptimalkan hari-hari seseorang.

FP 3

soal1
soal2
how to solve it :
First, write the code number 1 given in the problem into notepad (or just copy paste) and then save it in extension “.pl”, the name of the file is up 2 u all. Ex: FP3.pl
database 1
And so does the number 2
database 2_2
(I save it with the name “FP3_2.pl”)
Open your prolog program and consult  the FP3.pl
consult
consult2
Or just click it twice on the file FP3.pl
Now, let’s discuss number 1 first. After the database has been loaded, things we should do next is to solve this problems : 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.
How do we solve it then? That’s easy, I’ll tell you then.
For the first problem, the way to find all the mammals is by typing this into your prolog program : “animal(mammal,X,_,_).” (I replace the third and the fourth with “_” because we won’t be needing that element) and press enter. This the first result:
1a_1
the first output will be tiger. To show the another result just press “;”  (“;” means “or” in prolog) and press it again until the output is “no”.
And the result will be like this :
1a
That’s it.
Now for the second problem. Type this into your prolog : “animal(mammal,X,carnivore,_).” (this time I replace the third element with carnivore because it will be used to find all the carnivores). And do the same steps as the first problem. The result will be like this
1b
The same goes to the third problem. Type this into your prolog “animal(mammal,X,_,stripes).” (I assume this time you will understand why I type it like that)  And follow the previous steps. The result will be like this
1c
For the fourth problem. It will be the same as the previous by typing this “animal(mammal,X,_,mane).”. But when you press “;” the result will be “no”. Why? Because there is only one animal that’s mammal and has a mane.
1d
And it’s done
Time to discuss number 2. To solve the number 2, edit number 2’s code and add this rule “couple(X,Y):-person(X,male),person(Y,female).”
database 2
save it. After that load it into your prolog program.
Type “couple(X,Y).” and press enter. The first result will be
X = bill
Y = carol
To show the another result keep pressing “;” until the output is “ no”. and this is the result :
2
Actually it is the same like combinatorial, just like the final project week 2. Ok, that’s it for now. See ya next time. And greatest thanks to Mr. AM………

SUMMARY FOR CHAPTER 5

Input dan Output

built-in predikat yang membaca dari dan menulis baik untuk pengguna
terminal (keyboard dan layar) atau file, kedua istilah tersebut dengan istilah dan characterby -
karakter dalam program Anda sendiri. nilai ASCII untuk memanipulasi string karakter. Menggunakan istilah lebih sederhana dan akan dijelaskan terlebih dahulu. Awalnya, maka akan diasumsikan bahwa
semua output ke layar pengguna dan semua input adalah dari pengguna keyboard. Masukan dan keluaran menggunakan file eksternal.

Syarat keluaran
predikat mengambil satu argumen, yang harus yang valid Prolog istilah. Mengevaluasi menyebabkan predikat istilah yang akan ditulis ke arus keluaran
sungai, yang secara default adalah layar pengguna. (Yang dimaksud dengan arus keluaran Dengan Logika Pemrograman Prolog
streaming)

Contoh
? - Menulis (26), nl.
26
ya
? - Menulis ( 'string karakter'), nl.
string karakter
ya
? - Menulis ([a, b, c, d, [x, y, z]]), nl.
[a, b, c, d, [x, y, z]]
ya
? - Tulis (mypred (a, b, c)), nl.
mypred (a, b, c)
ya
? - Write ( 'Contoh penggunaan nl'), nl, nl, write ( 'akhir contoh'), nl.
Contoh penggunaan nl
contoh akhir
ya


Syarat memasukkan
Built-in predikat membaca disediakan untuk memasukkan istilah. Dibutuhkan satu argumen, yang harus menjadi variabel.
Mengevaluasi itu menyebabkan istilah berikutnya untuk dibaca dari input arus sungai,
yang secara default adalah pengguna keyboard. (Yang dimaksud dengan arus input). Dalam input stream, istilah harus diikuti oleh sebuah titik ('.') dan setidaknya satu spasi, seperti spasi atau baris baru. Titik dan spasi karakter dibaca dalam tetapi tidak dianggap bagian dari istilah. Perhatikan bahwa untuk masukan dari keyboard (hanya) sebuah prompt karakter seperti titik dua biasanya akan ditampilkan untuk menunjukkan bahwa input pengguna diperlukan. Mungkin perlu untuk tekan tombol 'kembali' tombol sebelum Prolog akan menerima input. Kedua tidak berlaku untuk masukan dari file. Ketika sebuah tujuan membaca dievaluasi, istilah input disatukan dengan argumen variabel. Jika variabel tidak terikat (yang biasanya terjadi) itu adalah terikat pada masukan nilai.

Contoh
? - 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).
: 'String karakter'.
Y = 'string karakter'

Input dan Output Menggunakan Karakter
Meskipun input dan output dari syarat-syarat sangat mudah, penggunaan tanda kutip dan penuh berhenti dapat menjadi rumit dan tidak selalu sesuai. Sebagai contoh, akan membosankan untuk menentukan predikat (menggunakan baca) yang akan membaca serangkaian karakter dari keyboard dan menghitung jumlah huruf vokal. Sebuah pendekatan yang lebih baik untuk masalah semacam ini adalah untuk masukan sebuah karakter pada satu waktu. Untuk melakukan hal ini, pertama-tama perlu
untuk mengetahui tentang nilai ASCII karakter. Semua mencetak karakter dan banyak karakter non-cetak (seperti ruang dan tab) memiliki sesuai ASCII (American Standard Kode untuk Informasi Interchange) nilai, yang merupakan integer 0-255. Nilai ASCII karakter yang kurang dari atau sama dengan 32 yang dikenal sebagai putih ruang karakter.

Keluaran karakter
Karakter adalah output dengan menggunakan built-in predikat meletakkan predikat mengambil argumen tunggal, yang harus menjadi nomor 0-255 atau ekspresi yang
mengevaluasi ke integer dalam jangkauan. Mengevaluasi tujuan put menyebabkan satu karakter untuk menjadi output untuk saat ini output stream. Ini adalah karakter yang sesuai dengan nilai numerik (ASCII nilai) dari argumen.

misalnya
? - Meletakkan (97), nl.
sebuah
ya
? - Meletakkan (122), nl.
z
ya
? - Meletakkan (64), nl.
@
ya

Output ke sebuah File
Meskipun definisi di atas kirim menyatakan bahwa 'semua file yang sudah ada dengan yang sama Namanya dihapus ', ada kemungkinan lain, yang penting bagi beberapa aplikasi, yaitu bahwa file tersebut tidak dihapus dan setiap output ditempatkan setelah akhir isi yang ada file. Baik 'menimpa' dan 'append' pilihan
kemungkinan besar akan tersedia dalam pelaksanaan praktis Prolog tetapi mungkin melibatkan menggunakan predikat yang berbeda (misalnya terbuka) sebagai pengganti atau serta kirim.

Input: Mengubah Input Current Stream
Input stream yang aktif dapat diubah dengan menggunakan melihat / 1 predikat. Ini membutuhkan argumen tunggal, yang merupakan atom atau variabel yang mewakili nama file, misalnya lihat ( 'myfile.txt'). Mengevaluasi sebuah tujuan melihat menyebabkan file bernama input yang menjadi sungai. Jika file ini belum terbuka itu pertama kali dibuka (untuk akses baca saja). Jika tidak mungkin untuk membuka file dengan nama yang diberikan, kesalahan akan dihasilkan.