Senin, 21 Desember 2009

Simple Expert System

now, we make a simple expert system to make easier our mother to find the recipe to make some food.

like usually, the first time, you must open your prolog and creat new .pl.

and then make the program in your notepade.











after make the rule, lets consult in your prolog:

and let's start the prolog program, write find(name of food) .


that is our prolog program can help our mother to find more easier recipes...
^ ^

Selasa, 15 Desember 2009

Simple Expert System

We make simple expert system to make someone more easier to find something what he want. Example, if someone want to buy a motorcycle, he/she can find what type of motorcycle he/she want with us this prolog program.
For more distinct you can see like this below:

 
 and if you want to fine a perusahaan san the tahun production of the motorcycle you can write " find(yamaha,2006)." and the result is:



that is our Simple Expert System,,,can help someone to find something more easier.

Senin, 07 Desember 2009

Input and Output in Prolog

Exercise 6

1.
write like this in your notepad with name output value.pl

and than consule in your prolog then write 'output_values(6,12).' and enter.



2.
write like this in your notepad with name or.pl

open your prolog and consult with or.pl, then write go.  in your prolog and th eresult like this below:

 3.
 write like this in your notepad with name person.pl







and then consult on prolog, and write 'see.'. And the result is

done.

Input and Output in Prolog

Summery for Chapter 6

6.1 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.
 
6.2 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.

     6.2.1 Recursion
              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. 
 
     6.2.2 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'. This can be used to create a looping effect.
 
6.3 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.

     6.3.1 Searching the Prolog Database
              Supposing the database contains clauses

     6.3.2 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.

Rabu, 25 November 2009

Exercise 5 (Output and Input)

Hii,,,
Let's learn about Output and input

1. Open your notepad and write like this below and consult at prolog

Than write makelower on Prolog, and than enter. Write a sentence and the sentence is up to you.
and then enter.



2.  Open your notepad and write like this below and consult at prolog
 
 than write this below in new wordpad and write copyterms(‘Infile.txt’,'Outfile.txt’). 

in prolog.






and the result is



3.  Open your notepad and write like this below and consult at prolog

and then make a file name testa.txt, and write ('testa.txt'). on prolog.


and the result is



 4.  Open your notepad and write like this below and consult at prolog
 

 and then make a new file name In1.txt


make a file name  in2
 

  And then write combine(‘in1.txt’,'in2.txt’,'out.txt’). on prolog, and the result is

 5.  Open your notepad and write like this below and consult at prolog

 make a new file,









 make a new file again,

and then write compare(‘1.txt’,'2.txt’). in prolog, and the result is

Input and Output


1.Outputting Term

The main built-in predicate provided for outputting terms is 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 user's screen.
Evaluating a nl goal causes a new line to be output to the current output stream.
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.


2.Inputting Term

The built-in predicate read/1 is provided to input term.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 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.
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.


3.Input and Output Using Characters

Although input and output of terms is straightforward, the use of quotes and full stops can be cumbersome and is not always suitable.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. Characters whose ASCII value is less than or equal to 32 are known as white space characters.


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.



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.
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. The get predicate takes a single argument, which must be a variable.



6.Using Characters: Examples
The first example shows how to read in a series of characters from the keyboard finishing with * and to output their corresponding ASCII values one per line (for all characters excluding *).
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.) Assuming the argument variable is unbound (which will usually be the case), it is bound to the ASCII value of the input character.


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).
Note that the file corresponding to the previous current output stream remains open when a new current output stream is selected. Only the current output stream can be closed (using the told predicate described below).
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

The 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.
Note that the file corresponding to the previous current input stream remains open when a new current input stream is selected. Only the current input stream can be closed (using the seen predicate described below).
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.

10.Reading from Files: End of File

If the end of file is encountered when evaluating the goal read(X), variable X will be bound to the atom end_of_file.
If the end of file is encountered while evaluating the goal get(X) or get0(X), variable X will be bound to a 'special' numerical value. As ASCII values must be in the range 0 to 255 inclusive, this will typically be -1, but may vary from one implementation of Prolog to another.

11. Reading from Files: End of Record

Depending on the version of Prolog used, there may be an incompatibility for character input between reading the end of a record (i.e. the character(s) that signify the end of a line) from the user's terminal and from a file.
Typically the end of a line of input at the user's terminal will be indicated by the character with ASCII value 13. The end of a record in a file will generally be indicated by two ASCII values: 13 followed by 10.
The following program shows how to read in a series of characters from the keyboard and print them out, one per line.



