Downloading code and report of Rice Crop Expert System

klik this link to download the source code
expert system in notepad or expertSystem in SWI-Prolog

klik this link to download the report of Rice-crop Doctor Expert System
document
PDF

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Graph

hello my friends..
this is baceman graph in discrete mathematic A class..

analysis of distribution and emission degree :


  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Rice-Crop Doctor Expert System by Using SWI-Prolog

hello hello all of my friends..
now I will show my Expert System using SWI-prolog..
so chek this out....
1. Firstly open your notepad and write like this as below



2. And then save it with file name's is expertSystem.pl
3. Then open your SWI-prolog and consult expertSystem.pl file
4. Then write solusi(Penyakit,_,_) to list what is the diseases of paddy. Don't forget!!, you must write start the character using capital.
5. so, this is the result.


6. Isn't final.., now we will checkanad finf the symptoms and solution of paddy's diseases
7. write solusi(Nama,Gejala,Solusi). then enter
8. if you only want to find the solution and symptoms
for example :write solusi(wereng_cokelat,Gejala,Solusi). don't forgrt starting with capital character.
9. then the result is


  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Summary of Loops

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, 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
Note the use of the two goals M is N-1,loop(M) in the second clause for the
loop predicate. The obvious alternative of loop(N-1) will not work. Prolog only
evaluates expressions such as N-1 when evaluating goals with functor is or one of
the relational operators, as described in Chapter 4. If N-1 is used as an argument of
a predicate it is taken to mean the term with infix operator - (i.e. a minus sign) and
arguments N and 1. This is most unlikely to be what is intended!

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).
56789
10
11
12
end of example
yes

