SlideShare a Scribd company logo
2
Most read
3
Most read
4
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)
Shuvongkor Barman
 
PPTX
Data Collection-Primary & Secondary
Prathamesh Parab
 
PPTX
Cloud Computing Fundamentals
Sonia Nagpal
 
PPTX
First Come First Serve & Shortest Job First-(FCFS & SJF)
Adeel Rasheed
 
PPT
Collection Framework in java
CPD INDIA
 
PPTX
Electronic Payment System
Dattatreya Reddy Peram
 
PPTX
Lecture 1 overview of the construction industry
JB Juanzon Builders Inc.
 
PPTX
ProLog (Artificial Intelligence) Introduction
wahab khan
 
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
 
Data Collection-Primary & Secondary
Prathamesh Parab
 
Cloud Computing Fundamentals
Sonia Nagpal
 
First Come First Serve & Shortest Job First-(FCFS & SJF)
Adeel Rasheed
 
Collection Framework in java
CPD INDIA
 
Electronic Payment System
Dattatreya Reddy Peram
 
Lecture 1 overview of the construction industry
JB Juanzon Builders Inc.
 
ProLog (Artificial Intelligence) Introduction
wahab khan
 

What's hot (20)

PPTX
Syntax-Directed Translation into Three Address Code
sanchi29
 
DOCX
DAA Lab File C Programs
Kandarp Tiwari
 
PPT
Code Optimization
guest9f8315
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
PPT
AI Lecture 7 (uncertainty)
Tajim Md. Niamat Ullah Akhund
 
PDF
Computer graphics lab report with code in cpp
Alamgir Hossain
 
PPTX
Problem solving agents
Megha Sharma
 
PDF
A* Search Algorithm
vikas dhakane
 
PPTX
N queen problem
Ridhima Chowdhury
 
PPTX
Regular expressions
Ratnakar Mikkili
 
PPTX
4.6 halting problem
Sampath Kumar S
 
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
PPTX
Context free grammar
Mohammad Ilyas Malik
 
PPT
Ll(1) Parser in Compilers
Mahbubur Rahman
 
PPT
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
PPTX
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
PPTX
Output primitives in Computer Graphics
Kamal Acharya
 
PDF
State Space Representation and Search
Hitesh Mohapatra
 
PPTX
And or graph
Ali A Jalil
 
PPTX
Asymptotic notations
Nikhil Sharma
 
Syntax-Directed Translation into Three Address Code
sanchi29
 
DAA Lab File C Programs
Kandarp Tiwari
 
Code Optimization
guest9f8315
 
heap Sort Algorithm
Lemia Algmri
 
AI Lecture 7 (uncertainty)
Tajim Md. Niamat Ullah Akhund
 
Computer graphics lab report with code in cpp
Alamgir Hossain
 
Problem solving agents
Megha Sharma
 
A* Search Algorithm
vikas dhakane
 
N queen problem
Ridhima Chowdhury
 
Regular expressions
Ratnakar Mikkili
 
4.6 halting problem
Sampath Kumar S
 
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Context free grammar
Mohammad Ilyas Malik
 
Ll(1) Parser in Compilers
Mahbubur Rahman
 
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
Output primitives in Computer Graphics
Kamal Acharya
 
State Space Representation and Search
Hitesh Mohapatra
 
And or graph
Ali A Jalil
 
Asymptotic notations
Nikhil Sharma
 
Ad

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

PDF
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
anuragupadhyay0537
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
PDF
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
PPTX
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
PDF
Python basic
Saifuddin Kaijar
 
PPTX
Python programming workshop
BAINIDA
 
PPTX
Compiler design lab
ilias ahmed
 
PPTX
Loops in Python
Arockia Abins
 
PDF
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
ODP
Scala as a Declarative Language
vsssuresh
 
PPTX
Basics of Python programming (part 2)
Pedro Rodrigues
 
PDF
Numerical analysis
Vishal Singh
 
PDF
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
PDF
Becoming a Pythonist
Raji Engg
 
PDF
paython practical
Upadhyayjanki
 
PPTX
Introduction to learn and Python Interpreter
Alamelu
 
DOCX
Mouse programming in c
gkgaur1987
 
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
anuragupadhyay0537
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Python basic
Saifuddin Kaijar
 
Python programming workshop
BAINIDA
 
Compiler design lab
ilias ahmed
 
Loops in Python
Arockia Abins
 
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
Scala as a Declarative Language
vsssuresh
 
Basics of Python programming (part 2)
Pedro Rodrigues
 
Numerical analysis
Vishal Singh
 
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
Becoming a Pythonist
Raji Engg
 
paython practical
Upadhyayjanki
 
Introduction to learn and Python Interpreter
Alamelu
 
Mouse programming in c
gkgaur1987
 
Ad

More from Alamgir Hossain (12)

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

Recently uploaded (20)

PDF
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
CDH. pptx
AneetaSharma15
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
CDH. pptx
AneetaSharma15
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 

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