0% found this document useful (0 votes)
42 views15 pages

Csbs-Ai Lab Manual

Uploaded by

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

Csbs-Ai Lab Manual

Uploaded by

Yogesh 02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS

RECORD NOTE BOOK

2022 – 2023

DHANALAKSHMI SRINIVASAN COLLEGE OF


ENGINEERING
NAVAKKARAI, COIMBATORE-641 105
LIST OF EXPERIMENTS :

1. Study of Prolog.
2. Write simple fact for the statements using PROLOG.
3. Write predicates one converts centigrade temperatures to Fahrenheit, the other
checks if a temperature is below freezing.
4. Write a program to solve the Monkey Banana problem.
5. Write a program in turbo prolog for medical diagnosis and show t he advantage
and disadvantage of green and red cuts.
6. Write a program to solve 4-Queen problem.
7. Write a program to solve any problem usingBreadth FirstSearch.
8. Write a program to solve Missionaries and Cannibal problem.
9. Write a program to solve water jug problem using LISP
10. Case study – expert system

PREPARED BY
Mr.A.D.Saravanaprabhu/AP
Ex:No:1 STUDY OF PROLOG
DATE:

PROLOG-PROGRAMMING IN LOGIC:

PROLOG stands for Programming, In Logic — an idea that emerged in the early 1970’s to
use logic as programming language. The early developers of this idea included Robert Kowaiski at
Edinburgh (on the theoretical side), Marrten van Emden at Edinburgh (experimental demonstration) and
Alian Colmerauer at Marseilles (implementation). David D.H. Warren’s efficient
implementation at Edinburgh in the mid -1970’s greatly contributed to the popularity of PROLOG.
PROLOG is a programming language centred around a small set of basic mechanisms, Including
pattern matching, tree based data structuring and automatic backtracking. This Small set constitutes a
surprisingly powerful and flexible programming framework. PROLOG is especially well suited for
problems that involve objects- in particular, structured objects- and relations between them.

SYMBOLIC LANGUAGE

PROLOG is a programming language for symbolic, non-numeric computation. It is


especially well suited for solving problems that involve objects and relations between objects.
For example, it is an easy exercise in prolog to express spatial relationship between
objects,such as the blue sphere is behind the green one. It is also easy to state a more general rule: if
object X is closer to the observer than object Y. and object Y is closer than Z, then X must be closer than
Z. PROLOG can reason about the spatial relationships and their consistency with respect to the general
rule. Features like this make PROLOG a powerful language for Artificia1 LanguageA1,) and non-
numerical programming.
There are well-known examples of symbolic computation whose implementation in other standard
languages took tens of pages of indigestible code, when the same algorithms were implemented in
PROLOG, the result was a crystal-clear program easily fitting on one page.
FACTS, RULES AND QUERIES

Progmmming in PROIOG is accomplished by creating a database of facts and rules about


objects, their properties, and their relationships to other objects. Queries then can be posed about the
objects and valid conclusions will be determined and returned by the program.Responsesto user queries
are determined through a form of inference control known as resolution.
FOR EXAMPLE:
a) FACTS:

Some facts about family relationships could be written as:


sister( sue,bill) parent( ann.sam)male(jo)
female( riya)

b) RULES:

To represent the general rule for grandfather,


we write: grand father( X2)parent(X,Y)
parent( Y,Z)male(X)

c) QUERIES:

Given a database of facts and rules such as that above, we may make queries by typing after a
query
a symbol’?’ statements such as:
?-parent(X,sam) Xann
?grandfather(X,Y)X=jo, Y=sam

PROLOG IN DISGINING EXPERT SYSTEMS

An expert system is a set of programs that manipulates encoded knowledge to solve problems
in a specialized domain that normally requires human expertise. An expert system’sknowledge is
obtained from expert sources such as texts, journal articles. databases etc and encodedin a form suitable
for the system to use in its inference or reasoning processes.

5
Once a sufficient body of expert knowledge has been acquired, it must be encoded in some
form, loaded into knowledge base, then tested, and refined continually throughout the life of the
system PROLOG serves as a powerful language in designing expert systems because of its following
features.

• Use of knowledge rather than data modification of the knowledge base without
recompilation of the control programs.

• Capable of explaining conclusion.

