SlideShare a Scribd company logo
1 of 9
Recursion Basic ,List
Manipulation and Function
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
contents
๏‚— Recursion Introduction
๏‚— List
๏‚— List manipulation
๏‚— List manipulation Example
๏‚— Functions
๏‚— Functions example
Recursion Introduction
๏‚— The recursion in any language is a function that can call
itself until the goal has been succeed.
๏‚— The best way in Prolog to calculate a factorial is to do it
recursivelly. Here is an example of how it can be done :
๏‚— factoriel(0,1).
๏‚— factoriel(X,Y)
๏‚— :- X1 is X - 1,
๏‚— factoriel(X1,Z),
๏‚— Y is Z*X,!.
after the first solution. Now if you enter :
?- factoriel(5,X).
X = 120
Yes
list
๏‚— we have only considered simple items as arguments
to our programs.
๏‚— [first,second,third] = [A|B]
๏‚— where A = first and B=[second,third]
๏‚— List is one of the most important data structure in
Prolog.
๏‚— Here are some example simple lists
[a,b,c,d,e,f,g]
[apple,pear,bananas,breadfruit]
๏‚— Consider the following fact.
?- p([a,b,c], X, Y).
๏‚— X=a
๏‚— Y=[b,c]
๏‚— yes
list manipulation
๏‚— The ๏ฌrst element of a list is called its head and the
remaining list is called the tail.
๏‚— An empty list doesnโ€™t have a head.
๏‚— A list just containing a single element has a head
๏‚— [Nepal | [India, Bhutan, Sri Lanka, Maldives,
Pakistan, Bangladesh]]
๏‚— Nepal is head and remaining countries constitute tail
and this is represented as
output
?- sky([1,2,3,4,5,6],X).
X = [1, 3, 5, 2, 6, 4] ;
false.
?- sky([1,2,3,4,5,6,7,8,9],X).
X = [1, 3, 5, 7, 9, 2, 6, 4, 8] ;
false.
functions
๏‚— Defining four functions (itโ€™s called predicates in prolog),
addition, subtraction, multiplication, and division.
๏‚— Each of them takes three parameters, the result is saved to
the third parameter.
๏‚— Functions are normal Prolog predicates.
๏‚— Some predicates are already predefined when you start your
Prolog system. These are called built-in predicates or
simply built-ins.
Functions example
addition(A, B, C):- C is A + B.
subtraction(A, B, C):- C is A - B.
multiplication(A, B, C):- C is A * B.
division(A, B, C):- C is A / B.
?- addition(2,3,X).
X = 5.
?- subtraction(4,2,X).
X = 2.
?- multiplication(3,4,K).
K = 12.
?- division(9, 3, D).
D = 3.
Assignment
๏‚— Explain List and function manipulation in prolog with
example

More Related Content

What's hot

Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
ย 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
ย 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternativesPooja Dixit
ย 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
ย 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mountingrajshreemuthiah
ย 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
ย 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
ย 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandasPiyush rai
ย 
System calls
System callsSystem calls
System callsBernard Senam
ย 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
ย 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CPrabu U
ย 
Process scheduling
Process schedulingProcess scheduling
Process schedulingRiya Choudhary
ย 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python pptPriyanka Pradhan
ย 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
ย 
[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOPMuhammad Hammad Waseem
ย 

What's hot (20)

Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
ย 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
ย 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
ย 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
ย 
NUMPY
NUMPY NUMPY
NUMPY
ย 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
ย 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mounting
ย 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
ย 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
ย 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
ย 
System calls
System callsSystem calls
System calls
ย 
Python OOPs
Python OOPsPython OOPs
Python OOPs
ย 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
ย 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
ย 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
ย 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
ย 
Queue ppt
Queue pptQueue ppt
Queue ppt
ย 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
ย 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
ย 
[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
ย 

Similar to List manipulation

Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with pythonPorimol Chandro
ย 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6Amba Research
ย 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Hamidreza Soleimani
ย 
Lesson 18
Lesson 18Lesson 18
Lesson 18Avijit Kumar
ย 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
ย 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in rmanikanta361
ย 
Erlang
ErlangErlang
ErlangBalaji G
ย 
R workshop
R workshopR workshop
R workshopRevanth19921
ย 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4Syed Farjad Zia Zaidi
ย 
List comprehensions
List comprehensionsList comprehensions
List comprehensionsJordi Gรณmez
ย 
final report.doc
final report.docfinal report.doc
final report.docbutest
ย 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searchingmondalakash2012
ย 

Similar to List manipulation (20)

Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with python
ย 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
ย 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
ย 
Lesson 18
Lesson 18Lesson 18
Lesson 18
ย 
AI Lesson 18
AI Lesson 18AI Lesson 18
AI Lesson 18
ย 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
ย 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
ย 
Erlang
ErlangErlang
Erlang
ย 
Data structures
Data structures Data structures
Data structures
ย 
Dr iterate
Dr iterateDr iterate
Dr iterate
ย 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
ย 
Mean, median, mode
Mean, median, mode Mean, median, mode
Mean, median, mode
ย 
binary search
binary searchbinary search
binary search
ย 
R workshop
R workshopR workshop
R workshop
ย 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4
ย 
List comprehensions
List comprehensionsList comprehensions
List comprehensions
ย 
final report.doc
final report.docfinal report.doc
final report.doc
ย 
Mean, median, mode 1
Mean, median, mode 1Mean, median, mode 1
Mean, median, mode 1
ย 
sort search in C
 sort search in C  sort search in C
sort search in C
ย 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
ย 

More from chauhankapil

Gray level transformation
Gray level transformationGray level transformation
Gray level transformationchauhankapil
ย 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perceptionchauhankapil
ย 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Requestchauhankapil
ย 
Jsp server response
Jsp   server responseJsp   server response
Jsp server responsechauhankapil
ย 
Markov decision process
Markov decision processMarkov decision process
Markov decision processchauhankapil
ย 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learningchauhankapil
ย 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)chauhankapil
ย 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interferencechauhankapil
ย 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javachauhankapil
ย 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistionchauhankapil
ย 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based systemchauhankapil
ย 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logicschauhankapil
ย 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in javachauhankapil
ย 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicschauhankapil
ย 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javachauhankapil
ย 
Propositional logic
Propositional logicPropositional logic
Propositional logicchauhankapil
ย 
Constructors in java
Constructors in javaConstructors in java
Constructors in javachauhankapil
ย 
Methods in java
Methods in javaMethods in java
Methods in javachauhankapil
ย 
Circular linked list
Circular linked listCircular linked list
Circular linked listchauhankapil
ย 

More from chauhankapil (20)

Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
ย 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
ย 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Request
ย 
Jsp server response
Jsp   server responseJsp   server response
Jsp server response
ย 
Markov decision process
Markov decision processMarkov decision process
Markov decision process
ย 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learning
ย 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)
ย 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interference
ย 
Jsp
JspJsp
Jsp
ย 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
ย 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistion
ย 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based system
ย 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logics
ย 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in java
ย 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
ย 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
ย 
Propositional logic
Propositional logicPropositional logic
Propositional logic
ย 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
ย 
Methods in java
Methods in javaMethods in java
Methods in java
ย 
Circular linked list
Circular linked listCircular linked list
Circular linked list
ย 

