Artificial-Intelligence-lab 7TH SEMESTER
Artificial-Intelligence-lab 7TH SEMESTER
Artificial-Intelligence-lab 7TH SEMESTER
LAB MANUAL
<TOPIC NAME>
Submitted in the Partial Fulfillment of the Requirement for the Award of
Bachelor of Technology
in
Computer Science & Engineering
Submitted By
<Name> <Roll No>
….
….
<Name> <Roll No>
Vision – Institute
To evolve into an Institution imparting high quality technical education infused with core
essentials of “Shiksha”, “Sanskar” and “Rojgar”.
Mission – Institute
M1: To strive for quality education of students by facilitating technology enabled holistic
learning programs.
M2: To inculcate principles of professional behavior that requires adherence to the values of
team work social conduct for the welfare of society.
M3: To provide necessary skills needed for entry into a global workforce with job assurance
as well as facilitate training and support that help in developing the entrepreneurial abilities.
Department – Vision
The Computer Science & Engineering Department aims to explore new avenues and dimensions
for making human life easier by offering students with the essential computational skills to
develop technology that serves the society by enhancing employability, deep understanding
of ethical values and responsibilities.
Department – Mission
M1: To ensure student’s progress through regular practice and implementation of new ideas
with an innovative approach
M2: To promote an environment of high moral values and discipline where students can
learn and Contribute towards the growth of self and society.
M2: To further an environment of entrepreneurship and professionalism of high excellence
and calibre, Giving professionals opportunities for employment and growth
College Code: 485
Department PEOs
To ensure that Students possess the understanding of engineering & computer science
to excel in chosen career path.
To create and provide opportunities for the sustainable development of students through
practical Experience and training programs.
Department PSOs
The ability to analyze and solve real life problems through the application of
fundamental knowledge of maths, science and engineering.
Understand the state of the art in the emerging areas of research in computer science
and engineering, formulate problems from them and perform original work to
contribute in the advancement of the state of the art.
PROGRAM OUTCOME
PO 1 Engineering Knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.
PO 2 Problem Analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO 3 Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
PO 4 Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions
PO 5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO 6 The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO 7 Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice
PO 9 Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO 10 Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
PO 11 Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
PO 12 Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
College Code: 485
COURSE OUTCOME
CO1: In a specialization domain of choice, students will be able to choose an appropriate
topic for study and will be able to clearly formulate & state a research problem and analyze
and understand the real-life problems and apply their knowledge to get programming
Solution.
CO2: For a selected Project topic, students will be able to compile the relevant literature and
frame hypotheses for project as applicable and engage in the creative design process through
the integration and application of diverse technical knowledge and expertise to meet customer
need and address socials issues.
CO3: For a selected topic, student manager will be able to plan a research design including
the sampling, observational, statistical and operational designs if any and Use the various
tools and techniques, coding practices for developing real life solution to the problems.
CO4: For a selected topic, student manager will be able to compile relevant data, interpret &
analyze it and test the hypotheses wherever applicable and Find out the error in software
solution and establishing the process to design maintainable software solution.
CO5: Based on the analysis and interpretation of the data collected, students will be able to
arrive at logical conclusions and propose suitable recommendations on the research problem.
Student manager will be able to create a logically coherent project report and will be able to
defend work in front of a panel of examiners and Write the report about what they are doing
in project and learning the team skills.
Department of Computer Science and Engineering
INDEX
S.No Practical’s Name Date Remark
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 WAP in turbo prolog for medical diagnosis and show t he
advantage and disadvantage of green and red cuts.
6 WAP to implement factorial, Fibonacci of a given number.
7 Write a program to solve 4-Queen problem.
8 Write a program to solve traveling salesman problem.
9 Write a program to solve water jug problem using LISP
S R INSTITUTE OF MANAGEMENT & TECHNOLOGY
LAB MANUAL
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’s
knowledge is obtained from expert sources such as texts, journal articles. databases etc and
encoded in a form suitable for the system to use in its inference or reasoning processes. 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 are interested in implementing new ideas quickly. New ideas
are rapidly implemented and experimented with.
OUTCOME: Students will get the basic idea of how to program in prolog and its working
environment.
S R INSTITUTE OF MANAGEMENT &
TECHNOLOGY
LAB MANUAL
Program:
Clauses
likes(ram ,mango).
girl(seema).
red(rose).
likes(bill ,cindy).
owns(john ,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.
OUTCOME: Student will understand how to write simple facts using prolog.
S R INSTITUTE OF MANAGEMENT &
TECHNOLOGY
LAB MANUAL
c_to_f f is c * 9 / 5 +32
freezing 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).
No
OUTCOME: Student will understand how to write a program using the rules.
LAB MANUAL
Parse Tree
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.
OUTCOME: Student will understand how to solve monkey banana problem using rules in
prolog.
S R INSTITUTE OF MANAGEMENT &
TECHNOLOGY
LAB MANUAL
Program:
Domains:
disease,indication=symbol
name-string
Predicates:
hypothesis(name,disease)
symptom(name,indication)
response(char)
go
goonce
clauses
go:-
goonce
write("will you like to try again (y/n)?"),
response(Reply),
Reply='n'.
go.
goonce:-
write("what is the patient's name"),nl,
readln(Patient),
hypothesis(Patient,Disease),!,
write(Patient,"probably has",Disease),!,
goonce:-
write("sorry, i am not ina position to diagnose"),
write("the disease").
symptom(Patient,fever):-
write("does",Patient,"has a fever (y/n)?"),nl,
response(Reply),
Reply='y',nl.
symptom(Patient,rash):-
Output:
OUTCOME: Student will understand how to create a expert system using prolog.
S R INSTITUTE OF MANAGEMENT &
TECHNOLOGY
LAB MANUAL
Program:
Factorial:
factorial(0,1).
factorial(N,F) :-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N * F1.
Output:
Goal:
?- factorial(4,X).
X=24
Fibonacci:
fib(0, 0).
fib(X, Y) :- X > 0, fib(X, Y, _).
fib(1, 1, 0).
fib(X, Y1, Y2) :-
X > 1,
X1 is X - 1,
fib(X1, Y2, Y3),
Y1 is Y2 + Y3.
Output:
Goal:
?-fib(10,X).
X=55
OUTCOME: Student will understand the implementation of Fibonacci and factorial series
using prolog.
S R INSTITUTE OF MANAGEMENT &
TECHNOLOGY
LAB MANUAL
Program:
In the 4 Queens problem the object is to place 4 queens on a chessboard in such a way that no
queens can capture a piece. This means that no two queens may be placed on the same row,
column, or diagonal.
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
Program:
Production Rules:-
route(Town1,Town2,Distance) road(Town1,Town2,Distance).
route(Town1,Town2,Distance)
road(Town1,X,Dist1),route(X,Town2,Dist2),Distance=Dist1+Dist2,
domains
town = symbol
distance = integer
predicates
nondeterm road(town,town,distance)
nondeterm route(town,town,distance)
clauses
road("tampa","houston",200).
road("gordon","tampa",300).
road("houston","gordon",100).
road("houston","kansas_city",120).
road("gordon","kansas_city",130).
route(Town1,Town2,Distance):-
road(Town1,Town2,Distance).
route(Town1,Town2,Distance):-
road(Town1,X,Dist1),
route(X,Town2,Dist2),
Distance=Dist1+Dist2,!.
Output:
Goal:
route("tampa", "kansas_city", X),
write("Distance from Tampa to Kansas City is ",X),nl.
Program:
;returns the quantity in first jug
(defun get-first-jug (state) (car state))
;return the state when the first jug is filled (first jug can hold 3)
(defun fill-first-jug (state)
(cond
((< (get-first-jug state) 3) (get-state 3 (get-second-jug state))))))
;returns the state when the second jug is filled (second jug can hold 5)
(defun fill-second-jug (state)
(cond
((< (get-second-jug state) 5) (get-state (get-first-jug state) 5))))
;;;MAIN FUNCTION
(defun dfs (start-state depth lmt)
(setf *node* 0)
(setf *limit* lmt)
(dfs-node start-state depth)
)
;dfs-node expands a node and calls dfs-children to recurse on it
(defun dfs-node (state depth)
(setf *node* (+ 1 *node*))
(cond
((is-goal state) (list state))
((zerop depth) nil)
((> *node* *limit*) nil)
((let ((goal-child (dfs-children (child-states state) (- depth 1))))
(and goal-child (cons state goal-child)))) ;for back-tracking if the branch don't have a goal
state
))