• Symbolic computations resembling manipulations of natural language.

• Reason with meta-knowledge.

META PROGRAMMING
A meta-program is a program that takes other programs as data. Interpreters and compilers
are examples of mela-programs. Meta-interpreter is a particular kind of meta-program: an interpreter
for a language written in that language. So a PROLOG interpreter is an interpreter for PROLOG,
itself written in PROLOG. Due to its symbol- manipulation capabilities, PROLOG is a powerful
language for meta-programming. Therefore, it is often used as an implementation language for other
languages. PROLOG is particularly suitable as a language for rapid prototyping where we areinterested
in implementing new ideas quickly. New ideas are rapidly implemented and experimented with.

6
Ex.No :2 SIMPLE FACT FOR THE STATEMENTS USING PROLOG
DATE:

Aim:
To write simple fact for the statements using prolog.

Algorithm:

Step1: In Prolog syntax, we can write − Understand logical programming syntax and semantics.
Design programs in PROLOG language.
Step2: Prolog programs describe relations, defined by means of clauses. Pure prolog is
restrictedto horn clauses. There are two types of clauses: facts and rules. A rule is one of the
form Head:-Body.and is read as “Head is true if Body is true”.
Step3: A rule's body consists of calls to predicates, which are called the rule's goals.
• Ram like s mango.
• Seema is a girl.
• Bill likes Cindy.
• Rose is red.
• John owns gold.

Output:

Goal queries
?-likes(ram,What).What= mango
?-likes(Who,cindy).Who= cindy
?-red(What).What= rose
?-owns(Who,What).
Who= john What= gold.

7
Ex.No:3 CONVERSION FOR WRITING PREDICATES
DATE:

Aim :
To write predicates one converts centigrade temperatures to Fahrenheit, the other
checks if a temperature is below freezing.

Algorithm:

Step 1: Start the program


Step 2 : Read the input of temperature in Celsius (say C)Step 3 : F=(9*C)/5+32
Step 4 : Print temperature in fahrenheit is FStep 5 : print the output.

Procedure:

Production rules:Arithmetic:
c_to_f = f is c * 9 / 5 +32freezing = f < = 32

Rules:
c_to_f(C,F) :-
F is C * 9 / 5 + 32.freezing(F) :-
F =< 32.

Output:

Queries:
?- c_to_f(100,X).X = 212
Yes
?- freezing(15)
.Yes
?- freezing(45).N

8
Ex.No:4 SOLVING THE MONKEY BANANA PROBLEM.
DATE:

Aim :
To write a program to solve the monkey banana problem using prolog.

Algorithm :
The monkey can perform the following actions:-
Step1: Walk on the floor.
Step2: Climb the box.
Step3: Push the box around (if it is beside the box).
Step4: Grasp the banana if it is standing on the box directly under the banana.
Step5: Production Rules:
can_reach(clever,close)
get_on:(can_climb)
under(in room,in_room,in_room,can_climb)Close(get_on,under| tall)

Procedure:

Clauses:
in_room(bananas).
in_room(chair).
in_room(monkey).
clever(monkey).
can_climb(monkey, chair).
tall(chair).
can_move(monkey, chair, bananas).
can_reach(X, Y):-
clever(X),close(X, Y).
get_on(X,Y):-
can_climb(X,Y). under(Y,Z):-
in_room(X),
in_room(Y),in_room(Z),can_climb(X,Y,Z)
. close(X,Z):-get_on(X,Y),
under(Y,Z);
tall(Y).

Output:
Queries:
?- can_reach(A, B).A = monkey.
B = banana.
?- can_reach(monkey, banana).Yes.

9
Ex.No:5 MEDICAL DIAGNOSIS WITH GREEN AND
DATE: RED CUTS

Aim:
To write a prolog program for medical diagnosis.

Procedure :

Tuberculosis is a lung disease whose symptoms are persistant cough, constant fatigue, weight loss,
loss of appetite, fever, coughing up blood, night sweats. So it will be stored in knowledge base in the
form of a rule which is as follow:-

Disease (Patient, tuberculosis):-


Symptom (Patient, persistant_cough),
Symptom (Patient, constant_fatigue),
Symptom (Patient, weight_loss),
Symptom (Patient, loss_of_appetite),
Symptom (Patient, fever),
Symptom (Patient, coughing_up_blood),
Symptom (Patient, night_sweats).

