Selasa, 22 Desember 2009

FP REPORT

Akhirnya tugas matdis kelompok kami telah selesai...... Terima kasih pada P.Mukhlason telah membing kita semua sehingga dapat menyelasaikan tugas ini... Download file kami di bawah ini.

DOWNLOAD

Selasa, 15 Desember 2009

EXPERT SYSTEM DESIGN

Saat ini perkembangan teknologi sangat pesat sekali . Kita tidak update sebentar sudah ketinggalan banyak mengenai teknologi. Sehingga apabila kita mengenal teknologi mungkin suatu pekerjaan dapat terselesaikan dengan mudah . misalnya saja satpam yang menjaga hunian rumah , kebanyakan satpam penjaga tidak tahu tentang penduduk yang tinggal di perumahan tersebut baik itu nama maupun blok rumah. Dan kebanyakan satpam mencatat di buku nama-nama penduduk dan alamatnya . Maka dari itu kami menciptakan suatu database yang memudahkan dalam pendataan penduduk . Satpam tidak lagi menggunakan buku untuk mencarinya, karena pasti dengan buku sangat lamban.
Langkahnya yaitu :

1. pertama kita bikin rulenya terlebih dahulu dalam notepad tentang penduduk hunian, kemudian jika kita ingin
    mencari data entah nama, blok, nama istri dengan menuliskan variable write.





  
2. Kemudian file save dalam bentuk .pl
3. Setelah itu buka file yang tadi di save dalam bentuk prolog.
4. Kemudian dalam prolog ketikan find untuk mencarinya.




 5. Di sini saya menampilkan nama penghuni. Dan nantinya akan keluar data lengkapnya.


Semoga ini bermanfaat.

Selasa, 08 Desember 2009

INPUT AND OUTPUT in Prolog

Jawaban Soal Practical Exercise 6

Soal No.1

1. Pertama-tama kita buat rulenya terlebih dahulu dalam notepad. Menggunakan rekursi untuk mencari nilai  kuadrat bilangan N1. Dan sampai tidak melebihi N2.



2. Kemudian save dalam format .pl
3. Kemudian buka file yang sudah dalam bentuk format prolog tadi.
4. Tuliskan dalam prolog outsquare(_,_). yang merupakan predikat kita dalam membuat rule tadi.




Soal No.2

1. Pertma-tama kita buat rulenya dulu dalam notepad. Dengan menggunakan predikat go,repeat,geto dan getrest.




2. Kemudian save dalam bentuk .pl
3. Buka file dalam bentuk prolog tadi. Ketik go. Seperti pada gambar di bawah ini.



Soal No. 3

1. Pertama-tama kita buat rulenya dalam notepad.Dengan menggunakan find sebagai predikatnya. Di sini menggunakan metode bactracking with failure. Untuk mencari profesi orang yang berumur lebih dari 40 tahun.
Bisa juga mencari profesi orang yang kurang dari 40 tahun.



2.  Simpan dalam bentuk .pl
3. Kemudian buka file prolog yang anda simpan tadi. Kemudian ketikkan find pada prolog.


Senin, 07 Desember 2009

SUMMARY FOR CHAPTER 6

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, as shown in the
example programs below.

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.

?- 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).

Here  output_values  has two arguments, which can be read as 'output the
integers from First to Last inclusive'. The loop terminates when both arguments are
the same.

?- output_values(5,12).
5
6
7
8
9
10
11
12
end of example
yes

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 name of this predicate is really a misnomer. 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, as shown in the examples below.
This program repeatedly prompts the user to enter a term until either yes or no
is entered. It is an alternative to the recursive program shown at the end of the
previous section. In this case it is debatable whether using  repeat is an
improvement on using recursion, but the example is included for purposes of
illustration.

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 first five goals in the body of get_answer will always succeed. Evaluating
the fifth goal: read(Ans) will prompt the user to enter a term. If the term input is
anything but yes or no, say unsure, the following goal valid(Ans) will fail. Prolog
will then backtrack over read(Ans) and write('answer yes or no'), both of which
are unresatisfiable, i.e. will always fail on backtracking.
Backtracking will then reach the predicate  repeat and succeed, causing
evaluation to proceed forward (left-to-right) again, with write('answer yes or no')
and read(Ans) both succeeding, followed by a further evaluation of valid(Ans).
Depending on the value of Ans, i.e. the user's input, the valid(Ans) goal will
either fail, in which case Prolog will backtrack as far as repeat, as before, or it will
succeed in which case the final three goals write('Answer is'), write(Ans) and nl
will all succeed. The overall effect is that the two goals write('answer yes or no')
and read(Ans) are called repeatedly until the terminating condition valid(Ans) is
satisfied, effectively creating a loop between repeat and valid(Ans).