Senin, 23 November 2009

Symple expert system untuk pengganti kebutuhan bahan pangan pokok

RUMPUT LAUT SEBAGAI ALTERNATIF PENGGANTI  KEBUTUHAN BAHAN PANGAN POKOK

LATAR BELAKANG

   Pada awalnya pertumbuhan penduduk relative lambat tetapi dengan bertambahnya individu yang bereproduksi, pertumbuhan menjadi meningkat. Saat ini penduduk Indonesia mencapai 231 juta jiwa yang penyebarannya tidak merata  disetiap pulau. Pertumbuhan penduduk tidak diimbangi dengan perkembangan sumber daya alam, terutama sumber daya alam yang menjadi kebutuhan pokok manusia seperti kebutuhan pangan.

   Berkurangnya produksi kebutuhan pangan disebabkan oleh menipisnya lahan untuk melakukan produksi, masalah ini timbul dari pergeseran lahan dari lahan produksi seperti daerah persawahan menjadi lahan pemukiman, apartemen, pembangunan jalan dan pembangunan infrastruktur pemerintah. Dengan pertambahan jumlah penduduk, tentunya semakin  banyak lahan-lahan produksi yang akan beralih fungsi menjadi pemukiman, hal ini mengakibatkan produksi pangan semakin menurun. Untuk mengatasi permasalahan produksi pangan yang semakin menurun akibat menyempitnya lahan produksi perlu diciptakan produksi pangan yang lahannya tidak berkurang akibat bertambahnya jumlah penduduk. Ekosistem yang mampu bertahan dari dampak pertambahan penduduk adalah ekosistem laut. Laut banyak mengandung sumber daya yang bermanfaat dimana sumber daya itu masih banyak yang belum dioptimalkan pemanfaatannya, seperti rumput laut. Dilihat dari komposisi rumput laut itu sendiri, rumput laut bisa dimanfaatkan sebagai alternative kebutuhan pangan. Keberadaan rumput laut tersebar di daerah pesisir pantai dan Indonesia merupakan negara penghasil rumput laut terbesar, terutama di daerah pulau-pulau kecil yang pemenuhan pangannya ditunjang daerah lain seperti pulau-pulau kecil yang ada di Propinsi Bali yaitu Pulau Nusa Penida yang kebutuhan pangan penduduknya yang harus didatangkan dari Pulau Bali, sedangkan pulau tersebut terkenal dengan penghasilan rumput lautnya. Untuk itulah perlu dikembangkan pemanfaatan rumput laut sebagai alternative bahan pangan.

MANFAAT

   Manfaat yang bisa diperoleh dari ide ini yaitu kemudahan bagi masyarakat dalam mencari pengganti bahan-bahan pangan pokok yang semakin menurun produksinya terutama bagi petani-petani rumput laut yang kebutuhan pangannya sebagian besar didatangkan dari luar pulau khususnya untuk masyarakat di pulau kecil dengan penghasilan rumput lautnya yang tinggi.

PENJELASAN

   Berdasarkan data-data kandungan rumput laut, didapatkan kandungan-kandungan yang bernilai tinggi dan sulit didapatkan pada bahan lainnya, kandungan yang paling tinggi di dalam rumput laut itu sendiri adalah kandungan karbohidratnya yang mencapai angka 39-51%, ini merupakan kandungan yang cukup tinggi, di dalam 100 gram beras putih mentah terkandung sekitar 80 gram karbohidrat, namun dalam 100 gram nasi putih hanya terkandung sekitar 28 gram karbohidrat karena beratnya bertambah besar dengan air sewaktu proses memasak.

   Berbeda dengan beras, rumput laut cenderung mengalami penurunan  yang sedikit, karena pada rumput laut yang kehilangan air karena mengalami proses pengeringan mendapatkan air kembali saat proses pemasakan, sehingga beratnyay cenderung tetap bahkan mengalami pengurangan berat, tetapi keadaan karbohidratnya tetap. Sedangkan saat ini, pemenuhan kebutuhan pangan seperti beras ini mulai mengalami masalah, bahkan negara kita pernah melakukan impor beras karena produksi kita mulai menurun. Namun, di sisi lain, negara kita terkenal sebagai penghatsil rumput laut terbesar, akan tetapi masyarakat jarang memangfaatkan rumput laut tersebut, hal ini karena masyarakat kita kurang terbiasa mengkonsumsi rumput laut dan lebih memntingkan untuk mengekspornya.