You can also take some other examples, which are given below:-
Pneumonia is a disease whose symptoms are cough, fever, shaking chills, shortness of breath.
So itwill be stored in knowledge base as follow:-
Disease (Patient, pneumonia):-
Symptom (Patient, cough),
Symptom (Patient, fever),
Symptom (Patient, shaking_chills),
Symptom (Patient, shortness_of_breath).

Output:
makewindow(1,7,7"Expert Medical Diagnosis",2,2,23,70),

10
Ex.No:6 SOLVING 4-QUEEN PROBLEM.
DATE:

Aim:
To write a program for placing 4 Queens on a chessboard using C programming

Algorithm:

Step1: The N-Queens problem is to place N-queens in such a manner on an NxN


chessboard that no queens attack each other by being in the same row,columnor
diagonal.
Step2: Here we solve the problem for N = 4queens.
Step3: Before solving the problem,let’s know about the movement of the queen in
chess.
Step4: In the chess game, a queen can move any number of steps in any direction like
vertical,horizontal, and diagonal.
Step5: In the 4-Queens problem we have to place 4 queens such as Q1,Q2,Q3,and Q4on
the chessboard, in such away that no two attack each other.

Description:-
In the 4 Queens problem the object is to place 4 queens on a chessboard in sucha
way that no queens can capture a piece. This means that no two queens may be placed
on the same row, column, or diagonal.

The n Queens Chessboard.domains


queen = q(integer, integer)queens = queen*
freelist = integer*
board = board(queens, freelist, freelist, freelist, freelist)predicates
nondeterm placeN(integer, board, board) nondeterm
place_a_queen(integer, board, board)nondeterm nqueens(integer)
nondeterm makelist(integer, freelist)
nondeterm findandremove(integer, freelist, freelist)
nextrow(integer, freelist, freelist)

Output:
Goal:

?-nqueens(4),nl. board([q(1,2),q(2,4),q(3,1),q(4,3),[],[],[7,4,1],[7,4,1])
yes

11
Ex.no:7 SOLVING A PROBLEM USING
DATE: BREADTH FIRST SEARCH

Aim:
To find the shortest path using BFS algorithm concepts in prolog.

Algorithm:

Step1: Pick any node, visit the adjacent unvisited vertex, mark it as visited, displayit, and
insert it in a queue.
Step2: If there are no remaining adjacent vertices left, remove the first vertex from the
queue.
Step3: Repeat step 1 and step 2 until the queue is empty or the desired node is found.

Procedure:

graph = {
'A' : ['B','C'],
'B' : ['D', 'E'],
'C' : ['F'],
'D' : [],
'E' : ['F'],'F' : []
}
visited = [] # List to keep track of visited nodes.queue = [] #Initialize a queue
def bfs(visited, graph, node):visited.append(node) queue.append(node)
while queue:
s = queue.pop(0) print (s, end = " ")
for neighbour in graph[s]: if neighbour not in visited:visited.append(neighbour)
queue.append(neighbour) # Driver Code
bfs(visited, graph, 'A')

Output : BFS(ABCDEF)

12
Ex.No:8 SOLVING MISSIONARIES AND CANNIBAL PROBLEM
DATE:

Aim:
To write a program to solve Missionaries and Cannibal problem

Algorithm:
Game start now the task is to move all of them to right side of the river rules:
Step1: The boat can carry at most two people
Step2: If cannibals num greater than missionaries then the cannibals would eat the
missionaries.
Step3: The boat cannot cross the river by itself with no people on board M M M
C C C |--- |
Left side -> right side river travel

Description :
Missionaries and Cannibals can be solved by using different search algorithms like Breadth
first and Depth first search algorithm to find the solution. The node of the graph to be
searched is represented by a state space. Each state space can be represent
by: State(no_of_missionaries, no_of_cannibals, side_of_the_boat)
Where, no_of_missonaries are the number of missionaries atleft side of river,
no_of_cannibals are the number of cannibals at the left side of river and side_of_the_boat is the side of
the boat at particular state. For our case
InitialState=>State(3,3,0)an
d Final State => State(0, 0,
1).
Where 0 represents left side and 1 represents right side of river. We should make a graph search
which traverse the graph from initial state and find out the final state in fewest moves. There are many
AI searches that search the graphs like Breadth first search, Depth first search, or iterative deepening
search. Each of these different search methods has different properties such as whether a result is
guaranteed,and how much time and space is needed to carry out the search. This project uses Breadth
first and Depth first search.

13
Production rules for Missionaries and Cannibals problem
Possible Moves
A move is characterized by the number of missionaries and the number of cannibals
taken in the boat at one time. Since the boat can carry no more than two people at once, the only
feasible combinations are:
Carry(2,0).
Carry(1,0).
Carry(1,1).
Carry(0,1).
Carry(0,2).
Where Carry (M, C) means the boat will carry M missionaries and C cannibals on one trip.
Feasible Moves
Once we have found a possible move, we have to confirm that it is feasible. It is not afeasible to
move more missionaries or more cannibals than that are present on one bank.
When the state is state(M1, C1, left) and we try carry (M,C) then M must be true.
When the state is state(M1, C1, right) and we try carry(M, C) then
M + M1 must be true.

Legal Moves
Once we have found a feasible move, we must check that is legal i.e. no missionaries must be
eaten.
Legal(X,X).
Legal(3,X).
Legal(0,X).
The only safe combinations are when there are equal numbers of missionaries and cannibals or all the
missionaries are on one side.

Output:

Path([3,3,left],[0,0,right],[3,3,left]],-). Output([]) :- n1,n1.


