SlideShare a Scribd company logo
3
Most read
4
Most read
17
Most read
1
Experiment No. : 01
Experiment Name : Write a Prolog program for addition of two numbers in Artificial Intelligence.
Objective : To find the summation of two numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X , Y
Set S to X+Y
Write S
Code :
% Prolog program for addition of two numbers------------
% Alamgir, CSE, JUST
go:- write('Enter first number : '), read(X),nl,
write('Enter second number : '), read(Y),nl,
sum(X,Y).
sum(X,Y):-
S is X+Y,
write('Summation of the two given number is : '), write(S)
Input :
go.
Enter first number : 100.
Enter second number : 200.
Output :
Summation of the two given number is : 300
2
Experiment No. : 02
Experiment Name : Write a Prolog program for addition & multiplication of two numbers in Artificial
Intelligence.
Objective : To find the addition & multiplication of two numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X , Y
Set S to X+Y
Set M to X*Y
Write S,M
Code :
% Prolog program for addition and multplication--------
% Alamgir, CSE, JUST
go:- write('Enter first number : '),read(X),nl,
write('Enter second number : '),read(Y),nl,
addmul(X,Y).
addmul(X,Y):-
S is X+Y,
M is X*Y,
write('Addition of the two number is : '),write(S),nl,
write('Multiplication of the two number is : '),write(M).
Input:
go.
Enter first number : 20.
Enter second number : 10.
Output :
Addition of the two number is : 30
Multiplication of the two number is : 200
3
Experiment No. : 03
Experiment Name : Write a Prolog program for finding the sum of all numbers in a given list in Artificial
Intelligence.
Objective : To find the sum of all numbers in a given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read all numbers
Add number and set to Result
Write Result
Code :
% Prolog program for find the sum of all numbers in a given list-------
% Alamgir, CSE, JUST
list([H|T],Result):-
listhelper(T,H,Result).
listhelper([],Acc,Acc).
listhelper([H|T],Acc,Result):-
Nacc is H+Acc,
listhelper(T,Nacc,Result).
Input: list([12,23,4,5,10,23,45],Result).
Output : Result = 122
4
Experiment No. : 04
Experiment Name : Write a Prolog program for comparing Character and String in Artificial Intelligence.
Objective : To compare character and String.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read two string
Compare Strings
Write Result
Code :
% Alamgir, CSE, JUST
predicates
start
comp_str(string,string)
comp_char(char,string)
goal
clearwindow,
start.
clauses
start:-
comp_str("abcd","dcab"),
write("equal"),nl.
start:-
write("not equal"),nl.
comp_str(Str1,Str2):-
Str1 <> "",
frontchar(Str1,Char1,Rest1),
comp_char(Char1,Str2),
comp_str(Rest1,Str2).
comp_str(Str1,Str2):-
Str1 = "".
comp_str(Str1,Str2):-
fail.
5
comp_char(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 <> Char2,
Rest2 <> "",
comp_char(Char1,Rest2).
comp_char(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 = Char2.
comp_char(Char1,Str2):-
fail.
Input : No input.
Output : equal
6
Experiment No. : 05
Experiment Name : Write a Prolog program to determine whether a element in a member of list in Artificial
Intelligence.
Objective : To determine whether a element in a member or not in a given list .
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Read the element
Check the element in the list or not
If exist set s to “Found”
Else set s to “Not Found”
Write s
Code :
% PROLOG PROGRAM TO DETERMINE WHETHER A ELEMENT IS A MEMBER OF LIST
% Alamgir, CSE, JUST
list=integer*
findnum(integer,list).
findnum(X,[]):-
write('The number is Not Found in the list.').
findnum(X,[X|Tail]):-
write('The number is Found in the list.').
findnum(X,[Y|Tail]):-
findnum(X,Tail).
Input : findnum(3,[1,2,3,4,5,6,7,8,10,11,12]).
Output : The number is Found in the list.
7
Experiment No. : 06
Experiment Name : Write a Prolog program to find sublists of the given list in Artificial Intelligence.
Objective : To find sublists of the given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Read the sublist
Check the sublist in the list or not
If exist set s to YES
Else set s to Not
Write s
Code :
% Alamgir, CSE, JUST
name = symbol
namelist = name*
predicates
sublist(namelist,namelist)
clauses
sublist([],[]).
sublist([First|Rest],[First|Sub]):-
sublist(Rest,Sub).
sublist([_|Rest],Sub):-
sublist(Rest,Sub).
Input : sublist([a,b,c],X).
Output :
X=["a","b","c"] ;
X=["a","b"] ;
X=["a","c"] ;
X=["a"] ;
X=["b","c"];
X=["b"] ;
X=["c"] ;
X=[]
8
Experiment No. : 07
Experiment Name : Write a prolog program for murder my story in Artificial Intelligence.
Objective : To find the murder of my story.
Software and Tools : GNU-Prolog Console, Notepad++.
Code :
% Alamgir, CSE, JUST
predicates
% pair(symbol,symbol)
iskiller(symbol,symbol)
male(symbol)
female(symbol)
isvictim(symbol)
not_at_bar(symbol,symbol)
not_at_beach(symbol,symbol)
not_alone(symbol)
twin(symbol,symbol)
younger(symbol,symbol)
child(symbol)
clauses
male(husband).
male(brother).
male(son).
female(alice).
female(daughter).
twin(brother,alice).
twin(son,daughter).
child(son).
child(daughter).
not_alone(
not_alone(alice).
not_alone(brother).
not_alone(X):-
9
child(X),child(Y)
not_at_beach(husband,alice).
not_at_beach(son,daughter).
not_at_bar(son,daughter).
not_at_bar(husband,alice).
not_at_bar(X,Y):-
male(X),male(Y).
not_at_bar(X,Y):-
female(X),female(Y).
isvictim(X):-
twin(X,Y),not(iskiller(Y,X)).
isvictim(X):-
twin(Y,X),not(iskiller(Y,X)).
younger(son,alice).
younger(son,husband).
younger(daughter,alice).
younger(daughter,husband).
iskiller(X,Y):-
not(alone(X)),
younger(X,Y),
not(not_at_beach(X,Y)),
not(not_at_bar(X,Y)).
Input : younger(son,alice).
Output : Yes
10
Experiment No. : 08
Experiment Name : Write a prolog program to reverse a list in Artificial Intelligence.
Objective : To reverse a given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for reverse
Set Result to reverse list
Write Result
Code :
% prolog program for reverse a given list------
% Alamgir, CSE, JUST
list([H|T],Result):-
reverselist(T, [H], Result).
reverselist([], Acc, Acc).
reverselist([H|T], Acc, Result):-
reverselist(T, [H|Acc], Result).
Input : list([3,5,6,7,8,12,34,120,22],Result).
Output : Result = [22,120,34,12,8,7,6,5,3]
11
Experiment No. : 09
Experiment Name : Write a prolog program to find the permutation of the given list in Artificial Intelligence.
Objective : To find the permutation of the given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for permutation is permute
Set Result p
Write p
Code :
% Alamgir, CSE, JUST
% PROLOG PROGRAM TO FIND THE PERMUTATION OF THE GIVEN LIST
% domains
list = symbol*
%predicates
permute(list,list).
del(symbol,list,list).
%clauses
del(X,[X|L1],L1).
del(X,[Y|L1],[Y|L2]):-
del(X,L1,L2).
permute([],[]).
permute(L,[X|P]):-
del(X,L,L1),
permute(L1,P).
Input : permute([a,b,c],P).
Output :
P=["a","b","c"];
P=["a","c","b"];
P=["b","a","c"];
P=["b","c","a"];
P=["c","a","b"];
P=["c","b","a"];
12
Experiment No. : 10
Experiment Name : Write a prolog program to find last item of the list in Artificial Intelligence.
Objective : To find the last item of the list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for check element from first to last
Set X to last elemtnt
Write X
Code :
% Last item of a given list.....
% Alamgir, CSE, JUST
namelist = symbol*
lastd(namelist,symbol).
lastd([Head],X):-
X = Head.
lastd([_|Tail],X):-
lastd(Tail,X).
Input : lastd([a,b,c,d,e,f,g,h,I,j,k],X).
Output : X = k
13
Experiment No. : 12
Experiment Name : Write a prolog program to determine the greatest common divisor of two positive integer
numbers in Artificial Intelligence.
Objective : To determine the greatest common divisor of two positive integer numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X,Y
Function gcd (X,Y)
Set Result into X
Write X
Code :
% Prolog program for finding GCD of the two given number
% Alamgir Hossain, CSE, JUST
go:- write('Enter the first number : '),read(X),nl,
write('Enter the second number : '),read(Y),nl,
gcd(X,Y).
gcd(X,Y):-
X=Y,
write('GCD of the two given numbers is : '),write(X);
X=0,write('GCD of the two given numbers is : '),write(Y);
Y=0,write('GCD of the two given numbers is : '),write(X);
Y>X,Y1 is Y-X,gcd(X,Y1);
X>Y,Y1 is X-Y,gcd(Y1,Y).
Input :
go.
Enter the first number : 24.
Enter the second number : 3.
Output : GCD of the two given numbers is : 3
14
Experiment No. : 13
Experiment Name : Write a prolog program that stores information about your family, and will answer queries
about relationships in Artificial Intelligence.
Objective : To stores information about my family, and will answer queries about relationships.
Software and Tools : GNU-Prolog Console, Notepad++.
Code :
% Prolog program that store information about my family
% Alamgir, CSE, JUST
% Facts
father(mosiur, sharmin).
father(mosiur, rawshanara).
father(mosiur, alamgir).
father(mosiur, rahim).
father(auncle, liza).
father(auncle, robin).
father(robin, abid).
father(robin, snigdho).
father(sumon, apu).
mother(morium, sharmin).
mother(morium, alamgir).
mother(morium, rahim).
mother(aunty, liza).
mother(aunty, robin).
mother(sharmin, abid).
mother(sharmin, snigdho).
mother(rawshanara, apu).
% Rules-------
parent(X, Y) :- father(X, Y).
parent(X, Y) :- mother(X, Y).
grandfather(X, Y) :- father(X, Z), parent(Z, Y).
grandmother(X, Y) :- mother(X, Z), parent(Z, Y).
mama(X, Y) :- mother(X, Z), father(Z, Y).
15
huswife(X, Y) :- father(X, Z), mother(Y, Z).
brothersistertr(Y, Z) :- father(X, Y), father(X, Z).
mamavagne(Z, Y) :- father(X, Z),grandfather(X, Y).
Input : parent(X, Y).
Output :
X = mosiur
Y = sharmin ? ;
X = mosiur
Y = rawshanara ? ;
X = mosiur
Y = alamgir ? ;
X = mosiur
Y = rahim ? ;
16
Experiment No. : 14
Experiment Name : Write a prolog program to print a Fibonacci series in Artificial Intelligence.
Objective : To print a Fibonacci series up to n numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read N
Function Fibonacci for the Fibonacci series
Write Result
Code :
% Prolog program for printing fibonacci series upto n numbers------
go:-
write('Enter a number : '),read(N),nl,
write('Fibonacci series for '),write(N),write(' elements is : '),nl,
A is 0,
B is 1,
write(A),write(' '),write(B),write(' '),
fibonacci(N,A,B).
fibonacci(N,A,B):-
(
N<2, write('Complete');
C is A+B,
write(C),write(' , '),
D is B,
E is C,
N1 is N-1, fibonacci(N1,D,E)
).
Input : go.
Enter a number : 10.
Output :
Fibonacci series for 10 elements is :
0 1 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , Complete
17
Experiment No. : 15
Experiment Name : Write a prolog program to calculate the factorial of a number using recursion in Artificial
Intelligence.
Objective : To calculate the factorial of a number using recursion.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read N
Repeat function fact and multiple N by N-1
Set result into F
Write F
Code :
% Alamgir, CSE, JUST
fact(0,1).
fact(N,F):-
(
N>0 ->
(
N1 is N-1,
fact(N1,F1),
F is N*F1
);
write('N should be greater than 0.')
).
Input : fact(8,R).
Output : R = 40320

More Related Content

PPTX
Presentation on Breadth First Search (BFS)
PPTX
Data Collection-Primary & Secondary
PDF
Ai lab manual
PPT
Performance Appraisal ppt [hrm]
PDF
IP Addressing (Subnetting, VLSM, Supernetting)
PDF
Full report on blood bank management system
PPTX
Privacy in simple
PPTX
FCFS scheduling OS
Presentation on Breadth First Search (BFS)
Data Collection-Primary & Secondary
Ai lab manual
Performance Appraisal ppt [hrm]
IP Addressing (Subnetting, VLSM, Supernetting)
Full report on blood bank management system
Privacy in simple
FCFS scheduling OS

What's hot (20)

DOC
Time and space complexity
PPTX
Asymptotic notations
PPT
Time complexity
PPTX
Inductive analytical approaches to learning
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
Data Structure and Algorithm - Divide and Conquer
PDF
Data Visualization in Python
DOCX
Lisp and prolog in artificial intelligence
PPTX
Packages In Python Tutorial
PPTX
heap Sort Algorithm
PPT
Ll(1) Parser in Compilers
PDF
Syntax Directed Definition and its applications
PDF
Ai lecture 7(unit02)
PPTX
Knowledge representation
PPTX
Tcp/ip server sockets
PPTX
Realibity design
PPT
Asymptotic Notation and Complexity
PPTX
Prolog Programming : Basics
PDF
Compiler Design- Machine Independent Optimizations
PPTX
Line Drawing Algorithms - Computer Graphics - Notes
Time and space complexity
Asymptotic notations
Time complexity
Inductive analytical approaches to learning
Algorithms Lecture 2: Analysis of Algorithms I
Data Structure and Algorithm - Divide and Conquer
Data Visualization in Python
Lisp and prolog in artificial intelligence
Packages In Python Tutorial
heap Sort Algorithm
Ll(1) Parser in Compilers
Syntax Directed Definition and its applications
Ai lecture 7(unit02)
Knowledge representation
Tcp/ip server sockets
Realibity design
Asymptotic Notation and Complexity
Prolog Programming : Basics
Compiler Design- Machine Independent Optimizations
Line Drawing Algorithms - Computer Graphics - Notes
Ad

Similar to Lab report for Prolog program in artificial intelligence. (20)

PDF
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
PPTX
Keep it Stupidly Simple Introduce Python
PPTX
Python Workshop - Learn Python the Hard Way
PDF
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
PPTX
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
PDF
Python basic
PDF
Data Handling_XI- All details for cbse board grade 11
PPTX
Python programming workshop
PPTX
Compiler design lab
PPTX
Loops in Python
PDF
python practicals-solution-2019-20-class-xii.pdf
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
ODP
Scala as a Declarative Language
PPTX
Basics of Python programming (part 2)
PDF
Numerical analysis
PDF
Basic C Programming Lab Practice
PDF
Becoming a Pythonist
PDF
paython practical
PPTX
Introduction to learn and Python Interpreter
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
Keep it Stupidly Simple Introduce Python
Python Workshop - Learn Python the Hard Way
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Python basic
Data Handling_XI- All details for cbse board grade 11
Python programming workshop
Compiler design lab
Loops in Python
python practicals-solution-2019-20-class-xii.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
Scala as a Declarative Language
Basics of Python programming (part 2)
Numerical analysis
Basic C Programming Lab Practice
Becoming a Pythonist
paython practical
Introduction to learn and Python Interpreter
Ad

More from Alamgir Hossain (13)

PPTX
How to write a project proposal for software engineering course
PPTX
Malware Detection Approaches using Data Mining Techniques.pptx
PPTX
5 nested if in c with proper example
PPTX
4. decision making and some basic problem
PPTX
3. user input and some basic problem
PPTX
2. introduction of a c program
PPTX
1. importance of c
PDF
Computer graphics lab report with code in cpp
PDF
Report on student-faculty document sharing android project
PDF
A lab report on modeling and simulation with python code
PDF
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
PDF
Digital signal Processing all matlab code with Lab report
PPTX
Microsoft Teams
How to write a project proposal for software engineering course
Malware Detection Approaches using Data Mining Techniques.pptx
5 nested if in c with proper example
4. decision making and some basic problem
3. user input and some basic problem
2. introduction of a c program
1. importance of c
Computer graphics lab report with code in cpp
Report on student-faculty document sharing android project
A lab report on modeling and simulation with python code
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Digital signal Processing all matlab code with Lab report
Microsoft Teams

Recently uploaded (20)

PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Institutional Correction lecture only . . .
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
 
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Business Ethics Teaching Materials for college
PDF
Pre independence Education in Inndia.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
 
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Institutional Correction lecture only . . .
TR - Agricultural Crops Production NC III.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Week 4 Term 3 Study Techniques revisited.pptx
 
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Renaissance Architecture: A Journey from Faith to Humanism
Business Ethics Teaching Materials for college
Pre independence Education in Inndia.pdf
RMMM.pdf make it easy to upload and study
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
 
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
human mycosis Human fungal infections are called human mycosis..pptx
O5-L3 Freight Transport Ops (International) V1.pdf

Lab report for Prolog program in artificial intelligence.

  • 1. 1 Experiment No. : 01 Experiment Name : Write a Prolog program for addition of two numbers in Artificial Intelligence. Objective : To find the summation of two numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X , Y Set S to X+Y Write S Code : % Prolog program for addition of two numbers------------ % Alamgir, CSE, JUST go:- write('Enter first number : '), read(X),nl, write('Enter second number : '), read(Y),nl, sum(X,Y). sum(X,Y):- S is X+Y, write('Summation of the two given number is : '), write(S) Input : go. Enter first number : 100. Enter second number : 200. Output : Summation of the two given number is : 300
  • 2. 2 Experiment No. : 02 Experiment Name : Write a Prolog program for addition & multiplication of two numbers in Artificial Intelligence. Objective : To find the addition & multiplication of two numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X , Y Set S to X+Y Set M to X*Y Write S,M Code : % Prolog program for addition and multplication-------- % Alamgir, CSE, JUST go:- write('Enter first number : '),read(X),nl, write('Enter second number : '),read(Y),nl, addmul(X,Y). addmul(X,Y):- S is X+Y, M is X*Y, write('Addition of the two number is : '),write(S),nl, write('Multiplication of the two number is : '),write(M). Input: go. Enter first number : 20. Enter second number : 10. Output : Addition of the two number is : 30 Multiplication of the two number is : 200
  • 3. 3 Experiment No. : 03 Experiment Name : Write a Prolog program for finding the sum of all numbers in a given list in Artificial Intelligence. Objective : To find the sum of all numbers in a given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read all numbers Add number and set to Result Write Result Code : % Prolog program for find the sum of all numbers in a given list------- % Alamgir, CSE, JUST list([H|T],Result):- listhelper(T,H,Result). listhelper([],Acc,Acc). listhelper([H|T],Acc,Result):- Nacc is H+Acc, listhelper(T,Nacc,Result). Input: list([12,23,4,5,10,23,45],Result). Output : Result = 122
  • 4. 4 Experiment No. : 04 Experiment Name : Write a Prolog program for comparing Character and String in Artificial Intelligence. Objective : To compare character and String. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read two string Compare Strings Write Result Code : % Alamgir, CSE, JUST predicates start comp_str(string,string) comp_char(char,string) goal clearwindow, start. clauses start:- comp_str("abcd","dcab"), write("equal"),nl. start:- write("not equal"),nl. comp_str(Str1,Str2):- Str1 <> "", frontchar(Str1,Char1,Rest1), comp_char(Char1,Str2), comp_str(Rest1,Str2). comp_str(Str1,Str2):- Str1 = "". comp_str(Str1,Str2):- fail.
  • 5. 5 comp_char(Char1,Str2):- frontchar(Str2,Char2,Rest2), Char1 <> Char2, Rest2 <> "", comp_char(Char1,Rest2). comp_char(Char1,Str2):- frontchar(Str2,Char2,Rest2), Char1 = Char2. comp_char(Char1,Str2):- fail. Input : No input. Output : equal
  • 6. 6 Experiment No. : 05 Experiment Name : Write a Prolog program to determine whether a element in a member of list in Artificial Intelligence. Objective : To determine whether a element in a member or not in a given list . Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Read the element Check the element in the list or not If exist set s to “Found” Else set s to “Not Found” Write s Code : % PROLOG PROGRAM TO DETERMINE WHETHER A ELEMENT IS A MEMBER OF LIST % Alamgir, CSE, JUST list=integer* findnum(integer,list). findnum(X,[]):- write('The number is Not Found in the list.'). findnum(X,[X|Tail]):- write('The number is Found in the list.'). findnum(X,[Y|Tail]):- findnum(X,Tail). Input : findnum(3,[1,2,3,4,5,6,7,8,10,11,12]). Output : The number is Found in the list.
  • 7. 7 Experiment No. : 06 Experiment Name : Write a Prolog program to find sublists of the given list in Artificial Intelligence. Objective : To find sublists of the given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Read the sublist Check the sublist in the list or not If exist set s to YES Else set s to Not Write s Code : % Alamgir, CSE, JUST name = symbol namelist = name* predicates sublist(namelist,namelist) clauses sublist([],[]). sublist([First|Rest],[First|Sub]):- sublist(Rest,Sub). sublist([_|Rest],Sub):- sublist(Rest,Sub). Input : sublist([a,b,c],X). Output : X=["a","b","c"] ; X=["a","b"] ; X=["a","c"] ; X=["a"] ; X=["b","c"]; X=["b"] ; X=["c"] ; X=[]
  • 8. 8 Experiment No. : 07 Experiment Name : Write a prolog program for murder my story in Artificial Intelligence. Objective : To find the murder of my story. Software and Tools : GNU-Prolog Console, Notepad++. Code : % Alamgir, CSE, JUST predicates % pair(symbol,symbol) iskiller(symbol,symbol) male(symbol) female(symbol) isvictim(symbol) not_at_bar(symbol,symbol) not_at_beach(symbol,symbol) not_alone(symbol) twin(symbol,symbol) younger(symbol,symbol) child(symbol) clauses male(husband). male(brother). male(son). female(alice). female(daughter). twin(brother,alice). twin(son,daughter). child(son). child(daughter). not_alone( not_alone(alice). not_alone(brother). not_alone(X):-
  • 10. 10 Experiment No. : 08 Experiment Name : Write a prolog program to reverse a list in Artificial Intelligence. Objective : To reverse a given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for reverse Set Result to reverse list Write Result Code : % prolog program for reverse a given list------ % Alamgir, CSE, JUST list([H|T],Result):- reverselist(T, [H], Result). reverselist([], Acc, Acc). reverselist([H|T], Acc, Result):- reverselist(T, [H|Acc], Result). Input : list([3,5,6,7,8,12,34,120,22],Result). Output : Result = [22,120,34,12,8,7,6,5,3]
  • 11. 11 Experiment No. : 09 Experiment Name : Write a prolog program to find the permutation of the given list in Artificial Intelligence. Objective : To find the permutation of the given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for permutation is permute Set Result p Write p Code : % Alamgir, CSE, JUST % PROLOG PROGRAM TO FIND THE PERMUTATION OF THE GIVEN LIST % domains list = symbol* %predicates permute(list,list). del(symbol,list,list). %clauses del(X,[X|L1],L1). del(X,[Y|L1],[Y|L2]):- del(X,L1,L2). permute([],[]). permute(L,[X|P]):- del(X,L,L1), permute(L1,P). Input : permute([a,b,c],P). Output : P=["a","b","c"]; P=["a","c","b"]; P=["b","a","c"]; P=["b","c","a"]; P=["c","a","b"]; P=["c","b","a"];
  • 12. 12 Experiment No. : 10 Experiment Name : Write a prolog program to find last item of the list in Artificial Intelligence. Objective : To find the last item of the list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for check element from first to last Set X to last elemtnt Write X Code : % Last item of a given list..... % Alamgir, CSE, JUST namelist = symbol* lastd(namelist,symbol). lastd([Head],X):- X = Head. lastd([_|Tail],X):- lastd(Tail,X). Input : lastd([a,b,c,d,e,f,g,h,I,j,k],X). Output : X = k
  • 13. 13 Experiment No. : 12 Experiment Name : Write a prolog program to determine the greatest common divisor of two positive integer numbers in Artificial Intelligence. Objective : To determine the greatest common divisor of two positive integer numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X,Y Function gcd (X,Y) Set Result into X Write X Code : % Prolog program for finding GCD of the two given number % Alamgir Hossain, CSE, JUST go:- write('Enter the first number : '),read(X),nl, write('Enter the second number : '),read(Y),nl, gcd(X,Y). gcd(X,Y):- X=Y, write('GCD of the two given numbers is : '),write(X); X=0,write('GCD of the two given numbers is : '),write(Y); Y=0,write('GCD of the two given numbers is : '),write(X); Y>X,Y1 is Y-X,gcd(X,Y1); X>Y,Y1 is X-Y,gcd(Y1,Y). Input : go. Enter the first number : 24. Enter the second number : 3. Output : GCD of the two given numbers is : 3
  • 14. 14 Experiment No. : 13 Experiment Name : Write a prolog program that stores information about your family, and will answer queries about relationships in Artificial Intelligence. Objective : To stores information about my family, and will answer queries about relationships. Software and Tools : GNU-Prolog Console, Notepad++. Code : % Prolog program that store information about my family % Alamgir, CSE, JUST % Facts father(mosiur, sharmin). father(mosiur, rawshanara). father(mosiur, alamgir). father(mosiur, rahim). father(auncle, liza). father(auncle, robin). father(robin, abid). father(robin, snigdho). father(sumon, apu). mother(morium, sharmin). mother(morium, alamgir). mother(morium, rahim). mother(aunty, liza). mother(aunty, robin). mother(sharmin, abid). mother(sharmin, snigdho). mother(rawshanara, apu). % Rules------- parent(X, Y) :- father(X, Y). parent(X, Y) :- mother(X, Y). grandfather(X, Y) :- father(X, Z), parent(Z, Y). grandmother(X, Y) :- mother(X, Z), parent(Z, Y). mama(X, Y) :- mother(X, Z), father(Z, Y).
  • 15. 15 huswife(X, Y) :- father(X, Z), mother(Y, Z). brothersistertr(Y, Z) :- father(X, Y), father(X, Z). mamavagne(Z, Y) :- father(X, Z),grandfather(X, Y). Input : parent(X, Y). Output : X = mosiur Y = sharmin ? ; X = mosiur Y = rawshanara ? ; X = mosiur Y = alamgir ? ; X = mosiur Y = rahim ? ;
  • 16. 16 Experiment No. : 14 Experiment Name : Write a prolog program to print a Fibonacci series in Artificial Intelligence. Objective : To print a Fibonacci series up to n numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read N Function Fibonacci for the Fibonacci series Write Result Code : % Prolog program for printing fibonacci series upto n numbers------ go:- write('Enter a number : '),read(N),nl, write('Fibonacci series for '),write(N),write(' elements is : '),nl, A is 0, B is 1, write(A),write(' '),write(B),write(' '), fibonacci(N,A,B). fibonacci(N,A,B):- ( N<2, write('Complete'); C is A+B, write(C),write(' , '), D is B, E is C, N1 is N-1, fibonacci(N1,D,E) ). Input : go. Enter a number : 10. Output : Fibonacci series for 10 elements is : 0 1 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , Complete
  • 17. 17 Experiment No. : 15 Experiment Name : Write a prolog program to calculate the factorial of a number using recursion in Artificial Intelligence. Objective : To calculate the factorial of a number using recursion. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read N Repeat function fact and multiple N by N-1 Set result into F Write F Code : % Alamgir, CSE, JUST fact(0,1). fact(N,F):- ( N>0 -> ( N1 is N-1, fact(N1,F1), F is N*F1 ); write('N should be greater than 0.') ). Input : fact(8,R). Output : R = 40320