0% found this document useful (0 votes)
70 views10 pages

Artificial Intelligence COSC-3212: Laboratory Manual (Student Copy)

Uploaded by

every one
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)
70 views10 pages

Artificial Intelligence COSC-3212: Laboratory Manual (Student Copy)

Uploaded by

every one
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
You are on page 1/ 10

Laboratory Manual (Student Copy)

for use with

Artificial Intelligence
COSC-3212

Lab Instructor:
Ms. Humaira Anwer
Student Name

Student Roll #

Department

Year/Section

Copyright © 2019 Ms. Humaira Anwer

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

S. No. Practical’s Name Date Remarks

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

The applications of Prolog are as follows:

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

The Prolog system predefined the meanings of some predicates like.

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.

Clauses are of two types: 1) Facts 2) Rules.

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.

Some facts could be written as:


likes(mary,food).
likes(mary,juice).
likes(john,juice).
likes(john,mary).

7. LAB TASKS

7.1. Lab Task 1

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).

7.2. Lab Task 2

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

7.3. Lab Task 3

Open Swi-Prolog compiler, and write some predicates to print the following lines in the given
format.

Prolog is Programming in Logic

Its a 4th Gen Language

Its declarative

Code:

___________________________________________________________________________5
Artificial Intelligence-Lab [COSC-3212]
7.4. Lab Task 4

Given some facts,

eat (cat, mouse).


eat(mouse, insect).
eat (insects, flies).
eat (hawk, snake).
eat(snake, mouse).
eat(shark, small fish).
eat(goat, grass).

Table III. Result of Queries

Queries Result

?-eats(X, small fish).

?-eat(X,Y).

?-eat(X, snake).

?-eat(goat, Y).

?-eat(elephant, grass).

___________________________________________________________________________6
Artificial Intelligence-Lab [COSC-3212]

You might also like