Example 3
Define a predicate to find the sum of the integers from 1 to N (say for N = 100).
It is natural to think of this procedurally, i.e. start with 1, then add 2, then add 3,
then add 4, … , then add 100. However the process is much easier to program if reexpressed
declaratively in terms of itself.
The sum of the first 100 integers is the sum of the first 99 integers, plus 100.
The sum of the first 99 integers is the sum of the first 98 integers, plus 99.
The sum of the first 98 integers is the sum of the first 97 integers, plus 98.
…………………………………………………………………………….
The sum of the first 3 integers is the sum of the first 2 integers, plus 3.
The sum of the first 2 integers is the sum of the first 1 integers, plus 2.
The sum of the first 1 integers is one.
There are two distinct cases to consider: the general case: 'the sum of the first
N integers is the sum of the first N-1 integers, plus N' and the terminating case: 'the
sum of the first 1 integers is 1'. This leads directly to the recursive definition:
/* 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.
?- sumto(100,N).
N = 5050
?- sumto(1,1).
yes
Note that using the additional variable N1 for holding the value of N-1 is
essential. Writing sumto(N-1,S1) etc. instead would not work correctly. N-1 is a
term, not a numerical value.

Example 4
Define a predicate to output the squares of the first N integers, one per line.
This can most easily be programmed if first recast in a recursive form, as
follows.
To output the squares of the first N integers, output the squares of the first N-1 and
then output N2
To output the squares of the first N-1 integers, output the squares of the first N-2
and then output (N-1)2
To output the squares of the first N-2 integers, output the squares of the first N-3
and then output (N-2)2
……………………………………………………………………………………….
To output the squares of the first 3 integers, output the squares of the first 2 and
then output 32
To output the squares of the first 2 integers, output the squares of the first 1 and
then output 22
To output the squares of the first 1 integers, output the number 1
Here the general case is 'to output the squares of the first N integers, output the
squares of the first N-1 and then output N2' and the terminating case is 'to output
the squares of the first 1 integers, output the number 1'. This leads to the following
two-clause program.
/* 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

Example 5
The following program reads the first 6 terms from a specified file and writes them
to the current output stream. It uses a 'counting down' method, in a similar way to
Example 1.
read_six(Infile):-seeing(S),see(Infile),
process_terms(6),seen,see(S).
process_terms(0).
process_terms(N):-N>0,read(X),write(X),nl,N1 is N-1,
process_terms(N1).

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

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

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 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
The next program is designed to search a database containing clauses
representing the name, age, place of residence and occupation of a number of
people.
If the database contains these five clauses
person(john,smith,45,london,doctor).
person(martin,williams,33,birmingham,teacher).
person(henry,smith,26,manchester,plumber).
person(jane,wilson,62,london,teacher).
person(mary,smith,29,glasgow,surveyor).
The names of all the teachers can be found using the allteachers predicate.
allteachers:-person(Forename,Surname,_,_,teacher),
write(Forename),write(' '),write(Surname),nl,
fail.
allteachers.
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
If the second clause of allteachers were omitted, both teachers would still be
found but the evaluation of allteachers would end with failure. This is of little or
no importance when a goal is entered at the system prompt, but if allteachers were
used as a goal in the body of a rule it would obviously be desirable to ensure that it
always succeeded.
It should be noted that it is not always necessary to use 'backtracking with
failure' to search the database. For example, the predicate somepeople/0 defined
below will find all the people in the database given previously, down to williams,
using only standard backtracking.
somepeople:-person(Forename,Surname,_,_,_),
write(Forename),write(' '),write(Surname),nl,
Surname=williams.
somepeople.
The goal Surname=williams succeeds if the variable Surname is bound to
williams. If not, it fails. The effect is to search the database down to and including
the person clause with second argument williams.
?- somepeople.
john smith
martin williams
yes

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.
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(_,_).
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Exercise 6 Loops (number 3)

hello hello...
hei my friends, nice to meet you again..
in this section we will continuing about loops..
check this out..
1. Firstly open your notepad and write like this as below
2. And then save it with file name's is no 3.pl
3. Then open your SWI-prolog and consult no 3.pl file
4. After that write the query like this " find. "
5. Then write some characters and they will check it
6. Finally the result is
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Exercise 6 loops (number 2)

hei hei my friends..
this section is continued with last section..
so no worries..
and let's see..
1. Firstly open your notepad and write like this as below
2. And then save it with file name's is no 2.pl
3. Then open your SWI-prolog and consult no 2.pl file
4. After that write the query like this " go. "
5. Then write some characters and they will check it
6. Finally the result is
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Exercise 6 Loops (number 1)

hello my friend, nice see you again..
now in this section we will learn about loops..
do you know that??
chek it out...
1. Firstly make a new file in notepad and write like this as below.
2. After that save it with name no 1.pl.
3. Then open your SWI-prolog, and consult file of no 1.pl
4. And compiled it, after compiled is successful write the query outsquare(6,12).
5. Finally the result is
4.
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Summary Input and Output

built-in predicates that read from and write well for users
terminal (keyboard and screen) or a file, the second term by term and characterby --
characters in your own programs. ASCII value for manipulating character strings. Prolog has a facility to enable both input and output of the term or character. Using simple terms and will be explained first. Initially, it will be assumed that
all the output to the screen the user and all user input is the keyboard. Inputs and outputs use external files.

1.Outputting Terms

predicate takes one argument, which must be a valid Prolog term. Evaluate the causes predicate terms to be written to the output current river, which by default is the user's screen. (The meaning of output current Logic Programming With Prolog streaming)
Examples
?- write(26),nl.
26
yes
?- write('a string of characters'),nl.
a string of characters
yes
?- write([a,b,c,d,[x,y,z]]),nl.
[a,b,c,d,[x,y,z]]
yes
?- write(mypred(a,b,c)),nl.
mypred(a,b,c)
yes
?- write('Example of use of nl'),nl,nl,write('end of example'),nl.
Example of use of nl
end of example
yes

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. (The meaning of current input stream willbe explained in Sections 5.7 and 5.9. At present it can simply be taken to mean theuser's keyboard.)
In the input stream, the term must be followed by a dot ('.') and at least onewhite space character, such as space or newline. The dot and white space
characters are read in but are not considered part of the term.
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.

4.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. For example, it would be tedious to define a predicate (using read) which would read a series of characters from the keyboard and count the number of vowels. A much better approach for problems of this kind is to input a character at a time. To do this it is first necessary to know about the ASCII value of a character.
All printing characters and many non-printing characters (such as space and tab) have a corresponding ASCII (American Standard Code for Information Interchange) value, which is an integer from 0 to 255.
The table below gives the numerical ASCII values corresponding to the main printable characters and some others.

5. 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 (ASCIIvalue) of its argument.

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

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

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

9. 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 outputstream.
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.

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

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

12.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.
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS