My Reference (app in prolog)

Program ini adalah program untuk merujukkan buku bagi mahasiswa dengan program studi masing-masing

pertama-tama, ketik program pada notepad sebagai berikut

Program ini dapat merujukkan mahasiswa kepada buku yang ingin diperoleh

outputnya adalah:

Untuk program yang kedua ini berfungsi untuk mengetahui profil dari buku

ketik program pada notepad sebagai berikut:

outputnya adalah:

Program yang ketiga ini sama seperti program pertama, namun inputan untuk syarat up date tahun tidak statis (1997) melainkan dinamis (terserah user). Berikut adalah program untuk inputan syarat up date tahun 2005

outputnya adalah

INPUT AND OUTPUT in Prolog (chapter 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.

langkah-langkah:

1. ketik pada notepad seperti berikut, lalu ubah dengan format.pl

2. Buka program tersebut (.pl)

3. lalu ketik “outsquare (2,8).” lalu tekan enter —>ini untuk menampilkan 2 kuadrat sampai 8 kuadrat.

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

Langkah-langkah :

1. ketik pada notepad sperti berikut, lalu ubah dengan format.pl

2. Buka program tersebut (.pl)

3. lalu ketik perintah “go.”

4. masukkan data yang diinginkan dalam format “_?” atau “_ _?_” atau terserah Anda (nb: “_”=data )

5. program ini akan menampilkan data sebelum tanda tanya (?)

(3) Using the person clauses given in Section 6.3.1, find the professions of all
those over 40.

Langkah-langkah :

1. ketik pada notepad sperti berikut, lalu ubah dengan format.pl

2. Buka program tersebut (.pl)

3. lalu ketik perintah “find.”

4. program ini hanya akan menampilkan data dengan NRP lebih dari 90

THAT’S ALL


Resume About Chapter 6

Loops

Kebanyakan bahasa pemrograman konvensional memiliki fasilitas perulangan yang memungkinkan
set instruksi yang akan dieksekusi berulang-ulang tetap baik beberapa kali atau sampai
kondisi tertentu terpenuhi. Meskipun, seperti yang ditunjukkan dalam pendahuluan ini
buku, Prolog tidak memiliki fasilitas perulangan, efek yang sama dapat diperoleh yang memungkinkan seorang
urutan tujuan untuk dievaluasi berulang kali. Hal ini dapat dilakukan dalam berbagai
cara, menggunakan backtracking, rekursi, built-in predikat, atau kombinasi dari semuanya.


  • Looping a Fixed Number of Times
  • Banyak bahasa pemrograman menyediakan ‘untuk loop’ yang memungkinkan satu set instruksi
    akan dieksekusi tetap beberapa kali. Tidak ada fasilitas tersebut tersedia dalam Prolog
    (langsung), tetapi efek yang sama dapat diperoleh dengan menggunakan rekursi, seperti ditunjukkan dalam
    contoh program di bawah ini.

    Contoh 1
    Keluaran program berikut bilangan bulat dari nilai tertentu ke 1.

    Predikat loop didefinisikan dalam istilah itu sendiri. Kalimat kedua dapat
    dianggap sebagai: ‘untuk loop dari N, pertama menulis nilai N, kemudian kurangi satu untuk memberikan
    M, kemudian loop dari M ‘. Proses ini jelas harus dihentikan dan ini
    dicapai oleh klausa pertama: ‘ketika argumen adalah nol, melakukan apa-apa (dan karenanya
    berhenti) ‘. Klausa pertama dapat dianggap sebagai suatu kondisi untuk menghentikan rekursi.

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

    perhatikan penggunaan dua gol M adalah N-1, loop (M) dalam kalimat kedua untuk
    loop predikat. Alternatif yang jelas loop (N-1) tidak akan bekerja. Prolog hanya
    mengevaluasi pernyataan seperti N-1 ketika mengevaluasi tujuan dengan atau functor adalah salah satu dari
    operator relasional, seperti dijelaskan dalam Bab 4. N-1 jika digunakan sebagai argumen
    suatu predikat itu diartikan istilah dengan infiks operator – (yaitu tanda minus) dan
    argumen N dan 1. Ini sangat tidak mungkin apa yang dimaksudkan!

    Contoh 2
    Program berikutnya keluaran bilangan bulat dari awal ke akhir inklusif.

    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

    Contoh 3
    Tentukan sebuah predikat untuk menemukan jumlah bilangan bulat dari 1 sampai N (katakanlah untuk N = 100).
    Adalah wajar untuk memikirkan secara prosedural ini, yaitu mulai dengan 1, kemudian tambahkan 2, kemudian tambahkan 3,
    kemudian tambahkan 4, …, kemudian tambahkan 100. Namun proses ini lebih mudah program jika reexpressed
    declaratively dalam hal itu sendiri.
    Jumlah dari 100 bilangan bulat yang pertama adalah jumlah dari 99 bilangan bulat yang pertama, ditambah 100.
    Jumlah dari 99 bilangan bulat yang pertama adalah jumlah dari 98 bilangan bulat yang pertama, ditambah 99.
    Jumlah dari 98 bilangan bulat yang pertama adalah jumlah dari 97 bilangan bulat yang pertama, ditambah 98.

    Jumlah dari 3 bilangan bulat pertama adalah jumlah dari 2 bilangan bulat pertama, ditambah 3.
    Jumlah dari 2 bilangan bulat pertama adalah jumlah dari 1 bilangan bulat pertama, ditambah 2.
    Jumlah 1 bilangan bulat pertama adalah satu.
    Ada dua kasus yang berbeda untuk mempertimbangkan: kasus umum: ‘jumlah pertama
    N bilangan bulat adalah jumlah dari N-1 pertama bilangan bulat, ditambah N ‘dan kasus mengakhiri:’ yang
    jumlah 1 bilangan bulat pertama adalah 1 ‘. Ini mengarah langsung ke definisi rekursif:
    output :

    ?- sumto(100,N).
    N = 5050
    ?- sumto(1,1).
    yes

    Perhatikan bahwa menggunakan N1 variabel tambahan untuk menyimpan nilai N-1 adalah
    penting. Menulis sumto (N-1, S1), dll bukannya tidak akan bekerja dengan benar. N-1 adalah
    istilah, bukan nilai numerik.

    Looping Until a Condition Is Satisfied

    Banyak bahasa memiliki sebuah ‘sampai loop’ yang memungkinkan sebuah set instruksi yang akan
    dieksekusi berulang kali sampai kondisi tertentu terpenuhi. Sekali lagi, tidak ada fasilitas seperti
    tersedia secara langsung di Prolog, tetapi efek yang sama dapat diperoleh dengan beberapa cara.

  • Rekursi
  • Contoh pertama di bawah ini menunjukkan penggunaan istilah rekursi untuk membaca dimasukkan oleh
    pengguna dari keyboard dan output mereka ke layar, sampai akhir dijumpai?- 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

    Menggunakan pemisahan operator; / 2 yang disebutkan dalam Pasal di atas 4,4

    The ‘disjunctive goal’ (Word=end;loop) succeeds if variable Word is bound to

    the atom end. If not, the system attempts to satisfy the goal loop recursively.

    ?- loop.

    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

    Program rekursif ini berulang kali mendorong pengguna untuk memasukkan istilah sampai baik
    ya atau tidak dimasukkan.

    ?- get_answer(Myanswer).
    Enter answer to question
    answer yes or no: maybe.
    answer yes or no: possibly.
    answer yes or no: yes.
    Answer is yes
    Myanswer = yes

  • Using the ‘repeat’ Predicate
  • Meskipun sering dapat digunakan untuk efek yang besar, rekursi tidak selalu yang paling mudah
    cara untuk menyediakan jenis perulangan yang diperlukan dalam program Prolog. Metode lain
    yang sering digunakan adalah berdasarkan pada built-in predikat ulangi.
    Nama predikat ini benar-benar sebuah ironi. Tujuan tidak mengulangi
    mengulangi apa pun; itu hanya berhasil setiap kali disebut. Nilai besar mengulang
    adalah bahwa hal itu juga berhasil (sebanyak yang diperlukan) pada kemunduran. Efek
    ini, seperti untuk tujuan lainnya berhasil, adalah untuk mengubah urutan mengevaluasi tujuan
    dari “kanan ke kiri ‘(yaitu backtracking) kembali ke’ kiri-ke-kanan ‘. Ini dapat digunakan untuk
    menciptakan efek perulangan, seperti ditunjukkan pada contoh di bawah ini.
    Program ini berulang kali mendorong pengguna untuk memasukkan istilah sampai entah ya atau tidak
    dimasukkan. Ini adalah alternatif dari program rekursif ditampilkan di bagian akhir
    bagian sebelumnya. Dalam hal ini masih diperdebatkan apakah menggunakan mengulang adalah
    perbaikan menggunakan rekursi, tetapi contoh adalah termasuk untuk tujuan
    ilustrasi.

    Program ini menunjukkan bagaimana untuk mengimplementasikan suatu struktur menu yang loop kembali
    berulang kali untuk meminta lebih banyak masukan. Memasuki pergi pada prompt menyebabkan Prolog untuk output
    menu dari mana pengguna dapat memilih satu kegiatan pada satu waktu sampai opsi d adalah
    dipilih. Perhatikan bahwa semua input adalah istilah-istilah dan harus diikuti oleh sebuah titik
    karakter.

    output:

    ?- go.
    This shows how a repeated menu works
    MENU
    a. Activity A
    b. Activity B
    c. Activity C
    d. End
    : b.
    Activity B chosen
    MENU
    a. Activity A
    b. Activity B
    c. Activity C
    d. End
    : xxx.
    Please try again!
    MENU
    a. Activity A
    b. Activity B
    c. Activity C
    d. End
    : d.
    Goodbye!
    yes

    Backtracking with Failure

    Seperti namanya, predikat gagal selalu gagal, apakah pada ‘standar’
    evaluasi kiri-ke-kanan atau pada kemunduran.
    Keuntungan dapat diambil dari ini,
    dikombinasikan dengan otomatis Prolog backtracking, untuk pencarian melalui database untuk
    menemukan semua klausa dengan properti tertentu.

    • Searching the Prolog Database


    Contoh program ini  dirancang untuk mencari database yang berisi klausa
    mewakili nama, umur, tempat tinggal dan pekerjaan sejumlah
    orang-orang.
    Jika database berisi lima klausa


    Nama semua guru dapat ditemukan dengan menggunakan allteachers predicate.

    The effect of using backtracking with failure in this case is to find all the
    teachers in the database.


    ?- allteachers.
    martin williams
    jane wilson
    yes

    • Finding Multiple Solutions

    Backtracking dengan kegagalan juga dapat digunakan untuk mencari semua cara untuk memuaskan tujuan.
    Misalkan sebuah predikat findroute (Town1, Town2, Route) menemukan sebuah rute Route
    antara dua kota Town1 dan Town2.
    Rincian predikat ini tidak relevan
    di sini. Ini dapat diasumsikan bahwa Town1 dan Town2 adalah atom dan bahwa rute ini adalah daftar.
    Backtracking dengan kegagalan kemudian dapat digunakan untuk mencari semua kemungkinan rute antara
    Town1 dan Town2 dan menulis masing-masing satu di baris terpisah, sebagai berikut:

    INPUT and OUTPUT in PROLOG

    Soal 1

    1. ketik soal di notepad, lalu simpan dengan format.pl

    Keterangan kode-kode dalam notepad:

    • readline:-get0(P),process(P). get: berguna untuk mengonvert karakter menjadi kode ASCII process: berguna untuk memroses argumen yang dinyatakan.
    • Kemudian ketik “case(P,Q):-P>64,P<91 is P+32” dan “case(P,Q):-Q is P+0.” Ini adalah kode-kode untuk menentukan kode bilangan ke huruf kecil.
    • “process(P):-P=\=13,case(P,Q),put(Q),nl,readline.” Bagian ini untuk melakukan proses.
    • Dan kode “nl” adalah perintah untuk ganti baris (berjajar secara vertikal).

    2. consult dalam program prolog.

    3. ketik readline, kemudian tekan tombol enter

    4. ketik kata yang anda inginkan, contoh dalam gambar : “csonmatdis”

    Soal 2

    1. Ketik seperti contoh dibawah ini kemudian save dengan nama “teks.txt”.

    2. Convert kedalam format .pl

    3. Consult pada prolog.

    4. Maka otomatis terbentuk “output.txt” :

    Soal 3

    1. ketik pada notepad lalu ubah dengan format.pl

    2. lalu consult pada program prolog.

    soal 4

    1. ketik dalam notepad.

    2. Kemudian ketik seperti ini namun dalam format (.pl).

    3. Lalu jalankan program tersebut dalam prolog.

    4. Dan output akan tersimpan otomatis dalam format ‘.txt’

    Soal 5

    1. ketik dalam notepad.

    3. Lalu ketik sperti dibawah ini dalam format .pl

    4. Lalu consult dalam program prolog

    THAT’S ALL!!!^^

    resume

    SUMMARY FOR CHAPTER 5

    Introduction

    Prolog has facilities to enable input and output either of terms or of characters. Using terms is simpler and will be described first. Initially, it will be assumed that all output is to the user’s screen and all input is from the user’s keyboard. Input and output using external files, e.g. on a hard disk or CD-ROM. Note that, like many other built-in predicates, those for input and output described in this chapter are all unresatisfiable, i.e. they always fail when backtracking.

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

    The built-in predicate nl/0 has also been used many times previously in this book. It takes no arguments. Evaluating a nl goal causes a new line to be output to the current output stream.

    b. Inputting Terms

    The built-in predicate read/1 is provided to input terms. It takes a single argument, which must be a variable.

    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.

    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.

    c. 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. It would be tedious to define a predicate (using read). 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.

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

    e. 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 lready bound, the goal succeeds if and only if it has a numerical value that is equal to the ASCII value of the input character.

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

    g. 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 streamcan 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.

    h. File Input: Changing the Current Input Stream

    The current input stream can be changed using the see/1 predicate. This takes asingle 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 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.

    * h.1 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.

    * h.2 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.

     

     

     

    My Reference (REVISI EXPERT SYSTEM)

    Abstract
    Saat ini masih banyak sekali mahasiswa Jurusan Sistem Informasi (khususnya mahasiswa baru) yang stres jika akan menghadapi praktikum alpro dan mengerjakan TP/LP. Umumnya mereka, masih bingung dengan bagaimana cara menyumbangkan atau menulis logikanya kedalam program Java. Hal ini mungkin dikarenakan para mahasiswa baru masih bertransisi dari dunia SMA ke dunia perkuliahan berbasis IT, dan para mahasiswa kurang mengerti konsep dasar bahasa Java itu sendiri. Untuk mengatasi hal ini, kami mempunyai inovasi yang spektakuler.

    Description
    Kami mempunyai inovasi untuk membuat suatu aplikasi yang dapat membantu mahasiswa dalam memecahkan masalah “coding-nya”. Aplikasi ini kami sebut dengan JSCC (J Source Code Converter). Aplikasi ini bekerja dengan cara meng-import inputan yang ditulis dengan notepad (format *.txt). Setelah itu, aplikasi ini mencocokkan inputan user dengan “fact-fact” yang telah ditulis owner dalam database aplikasi ini dan meng-export hasilnya dalam java file ke dalam drive yang telah ditentukan. Dengan demikian aplikasi ini dapat memudahkan para mahasiswa untuk menemukan logika berpikir dalam bahasa Java. Dan JSCC 1.0 ini merupakan aplikasi awal kami, yang mungkin dikembangkan terus sehingga aplikasi ini dapat meng-convert sampai tingkat Java applet,GUI dan sebagainya. :)

    OPERATOR AND ARITHMETIC in Prolog

    • Penyelesaian No. 1

    1. siapkan notepad yang diubah menjadi format.pl

    2. setelah format berubah lalu consult program tersebut.

    3. tulis kategori apa yang akan dimunculkan sesuai keinginan.

    4. Hingga semua kategori dijabarkan,sehingga tidak adalagi maka akan muncul “no”

    • Penyelesaian no 2

    1. Deklarasikan pada notepad yang dirubah format.pl yang akan dijalankan pada program prolog.

    no2

    2. Lalu consult pada program prolog sesuai dengan perintah soal.

    Summary of Chapter 4 (Operator and Arithmatic)

    • Operator

    notasi yang digunakan untuk predikat adalah salah satu dari standar
    pengguna diikuti oleh sejumlah argumen dalam kurung, misalnya suka (john, mary).
    Sebagai alternatif, apapun predikat yang ditetapkan pengguna dengan dua argumen (binary predikat) dapat dikonversi ke operator infiks. Hal ini memungkinkan functor
    (predikat nama) yang akan ditulis di antara dua argumen tanpa tanda kurung, misalnya
    john suka mary. Setiap predikat yang ditetapkan pengguna dengan satu argumen (a unary predikat)dapat diubah menjadi prefiks operator. Hal ini memungkinkan untuk functor ditulis sebelum argumen tanpa tanda kurung. Notasi operator juga dapat digunakan dengan mudah dibaca aturan untuk bantuan. Setiap predikat yang ditetapkan pengguna dengan satu atau dua argumen dapat dikonversi ke operator dengan memasukkan tujuan menggunakan op predikat pada sistem prom.

    Ada bentuk lain untuk menulis suatu predikat selain bentuk standar yang sudah dipelajari pada bab sebelumnya. Untuk binary predicate  yaitu predikat dengan dua argumen dapat diubah menjadi bentuk infix operator.

    contoh :

    main (budi,main)
    bentuk standar tersebut dapat diubah menjadi infix operator
    budi main bola
    Kemudian untuk bentuk unary predikat  yaitu predikat dengan satu argumen dapat diubah menjadi bentuk prefix operator atau postfix operator.

    Contoh :
    mbois(budi)
    bentuk tersebut diubah menjadi prefix operator
    mbois budi
    atau bisa juga diubah menjadi postfix operator
    budi mbois

    • Arithmetic

    Pada aplikasi prolog juga terdapat fasilitas penghitungan aritmatika . Pembahasan tentang aritmatik di dalam prolog dibagi menjadi beberapa bagian yaitu:

    1. Operator Aritmatika

    Operator yang digunakan untuk penghitungan aritmatik variabel-variabel di dalam pemrograman prolog. Berikut adalah contoh penggunaan dari masing-masing operator.
    X+Y (penjumlahan dari X ditambah Y)
    X-Y (selisih dari X dikurangi Y)
    X*Y (hasil perkalian dari X dan Y)
    X/Y (hasil pembagian dari X dibagi oleh Y)
    X//Y integer hasil bagi dari  X dan Y (hasilnya adalah dibagi ke integer terdekat antara hasil dan nol)
    X^Y (nilai dari X pangkat Y)
    -X (nilai negatif dari X)

     

    2.  Fungsi Aritmatika

    Operator / fungsi yang digunakan untuk melakukan penghitungan aritmatik variabel-variabel dalam prolog.

    contoh penggunaan dari masing-masing fungsi :
    abs(X) (nilai absolut dari X)
    sin(X) (nilai sinus dari X untuk X dalam derajat)
    cos(X) (nilai cosinus dari X untuk X dalam derajat)
    max(X,Y) (menentukan mana yang lebih besar antara X dan Y)
    sqrt(X) (nilai dari X akar pangkat dua)

     

    3.  Pengutamaan Operator Dalam Ekspresi Aritmatika
    Prolog menggunakan algoritma aljabar biasa dalam pengopersian aritmatika.

    Contoh :  p+q*r-s.

    Di dalam ajabar q dan r dikalikan lebih dahulu lalu ditambah dengan p lalu dikurangi dengan s. Di dalam prolog juga demikian, untuk pengecualian, kita tinggal menggunakan kurung.

    4.  Relational Operators
    Operator seperti =, !=, >,>=, <, =<, dapat digunakan di Prolog. Biasanya digunakan untuk membandingkan dua variabel.

    contoh :

    x != 0 —->dibaca : nilai x tidak sama dengan 0

    x >= 0 —>dibaca : nlai x lebih dari sama dengan 0

     

    • Operator Pembanding

    Dibawah ini merupakan daftar dari equality operators dalam prolog beserta fungsi dari masing-masing operator.
    o Arithmetic Expression Equality =:=
    o Arithmetic Expression Inequality =\=
    o Terms Identical ==
    o Terms Not Identical \==
    o Terms Identical With Unification =
    o Non-Unification Between Two Terms \=

     

    • Operator Logika

    1.  Operator Not
    Operator not dapat ditempatkan sebelum predikat untuk memberikan negasi. Predikat yang dinegasikan bernilai benar jika predikat yang asli salah dan bernilai salah jika predikat yang asli benar.

    berikut contohnya :

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

    2.  Operator Disjungsi
    Operator disjungsi (;) digunakan sebagai operator ‘atau’.

    berikut contohnya :

    ?- 6<3;7 is 5+2.
    yes

    ?- 6*6=:=36;10=8+3.
    yes

     

     

     

     

    EXPERT SYSTEM

    Expert system and Rule-based Expert System

    An expert system is software that attempts to provide an answer to a problem, or clarify uncertainties where normally one or more human experts would need to be consulted. Expert systems are most common in a specific problem domain, and is a traditional application and/or subfield of artificial intelligence. A wide variety of methods can be used to simulate the performance of the expert however common to most or all are 1) the creation of a so-called “knowledgebase” which uses some knowledge representation formalism to capture the Subject Matter Expert’s (SME) knowledge and 2) a process of gathering that knowledge from the SME and codifying it according to the formalism, which is called knowledge engineering. Expert systems may or may not have learning components but a third common element is that once the system is developed it is proven by being placed in the same real world problem solving situation as the human SME, typically as an aid to human workers or a supplement to some information system.
    Expert systems were introduced by Edward Feigenbaum, the first truly successful form of AI software. The topic of expert systems has many points of contact with general systems theory, operations research, business process reengineering and various topics in applied mathematics and management science.
    Expert systems topics
    Chaining
    Two methods of reasoning when using inference rules are backward chaining and forward chaining.
    Forward chaining starts with the data available and uses the inference rules to conclude more data until a desired goal is reached. An inference engine using forward chaining searches the inference rules until it finds one in which the if clause is known to be true. It then concludes the then clause and adds this information to its data. It would continue to do this until a goal is reached. Because the data available determines which inference rules are used, this method is also called data driven.
    Backward chaining starts with a list of goals and works backwards to see if there is data which will allow it to conclude any of these goals. An inference engine using backward chaining would search the inference rules until it finds one which has a then clause that matches a desired goal. If the if clause of that inference rule is not known to be true, then it is added to the list of goals. For example, suppose a rule base contains
    1. If Fritz is green then Fritz is a frog.
    2. If Fritz is a frog then Fritz hops.
    Suppose a goal is to conclude that Fritz hops. The rule base would be searched and rule (2) would be selected because its conclusion (the then clause) matches the goal. It is not known that Fritz is a frog, so this “if” statement is added to the goal list. The rule base is again searched and this time rule (1) is selected because its then clause matches the new as certainty factors. A human, when reasoning, does not always conclude things with 100% confidence: he might venture, “If Fritz is green, then he is probably a frog” (after all, he might be a chameleon). This type of reasoning can be imitated by using numeric values called confidences. For example, if it is known that Fritz is green, it might be concluded with 0.85 confidence that he is a frog; or, if it is known that he is a frog, it might be concluded with 0.95 confidence that he hops. These numbers are probabilities in a Bayesian sense, in that they quantify uncertainty.
    Expert system architecture
    The following general points about expert systems and their architecture have been illustrated.
    1. The sequence of steps taken to reach a conclusion is dynamically synthesized with each new case. It is not explicitly programmed when the system is built.
    2. Expert systems can process multiple values for any problem parameter. This permits more than one line of reasoning to be pursued and the results of incomplete (not fully determined) reasoning to be presented.
    3. Problem solving is accomplished by applying specific knowledge rather than specific technique. This is a key idea in expert systems technology. It reflects the belief that human experts do not process their knowledge differently from others, but they do possess different knowledge. With this philosophy, when one finds that their expert system does not produce the desired results, work begins to expand the knowledge base, not to re-program the procedures.
    There are various expert systems in which a rulebase and an inference engine cooperate to simulate the reasoning process that a human expert pursues in analyzing a problem and arriving at a conclusion. In these systems, in order to simulate the human reasoning process, a vast amount of knowledge needed to be stored in the knowledge base. Generally, the knowledge base of such an expert system consisted of a relatively large number of “if then” type of statements that were interrelated in a manner that, in theory at least, resembled the sequence of mental steps that were involved in the human reasoning process.
    Because of the need for large storage capacities and related programs to store the rulebase, most expert systems have, in the past, been run only on large information handling systems. Recently, the storage capacity of personal computers has increased to a point where it is becoming possible to consider running some types of simple expert systems on personal computers.
    In some applications of expert systems, the nature of the application and the amount of stored information necessary to simulate the human reasoning process for that application is just too vast to store in the active memory of a computer. In other applications of expert systems, the nature of the application is such that not all of the information is always needed in the reasoning process. An example of this latter type application would be the use of an expert system to diagnose a data processing system comprising many separate components, some of which are optional. When that type of expert system employs a single integrated rulebase to diagnose the minimum system configuration of the data processing system, much of the rulebase is not required since many of the components which are optional units of the system will not be present in the system. Nevertheless, earlier expert systems require the entire rulebase to be stored since all the rules were, in effect, chained or linked together by the structure of the rulebase.
    When the rulebase is segmented, preferably into contextual segments or units, it is then possible to eliminate portions of the Rulebase containing data or knowledge that is not needed in a particular application. The segmenting of the rulebase also allows the expert system to be run with systems or on systems having much smaller memory capacities than was possible with earlier arrangements since each segment of the rulebase can be paged into and out of the system as needed. The segmenting of the rulebase into contextual segments requires that the expert system manage various intersegment relationships as segments are paged into and out of memory during execution of the program. Since the system permits a rulebase segment to be called and executed at any time during the processing of the first rulebase, provision must be made to store the data that has been accumulated up to that point so that at some time later in the process, when the system returns to the first segment, it can proceed from the last point or rule node that was processed. Also, provision must be made so that data that has been collected by the system up to that point can be passed to the second segment of the rulebase after it has been paged into the system and data collected during the processing of the second segment can be passed to the first segment when the system returns to complete processing that segment.
    The user interface and the procedure interface are two important functions in the information collection process.
    End user
    The end-user usually sees an expert system through an interactive dialog, an example of which follows:
    Q. Do you know which restaurant you want to go to?
    A. No
    Q. Is there any kind of food you would particularly like?
    A. No
    Q. Do you like spicy food?
    A. No
    Q. Do you usually drink wine with meals?
    A. Yes
    Q. When you drink wine, is it French wine?
    A. Yes
    As can be seen from this dialog, the system is leading the user through a set of questions, the purpose of which is to determine a suitable set of restaurants to recommend. This dialog begins with the system asking if the user already knows the restaurant choice (a common feature of expert systems) and immediately illustrates a characteristic of expert systems; users may choose not to respond to any question. In expert systems, dialogs are not pre-planned. There is no fixed control structure. Dialogs are synthesized from the current information and the contents of the knowledge base. Because of this, not being able to supply the answer to a particular question does not stop the consultation.
    Explanation system
    Another major distinction between expert systems and traditional systems is illustrated by the following answer given by the system when the user answers a question with another question, “Why”, as occurred in the above example. The answer is:
    A. I am trying to determine the type of restaurant to suggest. So far Chinese is not a likely choice. It is possible that French is a likely choice. I know that if the diner is a wine drinker, and the preferred wine is French, then there is strong evidence that the restaurant choice should include French.
    It is very difficult to implement a general explanation system (answering questions like “Why” and “How”) in a traditional computer program. An expert system can generate an explanation by retracing the steps of its reasoning. The response of the expert system to the question WHY is an exposure of the underlying knowledge structure. It is a rule; a set of antecedent conditions which, if true, allow the assertion of a consequent. The rule references values, and tests them against various constraints or asserts constraints onto them. This, in fact, is a significant part of the knowledge structure. There are values, which may be associated with some organizing entity. For example, the individual diner is an entity with various attributes (values) including whether they drink wine and the kind of wine. There are also rules, which associate the currently known values of some attributes with assertions that can be made about other attributes. It is the orderly processing of these rules that dictates the dialog itself.
    Expert systems versus problem-solving systems
    The principal distinction between expert systems and traditional problem solving programs is the way in which the problem related expertise is coded. In traditional applications, problem expertise is encoded in both program and data structures. In the expert system approach all of the problem related expertise is encoded in data structures only; no problem-specific information is encoded in the program structure. This organization has several benefits.
    An example may help contrast the traditional problem solving program with the expert system approach. The example is the problem of tax advice. In the traditional approach data structures describe the taxpayer and tax tables, and a program in which there are statements representing an expert tax consultant’s knowledge, such as statements which relate information about the taxpayer to tax table choices. It is this representation of the tax expert’s knowledge that is difficult for the tax expert to understand or modify.
    In the expert system approach, the information about taxpayers and tax computations is again found in data structures, but now the knowledge describing the relationships between them is encoded in data structures as well. The programs of an expert system are independent of the problem domain (taxes) and serve to process the data structures without regard to the nature of the problem area they describe. For example, there are programs to acquire the described data values through user interaction, programs to represent and process special organizations of description, and programs to process the declarations that represent semantic relationships within the problem domain and an algorithm to control the processing sequence and focus.
    The general architecture of an expert system involves two principal components: a problem dependent set of data declarations called the knowledge base or rule base, and a problem independent (although highly data structure dependent) program which is called the inference engine.
    Individuals involved with expert systems
    There are generally three individuals having an interaction with expert systems. Primary among these is the end-user; the individual who uses the system for its problem solving assistance. In the building and maintenance of the system there are two other roles: the problem domain expert who builds and supplies the knowledge base providing the domain expertise, and a knowledge engineer who assists the experts in determining the representation of their knowledge, enters this knowledge into an explanation module and who defines the inference technique required to obtain useful problem solving activity. Usually, the knowledge engineer will represent the problem solving activity in the form of rules which is referred to as a rule-based expert system. When these rules are created from the domain expertise, the knowledge base stores the rules of the expert system.
    Inference rule
    An understanding of the “inference rule” concept is important to understand expert systems. An inference rule is a statement that has two parts, an if clause and a then clause. This rule is what gives expert systems the ability to find solutions to diagnostic and prescriptive problems. An example of an inference rule is:
    If the restaurant choice includes French, and the occasion is romantic,
    Then the restaurant choice is definitely Paul Bocuse.
    An expert system’s rulebase is made up of many such inference rules. They are entered as separate rules and it is the inference engine that uses them together to draw conclusions. Because each rule is a unit, rules may be deleted or added without affecting other rules (though it should affect which conclusions are reached). One advantage of inference rules over traditional programming is that inference rules use reasoning which more closely resemble human reasoning.
    Thus, when a conclusion is drawn, it is possible to understand how this conclusion was reached. Furthermore, because the expert system uses knowledge in a form similar to the expert, it may be easier to retrieve this information from the expert.
    Procedure node interface
    The function of the procedure node interface is to receive information from the procedures coordinator and create the appropriate procedure call. The ability to call a procedure and receive information from that procedure can be viewed as simply a generalization of input from the external world. While in some earlier expert systems external information has been obtained, that information was obtained only in a predetermined manner so only certain information could actually be acquired. This expert system, disclosed in the cross-referenced application, through the knowledge base, is permitted to invoke any procedure allowed on its host system. This makes the expert system useful in a much wider class of knowledge domains than if it had no external access or only limited external access.
    In the area of machine diagnostics using expert systems, particularly self-diagnostic applications, it is not possible to conclude the current state of “health” of a machine without some information. The best source of information is the machine itself, for it contains much detailed information that could not reasonably be provided by the operator.
    The knowledge that is represented in the system appears in the rulebase. In the rulebase described in the cross-referenced applications, there are basically four different types of objects, with associated information present.
    1. Classes—these are questions asked to the user.
    2. Parameters—a parameter is a place holder for a character string which may be a variable that can be inserted into a class question at the point in the question where the parameter is positioned.
    3. Procedures—these are definitions of calls to external procedures.
    4. Rule Nodes—The inferencing in the system is done by a tree structure which indicates the rules or logic which mimics human reasoning. The nodes of these trees are called rule nodes. There are several different types of rule nodes.
    The rulebase comprises a forest of many trees. The top node of the tree is called the goal node, in that it contains the conclusion. Each tree in the forest has a different goal node. The leaves of the tree are also referred to as rule nodes, or one of the types of rule nodes. A leaf may be an evidence node, an external node, or a reference node.
    An evidence node functions to obtain information from the operator by asking a specific question. In responding to a question presented by an evidence node, the operator is generally instructed to answer “yes” or “no” represented by numeric values 1 and 0 or provide a value of between 0 and 1, represented by a “maybe.”
    Questions which require a response from the operator other than yes or no or a value between 0 and 1 are handled in a different manner.
    A leaf that is an external node indicates that data will be used which was obtained from a procedure call.
    A reference node functions to refer to another tree or subtree.
    A tree may also contain intermediate or minor nodes between the goal node and the leaf node. An intermediate node can represent logical operations like And or Or.
    The inference logic has two functions. It selects a tree to trace and then it traces that tree. Once a tree has been selected, that tree is traced, depth-first, left to right.
    The word “tracing” refers to the action the system takes as it traverses the tree, asking classes (questions), calling procedures, and calculating confidences as it proceeds.
    As explained in the cross-referenced applications, the selection of a tree depends on the ordering of the trees. The original ordering of the trees is the order in which they appear in the rulebase. This order can be changed, however, by assigning an evidence node an attribute “initial” which is described in detail in these applications. The first action taken is to obtain values for all evidence nodes which have been assigned an “initial” attribute. Using only the answers to these initial evidences, the rules are ordered so that the most likely to succeed is evaluated first. The trees can be further re-ordered since they are constantly being updated as a selected tree is being traced.
    It has been found that the type of information that is solicited by the system from the user by means of questions or classes should be tailored to the level of knowledge of the user. In many applications, the group of prospective uses is nicely defined and the knowledge level can be estimated so that the questions can be presented at a level which corresponds generally to the average user. However, in other applications, knowledge of the specific domain of the expert system might vary considerably among the group of prospective users.
    One application where this is particularly true involves the use of an expert system, operating in a self-diagnostic mode on a personal computer to assist the operator of the personal computer to diagnose the cause of a fault or error in either the hardware or software. In general, asking the operator for information is the most straightforward way for the expert system to gather information assuming, of course, that the information is or should be within the operator’s understanding. For example, in diagnosing a personal computer, the expert system must know the major functional components of the system. It could ask the operator, for instance, if the display is a monochrome or color display. The operator should, in all probability, be able to provide the correct answer 100% of the time. The expert system could, on the other hand, cause a test unit to be run to determine the type of display. The accuracy of the data collected by either approach in this instance probably would not be that different so the knowledge engineer could employ either approach without affecting the accuracy of the diagnosis. However, in many instances, because of the nature of the information being solicited, it is better to obtain the information from the system rather than asking the operator, because the accuracy of the data supplied by the operator is so low that the system could not effectively process it to a meaningful conclusion.
    In many situations the information is already in the system, in a form of which permits the correct answer to a question to be obtained through a process of inductive or deductive reasoning. The data previously collected by the system could be answers provided by the user to less complex questions that were asked for a different reason or results returned from test units that were previously run.
    User interface
    The function of the user interface is to present questions and information to the user and supply the user’s responses to the inference engine.
    Any values entered by the user must be received and interpreted by the user interface. Some responses are restricted to a set of possible legal answers, others are not. The user interface checks all responses to insure that they are of the correct data type. Any responses that are restricted to a legal set of answers are compared against these legal answers. Whenever the user enters an illegal answer, the user interface informs the user that his answer was invalid and prompts him to correct it.
    Application of expert systems
    Expert systems are designed and created to facilitate tasks in the fields of accounting, medicine, process control, financial service, production, human resources etc. Indeed, the foundation of a successful expert system depends on a series of technical procedures and development that may be designed by certain technicians and related experts.
    A good example of application of expert systems in banking area is expert systems for mortgages. Loan departments are interested in expert systems for mortgages because of the growing cost of labour which makes the handling and acceptance of relatively small loans less profitable. They also see in the application of expert systems a possibility for standardised, efficient handling of mortgage loan, and appreciate that for the acceptance of mortgages there are hard and fast rules which do not always exist with other types of loans.
    While expert systems have distinguished themselves in AI research in finding practical application, their application has been limited. Expert systems are notoriously narrow in their domain of knowledge—as an amusing example, a researcher used the “skin disease” expert system to diagnose his rustbucket car as likely to have developed measles—and the systems were thus prone to making errors that humans would easily spot. Additionally, once some of the mystique had worn off, most programmers realized that simple expert systems were essentially just slightly more elaborate versions of the decision logic they had already been using. Therefore, some of the techniques of expert systems can now be found in most complex programs without any fuss about them.
    An example, and a good demonstration of the limitations of, an expert system used by many people is the Microsoft Windows operating system troubleshooting software located in the “help” section in the taskbar menu. Obtaining expert/technical operating system support is often difficult for individuals not closely involved with the development of the operating system. Microsoft has designed their expert system to provide solutions, advice, and suggestions to common errors encountered throughout using the operating systems.
    Another 1970s and 1980s application of expert systems — which we today would simply call AI — was in computer games. For example, the computer baseball games Earl Weaver Baseball and Tony La Russa Baseball each had highly detailed simulations of the game strategies of those two baseball managers. When a human played the game against the computer, the computer queried the Earl Weaver or Tony La Russa Expert System for a decision on what strategy to follow. Even those choices where some randomness was part of the natural system (such as when to throw a surprise pitch-out to try to trick a runner trying to steal a base) were decided based on probabilities supplied by Weaver or La Russa. Today we would simply say that “the game’s AI provided the opposing manager’s strategy.”
    Advantages and disadvantages
    Advantages:
    • Provides consistent answers for repetitive decisions, processes and tasks
    • Holds and maintains significant levels of information
    • Encourages organizations to clarify the logic of their decision-making
    • Always asks a question, that a human might forget to ask
    • Can work continuously (no human needs)
    • Can be used by the user more frequently
    • A multi-user expert system can serve more users at a time
    Disadvantages:
    • Lacks common sense needed in some decision making
    • Cannot respond creatively like a human expert would in unusual circumstances
    • Domain experts not always able to explain their logic and reasoning
    • Errors may occur in the knowledge base, and lead to wrong decisions
    • Cannot adapt to changing environments, unless knowledge base is changed
    Types of problems solved by expert systems
    Expert systems are most valuable to organizations that have a high-level of know-how experience and expertise that cannot be easily transferred to other members. They are designed to carry the intelligence and information found in the intellect of experts and provide this knowledge to other members of the organization for problem-solving purposes.
    Typically, the problems to be solved are of the sort that would normally be tackled by a medical or other professional. Real experts in the problem domain (which will typically be very narrow, for instance “diagnosing skin conditions in human teenagers”) are asked to provide “rules of thumb” on how they evaluate the problems, either explicitly with the aid of experienced systems developers, or sometimes implicitly, by getting such experts to evaluate test cases and using computer programs to examine the test data and (in a strictly limited manner) derive rules from that. Generally, expert systems are used for problems for which there is no single “correct” solution which can be encoded in a conventional algorithm — one would not write an expert system to find shortest paths through graphs, or sort data, as there are simply easier ways to do these tasks.
    Simple systems use simple true/false logic to evaluate data. More sophisticated systems are capable of performing at least some evaluation, taking into account real-world uncertainties, using such methods as fuzzy logic. Such sophistication is difficult to develop and still highly imperfect.
    Expert Systems Shells or Inference Engine
    A shell is a complete development environment for building and maintaining knowledge-based applications. It provides a step-by-step methodology, and ideally a user-friendly interface such as a graphical interface, for a knowledge engineer that allows the domain experts themselves to be directly involved in structuring and encoding the knowledge. Many commercial shells are available, one example being eGanges which aims to remove the need for a knowledge engineer.

    Link yang terkait dengan pembahasan ini :
    expert system
    rule-based expert system

    prolog

    langkah-langkah mengerjakan :
    1. salin soal yang ada pada buku logic-program (e-learning) hal 27 pada notepad
    2. save dalam format .pl untuk merubah dalam program prolog
    3. kerjakan di dalam prolog tersebut sesuai soal
    4. soal :D evise and test goals to 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.

    keterangan :
    - pada jawaban no 1 merupakan penyelesaian soal A
    - pada jawaban no 2 merupakan penyelesaian soal B
    - pada jawaban no 3 terdapat kesalahan ketikan pada statement untuk soal C
    - pada jawaban no 4 terdapat kesalahan pada penegtikan “stripes” menjadi “streps”
    - pada jawaban no 5 merupakan penyelesaian soal C
    - pada jawaban no 6 merupakan penyelesaian soal D

    « Older entries
    Follow

    Get every new post delivered to your Inbox.