Output([A,B,String] | T]) :- Output(T),
Write(B),Write(‘….’),Write(A),Write(‘:]),Write(string),n1.

14
Ex.no:9 SOLVING WATER JUG PROBLEM
DATE: USING LISP

Aim:
To write a program to solve water jug problem using Lisp.

Algorithm:

Step1: Empty a Jug, (X, Y)->(0, Y) Empty Jug 1

Step2: Fill a Jug, (0, 0)->(X, 0) Fill Jug 1

Step3: Pour water from one jug to the other until one of the jugs is either empty or full,

(X, Y) ->(X-d, Y+d)

PROCEDURE :
1. First we will fill the 4 litre jug completely with water.

2. Then optimal approach would be to empty water from 4-litre jug into 3-litre (leaving 1Lwater
in 4L jug and 3L completely full). Hence we got 1L water. Now, Empty water from 3L.

3. Pour the water from 4L jug into 3L jug Now 4L container is completely empty and1L water in
present in 3L litre jug.

4. Fill the 4L jug with water completely again.

5. On transferring water from 4L jug to 3L jug, we will get 2L water in 4L jug which wasour
required quantity.

Output :
Input: X = 3, Y = 5, Z = 4
Output: 6

15
Ex:No:10 CASE STUDY – EXPERT SYSTEM
DATE:

EXPERT SYSTEM:
Expert system needs similar knowledge which is fetched from its knowledge base, and then
interprets it according to user’s problem. All data is inserted in the knowledge base by domain experts
who are expert in specific domain. This computer based applications are used by userswho are
non- experts in this area for obtaining information.

Types of Expert System


There are different types of expert system in artificial intelligence.
Below explain each one –

Rule Based Expert System


This expert system contains the group of rules, and these rules are straight forward, more
expressive and flexible. In this system, knowledge is denominated like as set of rules that is
theoretically otherwise understanding of Domain or subject. Rule based ES has five components such
as knowledge base, database, inference engine, explanation facility and user interface.

Fuzzy Expert System


If, you want to express the expert knowledge which are used unclear and vague values
such as “very tall”, “heavily reduced”, and more. Then we can implement the fuzzy set theory.Fuzzy
base expert system is based on ideas which are expressed on the sliding scale, which allowing you to
get different between members of the class from non-members.

Frame Based Expert System


This expert systems use the several frames for representing of knowledge.
A Frame acts as data structure that is contained the knowledge about specific objects otherwise
concepts. Main objective of all frames are to capture and represent knowledge into frame basedES,
and every frame contains its name and group of attributes.

Hybrid Expert System


Hybrid Expert System is combination of the advantages of rule based expert system,
fuzzy expert system, and frame based expert system, then it is known as “Hybrid Expert System”.

16

You might also like