Selasa, 24 November 2009

INPUT AND OUTPUT (READFILE)

1. Create testa.txt


2. Create in your prolog:




3. The Result Is :

INPUT AND OUTPUT (COPYTERMS)

1. create copyterms.txt






2. Save and now open your prolog, create new rule :




3. Outputfile






Jumat, 13 November 2009

OPERATOR AND ARITHMETIC


Operators and Arithmetics

Operators
Up to now, Prolog user usually use the notation for predicates by a number of arguments in parentheses.
Ex : likes(john,mary)
There is another alternative :


- Two arguments (a binary predicates) be converted to an infix operator ? the functor be written between two arguments with no parentheses
Ex : john likes mary


- One argument (a unary predicate) be converted to :
1. Prefix operator ? the functor be written before the argument with no parentheses
Ex : isa_dog fred
2. Postfix operator ? the functor be written after the argument
Ex : fred isa_dog


Both of predicate (one or two arguments) can be converted to an operator by entering a goal using the op predicate at the system prompt.

Ex : ?-op(150,xfy,likes).
This predicate takes three arguments :
1. 150 (operator precedence) : an integer from 0 upwards
So we can change it with another integer.
2. Xfy : the predicate is binary and is to be converted to an infix operator.
This argument should normally be one of the following three atoms:
1. Xfy
2. Fy : the predicate is unary and is to be converted to an prefix operator
3. Xf : the predicate is unary and is to be converted to a postfix operator
3. Likes : the name of the predicate that is to be converted to an operator. 


Arithmetics
Prolog user can doing arithmetic calculate with prolog, such as :


1. Arithmetic operator
X+Y : sum of X and Y
X-Y : dfference of X and Y
X*Y : product of X and Y
X/Y : quotient of X and Y
X//Y : the ‘integer quotient’ of X and Y (the result is truncated to the nearest integerbetween it and zero)
X^Y : X to the power of Y
-X : negative of X
abs(X) : absolute value of X
sin(X) : sine of X
cos(X) : cosine of X
max(X,Y) : yhe larger of X and Y
sqrt(X) : square root of X


2. Operator presedence in arithmetic expression
Prolog use ordinary algebra algorithm in arithmetic operation.
Ex : A+B*C-D
In the algebra, C*B are calculate first, then the result+A, then the result of sum-D. it is same with those in prolog. But, if we want to calculate A+B, C-D, then multiply both of the result, we must add the parentheses.
Ex : (A+B)*(C-D)


3. Relasion operator
The operator like =,!=, >, >=, <, <= can be used in prolog

Degree operator
Under is the rist of equality operators that used in prolog with the function of each operator:
• Arithmetic Expression Equality ( =:= )
• Arithmetic Expression Inequality ( =\= )
• Terms Identical ( == )
• Terms Not Identical ( \== )
• Terms Identical With Unification ( = )
• Non-Unification Between Two Terms( \= )

Logic operator
a. Operator NOT
Operator not can be placed before predicate to give the negation. Predicate that be negation has the truth value if the origin predicate is false and has the false value if the origin predicate is truth.
The example of using operator not :
dog(fido).
?- not dog(fido).
no
?- dog(fred).
no
?- not dog(fred).
Yes


b. Disjunction operator
Operator disjungsi (;) digunakan sebagai operator ‘atau’. Contoh :
?- 6 > 3;7 is 5+2.
yes
?- 6*6=:=36;10=8+3.
yes



Figure out the Practical Exercise 4 Page : 68




Kamis, 22 Oktober 2009

Fact, Rules, Predicate, and Variable in Prolog

Hellooo .. this is our Final Project on Third Week.
Lets do the exercise on Logic Programming using Prolog e-book Page 27.

Exercise no. 1
Type the following program into a file and load it into Prolog.

