Artificial Intelligence COSC-3212: Laboratory Manual (Student Copy)
Artificial Intelligence COSC-3212: Laboratory Manual (Student Copy)
Artificial Intelligence
COSC-3212
Lab Instructor:
Ms. Humaira Anwer
Student Name
Student Roll #
Department
Year/Section
To suggest more improvements and corrections please feel free to email to [email protected]. All rights
are reserved by the author. Manufactured in Pakistan. Except as permitted under the Pakistan States Copyright Act
of 1971, no part of this report may be reproduced or distributed in any form or by any means, or stored in a database
or retrieval system, without the prior written consent of the author, including, but not limited to, network or other
electronic storage or transmission, or broadcast for distance learning.
_____________________________________________________________________________
Artificial Intelligence-Lab [COSC-3212]
INDEX
01
02
03
04
05
06
07
08
09
10
11
_____________________________________________________________________________
Artificial Intelligence-Lab [COSC-3212]
12
13
14
15
16
_____________________________________________________________________________
Artificial Intelligence-Lab [COSC-3212]
STUDY OF PROLOG
Lab-01
___________________________________________________________________________1
Artificial Intelligence-Lab [COSC-3212]
1. OBJECTIVES
What is Prolog
Applications of Prolog
Installation
Prolog Code
Built in Predicates
Prolog Clauses
2. PROLOG
a) Prolog stands for programming in logic. In the logic programming paradigm, prolog language is most
widely available. Prolog is a declarative language, which means that a program consists of data based
on the facts and rules (Logical relationship) rather than computing how to find a solution. A logical
relationship describes the relationships which hold for the given application.
b) To obtain the solution, the user asks a question rather than running a program. When a user asks a
question, then to determine the answer, the run time system searches through the database of facts and
rules.
c) The first Prolog was 'Marseille Prolog', which is based on work by Colmerauer. The major example
of fourth-generation programming language was prolog. It supports the declarative programming
paradigm.
d) Prolog features are 'Logical variable', which means that they behave like uniform data structure, a
backtracking strategy to search for proofs, a pattern-matching facility, mathematical variable, and
input and out are interchangeable.
e) To deduce the answer, there will be more than one way. In such case, the run time system will be
asked to find another solution. To generate another solution, use the backtracking strategy. Prolog is a
weakly typed language with static scope rules and dynamic type checking.
f) Prolog is a declarative language that means we can specify what problem we want to solve rather than
how to solve it.
g) Prolog is used in some areas like database, natural language processing, artificial intelligence, but it is
pretty useless in some areas like a numerical algorithm or instance graphics.
h) In artificial intelligence applications, prolog is used. The artificial intelligence applications can be
automated reasoning systems, natural language interfaces, and expert systems. The expert system
consists of an interface engine and a database of facts. The prolog's run time system provides the
service of an interface engine.
___________________________________________________________________________2
Artificial Intelligence-Lab [COSC-3212]
3. Applications of Prolog
a) Specification Language
b) Robot Planning
c) Natural language understanding
d) Machine Learning
e) Problem Solving
f) Intelligent Database retrieval
g) Expert System
h) Automated Reasoning
4. Prolog Code
After startup, Prolog will produce a number of lines of headings in the starting, which is followed by a
line, that contains:
?-
The above symbol shows the system prompt. The prompt is used to show that the Prolog system is ready
to specify one or more goals of sequence to the user. Using a full stop, we can terminate the sequence of
goals.
For example:
?- write('Welcome'),nl,write(' To Prolog'),nl.
nl indicates 'start a new line'. When we press 'return' key, the above line will show the effect like this:
Welcome
To Prolog
true
5. Built-in Predicates
a) Write
b) nl
c) halt. The above command is used to terminate the Prolog system.
___________________________________________________________________________3
Artificial Intelligence-Lab [COSC-3212]
d) statistics.
This command will cause the Prolog system statistics. This statistics feature is mainly used to
experienced user.
6. PROLOG CLAUSES
In Prolog, the program contains a sequence of clauses. The clauses can run over many lines.
Clause can be terminated using a dot character.
FACTS:
Facts are specified in the form of the head. Head is known as the clause head.
The Head of the clause must be a compound term or atom. Compound terms and atoms are
collectively called as terms.
7. LAB TASKS
Given a database of facts such as that above, make queries by typing after a symbol’?’
statements in prolog complier and write result in the following table:
Table I. Result of Queries
Queries Result
?-likes(X, food).
?-likes(X,Y).
?-likes(X, mary).
?-likes(john, food).
___________________________________________________________________________4
Artificial Intelligence-Lab [COSC-3212]
?-likes(mary,juice).
We can state that Mia, Jody, and Yolanda are women, that Jody plays air guitar, and that a party
is taking place. Write facts for this description in table II below:
Table II.
Sr. No Facts
Open Swi-Prolog compiler, and write some predicates to print the following lines in the given
format.
Its declarative
Code:
___________________________________________________________________________5
Artificial Intelligence-Lab [COSC-3212]
7.4. Lab Task 4
Queries Result
?-eat(X,Y).
?-eat(X, snake).
?-eat(goat, Y).
?-eat(elephant, grass).
___________________________________________________________________________6
Artificial Intelligence-Lab [COSC-3212]