Subscribe:

Tampilkan postingan dengan label TUTORIAL. Tampilkan semua postingan
Tampilkan postingan dengan label TUTORIAL. Tampilkan semua postingan
































Yuuuhuuu...hellow we meet again...
This time we'll learn next chapter of logic programming with prolog.
So lets start...














































































Just like we said before,
we'll try to figure out the Pratical Exercise 4 Page 68 with the images of captured prolog work.
Nah...this is the time,
please enjoy our journey of learning...

This program is based on Animals Program given in Chapter 3


Convert the seven predicates used to operator form and test your revised program. The output should be the same as the output from the program above. Include directives to define the operators in your program.
To make it more easier to read, then we can change the database. We're gonna convert seven predicates in the database, they are :



How to use xf and xfy :
1. First of all, load the database with consult predicate ?-consult('database2.pl')
2. The is_a_dog predicate



3. The is_a_cat predicate


4. The is_large predicate


5. The is_small predicate


6. The is_large_dog predicate


7. The is_small_animal predicate


8. The chases predicate





You can see that both of the prolog have the same result. Converted predicates are easier to read.
fido chases mary is easier to understand than chases(fido,mary).
Basicly, they are the same, the different between them is just the way of writing.

Hope you are not being confused with this concept.
Okay...see you in the next lesson.
See youuuu...
Keep the spirit of learning...
\(^.^)/


Regards,
Mathlovers
Hello again,
this time we're gonna learn about Operators and Arithmetic in Prolog.
But first we have to know what the meaning of Operators and Arithmetic.

Operators
The standard one of a functor followed by a number of arguments in parentheses, e.g. likes(john,mary).
As an alternative, any user-defined predicate with two arguments (a binary predicate) can be converted to an infix operator. This enables the functor (predicate name) to be written beetwen the two arguments with no parentheses e.g. john likes mary.
Any user-defined predicate with one argument (a unary predicate) can be converted to a prefix operator. This enables the functor to be written before the argument with no parentheses e.g.
isa_dog fred
instead of
isa_dog(fred)
a unary predicates can be converted to a postfix operator. This is enables the functor to be written after the argument e.g.
fred isa_dog
Operators notation can be used with rules to aid readability.
Such as :
likes(john,X):-is_female(X),owns(X,Y),isa_cat.(Y)
is a valid form from previous rule but easier to understand if it is written as
john likes X:- X is_female, X owns Y, Y isa_cat.
The standard bracketed "functor and arguments' notation can still be used with operators if preferred. likes, is_female, owns, ang isa_cat are operators.
Bracketed notation may also built-in predicates that are defined as operators.


Arithmetic
Prolog also provides facilities for doing arithmetic using a notation simiiar to that which will already be familiar to many users from basic algebra.
Any variables appearing in an arithmatic expressions must already be bound and their values must be numerical.
Symbols such as +-*/ in arithmetic expressions are a special type of infix operators known as arithmetic operators. Unlike operators used elsewhere in Prolog they are not predicates but functions, which return a numerical value.

Operator Precedence in Arithmetic Expressions
Whwn there is more than one operator in an arithmetic expressions, example A*B+C-D, prolog needs a means of deciding the order in which the operators will be applied.
Prolog achives this by giving each operators a numerical precedence value.
Operators with relatively high precedence such as * and / are applied before those with lower precedence such as + and -. Operators with same precedence are applied from left to right.
If a different order of evaluation is required this can be archieved by use of brackets. Bracketed expressions are always evaluated first.

Relational Operators
The infix operators =:= =\= > >= < <= are a special type known as relational operators. They are used to compare the value of two arithmetic expressions. Both arguments must be numbers, bound variables or arithmetic expressions.


Equality Operators
There are 3 types of relational operators for testing equality and inequality available in Prolog. The first type is to compare the values of arithmetic expressions, the othr two are to compare terms.

Arithmetic Expression Equality =:=
E1=:=E2 succeeds if the arithmetic expression E1 and E2 to the same value.

Arithmetic Expression Inequality =\=
E1=\=E2 succeeds if the arithmetic expression E1 and E2 do not evaluate to the same value.

Term Identical
Boh arguments of the infix operator == must be terms.
E1==E2 succeeds if and only if E1 is identical to E2.

Terms Not Identical \==
E1\==E2 tests whether E1 is not identical to E2.
E1\==E2 succeeds if E1==E2 fails.

Terms Identical With Unifications =
The term equality operator = is similar to == with one vital (and often very usful) difference.
E1=E2 succeeds if terms E1 and E2 unify, i.e. there is some way of binding variables to values which would make the terms identical.

Non-Unification Between Two Terms \=
E1\=E2 succeeds if E1=E2 fails.


Logical Operators
The Not Operator
The prefix operator not can be placed before any goal to give its negation.
The negated goal succeeds if the oriinal goal fails and fails if the original goal succeeds.

The Disjunction Operator
The disjunction operator ; is used to represent 'or'.
It is an infix operator that takes two arguments, both of which are goals.
E1;E2 succeeds if either E1 or E2 succeeds.


Okay,
that's all the summary Chapter 4 of Logic programming With Prolog.
Next we'll try to figure out the Pratical Exercise 4 Page 68 with the images of captured prolog work.
Be there or behind (~_^)

Regards,
Mathlovers.
Hello there, we meet again,
now we're gonna learn about fact using Prolog.
Okey, let's start....

Exercise 1 : Animal

This Exercise is to show how to devise and test goals to find (a) all the mammals, (b) all the carnivores that are mammals, (c) all the mammals with stripes, (d) wether there is reptile that has a mane.

First run prolog.exe and then make a database.

This is how to show all the animals.

We can see that all the mammals are :

Next, how to find all the carnivoran mammals.

We can see that all the carnivoran mammals are :

Then, how to know all mammals that have stripes?

We can see that mammals that have stripes are zebra and tiger.


Now lets try to find is there any reptile that have mane?


Ooops...there's no reptille that have mane.


Exercise 2 : Couple

Lets extend the program with a rule that defines a predicate couple with two arguments, the first being the name of a man and the second being the name of a woman.

Load your revised program into Prolog and lets test it.

Now we'll try to make some couples from 3 men and 3 women, there's 9 posibilities.

Lets begin...

First run prolog.exe then make a database.



input the command and the result is


Soooo eazy rite?


Hope you enjoy and understand all steps of this tutorial,

just like we do (^_^)V


Okay...

see you on next tutorial from us,

don't miss it!!!


Regards,

Mathlovers.





 
Copyright 2009 mathlovers