Recently uploaded

Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
ย 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
ย 
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night StandCall Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Standamitlee9823
ย 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
ย 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
ย 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
ย 
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoordharasingh5698
ย 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7Call Girls in Nagpur High Profile Call Girls
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
ย 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
ย 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
ย 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
ย 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
ย 

Recently uploaded (20)

Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
ย 
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night StandCall Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
ย 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
ย 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
ย 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
ย 
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor ๐Ÿ“ฑ {7001035870} VIP Escorts chittoor
ย 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
ย 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
ย 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
ย 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
ย 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
ย 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
ย 

List manipulation

  • 1. Recursion Basic ,List Manipulation and Function Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. contents ๏‚— Recursion Introduction ๏‚— List ๏‚— List manipulation ๏‚— List manipulation Example ๏‚— Functions ๏‚— Functions example
  • 3. Recursion Introduction ๏‚— The recursion in any language is a function that can call itself until the goal has been succeed. ๏‚— The best way in Prolog to calculate a factorial is to do it recursivelly. Here is an example of how it can be done : ๏‚— factoriel(0,1). ๏‚— factoriel(X,Y) ๏‚— :- X1 is X - 1, ๏‚— factoriel(X1,Z), ๏‚— Y is Z*X,!. after the first solution. Now if you enter : ?- factoriel(5,X). X = 120 Yes
  • 4. list ๏‚— we have only considered simple items as arguments to our programs. ๏‚— [first,second,third] = [A|B] ๏‚— where A = first and B=[second,third] ๏‚— List is one of the most important data structure in Prolog. ๏‚— Here are some example simple lists [a,b,c,d,e,f,g] [apple,pear,bananas,breadfruit] ๏‚— Consider the following fact. ?- p([a,b,c], X, Y). ๏‚— X=a ๏‚— Y=[b,c] ๏‚— yes
  • 5. list manipulation ๏‚— The ๏ฌrst element of a list is called its head and the remaining list is called the tail. ๏‚— An empty list doesnโ€™t have a head. ๏‚— A list just containing a single element has a head ๏‚— [Nepal | [India, Bhutan, Sri Lanka, Maldives, Pakistan, Bangladesh]] ๏‚— Nepal is head and remaining countries constitute tail and this is represented as
  • 6. output ?- sky([1,2,3,4,5,6],X). X = [1, 3, 5, 2, 6, 4] ; false. ?- sky([1,2,3,4,5,6,7,8,9],X). X = [1, 3, 5, 7, 9, 2, 6, 4, 8] ; false.
  • 7. functions ๏‚— Defining four functions (itโ€™s called predicates in prolog), addition, subtraction, multiplication, and division. ๏‚— Each of them takes three parameters, the result is saved to the third parameter. ๏‚— Functions are normal Prolog predicates. ๏‚— Some predicates are already predefined when you start your Prolog system. These are called built-in predicates or simply built-ins.
  • 8. Functions example addition(A, B, C):- C is A + B. subtraction(A, B, C):- C is A - B. multiplication(A, B, C):- C is A * B. division(A, B, C):- C is A / B. ?- addition(2,3,X). X = 5. ?- subtraction(4,2,X). X = 2. ?- multiplication(3,4,K). K = 12. ?- division(9, 3, D). D = 3.
  • 9. Assignment ๏‚— Explain List and function manipulation in prolog with example