?- get_answer(X).
Enter answer to question
answer yes or no: unsure.
answer yes or no: possibly.
answer yes or no: no.
answer is no
X = no

Goals to the left of  repeat in the body of a clause will never be reached on
backtracking.

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.

 Searching the Prolog Database

Supposing the database contains clauses such as
dog(fido).
dog(fred).
dog(jonathan).

Each dog clause can be processed in turn using the alldogs predicate defined
below.

alldogs:-dog(X),write(X),write(' is a dog'),nl,fail.
alldogs.

Calling alldogs will cause dog(X) to be matched with the dog clauses in the
database. Initially X will be bound to  fido and 'fido is a dog' will be output. The
final goal in the first clause of the alldogs predicate will then cause evaluation to
fail. Prolog will then backtrack over nl and the two write goals (all of which are
unresatisfiable) until it reaches dog(X). This goal will succeed for a second  time
causing X to be bound to fred.
This process will continue until  fido, fred and  jonathan have all been output,
when evaluation will again fail. This time the call to dog(X) will also fail as there
are no further  dog clauses in the database. This will cause the first clause for
alldogs to fail and Prolog to examine the second clause of  alldogs. This will
succeed and evaluation will stop.
The effect is to loop through the database finding all possible values of X that
satisfy the goal dog(X).

?- alldogs.
fido is a dog
fred is a dog
jonathan is a dog
yes

Note the importance of the second clause of the alldogs predicate. It is there to
ensure that, after the database has been searched, the goal succeeds. With only the
first line, any call to alldogs will eventually fail.

alldogs:-dog(X),write(X),write(' is a dog'),nl,fail.

?- alldogs.
fido is a dog
fred is a dog
jonathan is a dog
no

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.
Backtracking with failure can then be used to find all possible routes between
Town1 and Town2 and write out each one on a separate line, as follows:

find_all_routes(Town1,Town2):-
   findroute(Town1,Town2,Route),
   write('Possible route: '),write(Route),nl,fail.
find_all_routes(_,_).

Rabu, 25 November 2009

INPUT DAN OUTPUT dalam Prolog (5)






























1. Buat variabel dalam notepad dan file yang untuk di compare.
2. Kemudian simpan dalam drive C atau yang lainnya.
3. Consult di prolog. Ketik perintahnya '?-compare('C:/nomor5.txt','C:/nomor51.txt','C:/output5.txt').'

4. Kemudian muncul beberapa macam statement dan muncul statement lagi menyatakan YES.




INPUT DAN OUTPUT dalam Prolog (4)






1. Pertama kita membuat di dalam notepad variabel in1 dulu,
2. Kemudian simpan dalam bentuk txt.
3. Ketik lagi perintah dalam notepad untuk in2.




4. Kemudian simpan dalam bentuk txt.
5. Buatlah variabel dalam prolog yang menggunakan combine sebagai predikat untuk mengabungkan kedua file tersebut. Kemudian simpan dalam bentuk .pl

 
6. Consult di prolog. Ketik perintah yaitu?- combine('in1.txt','in2.txt','out.txt').
7. Lalu akan muncul statement yang menyatakan YES






8. Kemudian dengan sendirinya output akan tersimpan dalam drive dimana anda simpan tadi dalam bentuk
    notepad.


INPUT DAN OUTPUT dalam Prolog (3)















1. Buatlah variabelnya dulu dalam notepad.
2. Kemudian simpan dalam drive C atau yang lainnya dalam bentuk .pl
3. Bikin lagi inputanya dalam notepad simpan dengan nama input3 atau yang lain dalam bentuk txt.




4. Consult di program prolog variabel yang pertama tadi. Ketik perintahnya seperti pada gambar.



5. Akan muncul hasil  berbagai macam angka dan statement dengan dinyatakan  YES.