/* Animals Database */
animal(mammal,tiger,carnivore,stripes).
animal(mammal,hyena,carnivore,ugly).
animal(mammal,lion,carnivore,mane).
animal(mammal,zebra,herbivore,stripes).
animal(bird,eagle,carnivore,large).
animal(bird,sparrow,scavenger,small).
animal(reptile,snake,carnivore,long).
animal(reptile,lizard,scavenger,small).



Instructions : Devise 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.


Answer :

Step 1 . write down the following program to notepad, and save as .pl file. For this exercise, we will save it as numberone.pl



 Step 2 . Open your Prolog, click File>Consult and find the file you’ve just saved it. After you successfully open it, Prolog will show to you a successful quote like this image above.



Step 3 . First Question : find all mammals. just type ..
 animal(mammal,X,Y,Z).
   


Step 4 . for the second question : find all the carnivores that are
mammals. type ..

animal(mammal,X,carnivore,Z). 



Rule-based Expert System

Short definition about Rule-based Expert System is an expert system based on a set of rules that a human expert would follow in diagnosing a problem.

But .. WHAT ARE RULE-based EXPERT SYSTEM completely ??
Lets learn more ..

Conventional problem-solving computer programs make use of well-structured algorithms, data structures, and crisp reasoning strategies to find solutions. For the difficult problems with which expert systems are concerned, it may be more useful to employ heuristics: strategies that often lead to the correct solution, but that also sometimes fail. Conventional rule-based expert systems, use human expert knowledge to solve real-world problems that normally would require human intelligence. Expert knowledge is often represented in the form of rules or as data within the computer.

Depending upon the problem requirement, these rules anddata can be recalled to solve problems. Rule-based expert systems have played an important role in modern intelligent systems and their applications in strategic goal setting, planning, design, scheduling, fault monitoring, diagnosis and so on. With the technological advances made in the last decade, today’s users can choose from dozens of commercial software packages having friendly graphic user interfaces (Ignizio, 1991). Conventional computer programs perform tasks using a decision-making logic containing very little knowledge other than the basic algorithm for solving that specific problem. The basic knowledge is often embedded as part of the programming code, so that as the knowledge changes, the program has to be rebuilt. Knowledge-based expert systems collect the small fragments of human knowhow into a knowledge base, which is used to reason through a problem, using the knowledge that is appropriate. An important advantage here is that within the domain of the knowledge base, a different problem can be solved using the same program without reprogramming efforts.

Moreover, expert systems could explain the reasoning process and handle levels of confidence and uncertainty,
which conventional algorithms do not handle (Giarratano and Riley, 1989). Some of the important advantages of expert systems are as follows:
• ability to capture and preserve irreplaceable human experience;
• ability to develop a system more consistent than human experts;
• minimize human expertise needed at a number of locations at the same time (especially in a hostile  environment that is dangerous to human health);
• solutions can be developed faster than human experts.

The basic components of an expert system are illustrated in Figure 1. The knowledge base stores all relevant information, data, rules, cases, and relationships used by the expert system. A knowledge base can combine the knowledge of multiple human experts. A rule is a conditional statement that links given conditions to actions or outcomes. A frame is another approach used to capture and store knowledge in a knowledge base. It relates an object or item to various facts or values. A frame-based representation is ideally suited for object-oriented programming techniques. Expert systems making use of frames to store knowledge are also called frame-based expert systems. The purpose of the inference engine is to seek information and relationships from the knowledge base and to provide answers, predictions, and suggestions in the way a human expert would. The inference engine must find the right facts, interpretations, and rules and assemble them correctly. Two types of inference methods are commonly used – Backward chaining is the process of starting with conclusions and working backward to the supporting facts.

Forward chaining starts with the facts and works forward to the conclusions.


 Figure 1. Architecture of a simple expert system.

The explanation facility allows a user to understand how the expert system arrived at certain results. The overall purpose of the knowledge acquisition facility is to provide a convenient and efficient means for capturing and storing all components of the knowledge base. Very often specialized user interface software is used for designing, updating, and using expert systems. The purpose of the user interface is to ease use of the expert system for developers, users, and administrators.