0% found this document useful (0 votes)
11 views8 pages

SWI Prolog

The document provides an overview of Prolog programming, including software options like SWI-Prolog and GNU-Prolog, and explains how to create and run Prolog programs. It covers key concepts such as query mode, the principle of resolution, unification, structures, and equality in Prolog. Examples illustrate how to load programs and perform queries within the Prolog environment.

Uploaded by

damdipayan2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

SWI Prolog

The document provides an overview of Prolog programming, including software options like SWI-Prolog and GNU-Prolog, and explains how to create and run Prolog programs. It covers key concepts such as query mode, the principle of resolution, unification, structures, and equality in Prolog. Examples illustrate how to load programs and perform queries within the Prolog environment.

Uploaded by

damdipayan2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Software to Run Prolog

• SWI-Prolog
• GNU-Prolog
• XSB Prolog
A Prolog Program
• The program, sometimes called Database is a text file (*.pl)
that contain the facts and rules. It contains all the relations
needed to define the problem.

• When you launch a program you are in query mode


represented by the ? – prompt. In query mode you ask
questions about the relations described in the program.

• When Prolog is launched the ?- should appear meaning you


are in query mode. In SWI-Prolog you can load a program by
typing the command [file]. when the file containing your
program is [Link]. When you have done this you can use all the
facts and rules that are contained in the program.
SWI-Prolog
• We will use SWI-Prolog for the Prolog programming
assignment
– [Link]
• After the installation, try the example program
?- [likes].
Load example [Link]
% likes compiled 0.00 sec, 2,148 bytes
Yes This goal cannot be proved, so it assumed to be
?- likes(sam, curry). false (This is the so called Close World Assumption)
No
Asks the interpreter to
?- likes(sam, X). find more solutions
X = dahl ;
X = tandoori ;
X = kurma ;
Principle of Resolution
• Prolog execution is based on the principle of resolution
– If C1 and C2 are Horn clauses and the head of C1 matches one
of the terms in the body of C2, then we can replace the term
in C2 with the body of C1
• For example,
C1: likes(sam,Food) :- indian(Food), mild(Food).
C2: indian(dahl).
C3: mild(dahl).

– We can replace the first and the second terms in C1 by C2 and


C3 using the principle of resolution (after instantiating variable
Food to dahl)
– Therefore, likes(sam, dahl) can be proved
Unification
• Can the given terms be made to represent the
same structure
• Prolog associates variables and values using a process
known as unification
– Variable that receive a value are said to be instantiated
• Unification rules
– A constant unifies only with itself
– Two structures unify if and only if they have the same functor
and the same number of arguments, and the corresponding
arguments unify recursively
– A variable unifies to with anything
Structures
• Structures consist of an atom called the functor
and a list of arguments
– E.g. date(Year,Month,Day)
–[Link]
T = tree(3, tree(2,nil,nil), tree(5,nil,nil))

2 5
Equality
• Equality is defined as unifiability
– An equality goal is using an infix predicate =
• For instance,
?- dahl = dahl.
Yes
?- dahl = curry.
No
?- likes(Person, dahl) = likes(sam, Food).
Person = sam
Food = dahl ;
No
?- likes(Person, curry) = likes(sam, Food).
Person = sam
Food = curry ;
No
Equality
• What is the results of

?- likes(Person, Food) = likes(sam, Food).

Person = sam
Food = _G158 ;

No Internal Representation for an


uninstantiated variable
Any instantiation proves the equality

You might also like