Thursday, October 12, 2006

Congratulation Mail To Friend On Marriage

Prolog Language Features

programs:
For the implementation of Prolog programs, we propose the Ciao-Prolog, http://www.clip.dia.fi.upm.es/Software/Ciao/index.html # ciao
which has a shell that lets you run objectives.

The shell is an application that is included in the Ciao-Prolog with ciaosh name, and when you run the following message appears:

Ciao-Prolog 1.9 # 44: Mon Dec 30 16:47:15 2002
? -

The symbol? indicates the area where we can write the objectives to be executed.

For example:

Ciao-Prolog 1.9 # 44: Mon Dec 30 16:47:15 2002
? - F (X) = f (3).

X = 3?

To run the goal is to type dot, type ENTER.
Then the shel tell us whether the objective is successful or not and how the variables are instantiated. After which a question mark, which indicates that we can ask another solution by typing a semicolon (;) and pressing ENTER.

To upload a Ciao-Prolog program is as follows:


? - Consutl ('Programa.pl'). Yes


? -

Note that the filename is enclosed in single quotes. If you want to execute programs from a folder, such course would be:

? - Consutl ('c: / course / Programa.pl' .) Yes


? -


To exit the shell just type the predicate halt.
? - Halt.




2.2.1. Statement of facts and rules

As mentioned prolog-style rule is represented as:

Predicate (argument1, argument2 ,.....)

Pc (Arg, ..) if P1 (Arg .. ...) and P2 (Arg ,.....) and .......

But the correct syntax in Prolog would

Pc (Arg ,.....): - P1 (Arg ,......), P2 (Arg ,.....), P3 (Arg ,....)........
(which is the standard syntax is DEC 10 Prolog)

Some languages \u200b\u200balso accept the following syntax

Pc (Arg ,.....) if P1 (Arg ,....) and P2 (Arg ,....) and ..........

where each rule is called clause
And we will need to:
Pc - Pi
Pc: Head of the clause
Pi:
Main clause: - Neck of the clause. Sean

the following examples of facts or predicates:
parent (bob, luis).
parent (maria, luis).
parent (luis, jose).
parent (luis, ana).
parent (ana, Elena).

Now if you ask the Prolog compiler

? - Parent (bob, luis).
yes.

But if

? - parent (bob, sofia)


not be the answer, because there are no grounds to confirm the question.

If quiseramos know all the descendants of Louis

? - Parent (luis, X). Jose

X = X = Ana

Joseph and Ana are the descendants of Louis

Now let's define a rule or clause, so far we have only defined facts. Consider the rule
grandfather
grandfather (X, Y): - parent (X, Z), parent (Z, Y), male (X).
We took a predicate which was not defined (male), so we need to include new facts.
male (john).
male (Joseph).
male (luis).
female (ana).
female (maria).
women (Elena).
Now my knowledge base is composed of the rule grandfather and father made male and female.
And if you want to include the rule brother.
brother (X, Y): - parent (Z, X), parent (Z, Y), male (X). Rule
O mother, mother
(X, Y): - parent (X, Y), female (X).