SlideShare a Scribd company logo
4
Most read
5
Most read
7
Most read
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 first 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

PPT
Code Optimization
PPTX
3D Graphics : Computer Graphics Fundamentals
PDF
Software Engineering Past Papers (Short Questions)
PDF
Differences between c and c++
PDF
SOFTWARE PROJECT PLANNING on Software Engineering
PPTX
AI Programming language (LISP)
PPTX
Presentation on C++ Programming Language
PPTX
Semantic nets in artificial intelligence
Code Optimization
3D Graphics : Computer Graphics Fundamentals
Software Engineering Past Papers (Short Questions)
Differences between c and c++
SOFTWARE PROJECT PLANNING on Software Engineering
AI Programming language (LISP)
Presentation on C++ Programming Language
Semantic nets in artificial intelligence

What's hot (20)

PDF
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
PPTX
Asymptotic Notations
PPTX
Knowledge representation and Predicate logic
PPT
lecture1 introduction to computer graphics(Computer graphics tutorials)
PPTX
Introduction to python for Beginners
PPTX
Hidden surface removal
PPTX
Context free grammar
PPTX
CATHODE RAY TUBE IN COMPUTER GRAPHICS
PPTX
PPTX
Planning in Artificial Intelligence
PPTX
FLOW OF CONTROL-NESTED IFS IN PYTHON
PPTX
Introduction to Basics of Python
PPT
Bresenham's line algo.
PPT
Fundamentals of Computer Design including performance measurements & quantita...
PPT
1.python interpreter and interactive mode
PPTX
Asymptotic notations
PDF
Introduction to ai
PPTX
Dempster shafer theory
PDF
Planning Agent
PPTX
3. planning in situational calculas
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Asymptotic Notations
Knowledge representation and Predicate logic
lecture1 introduction to computer graphics(Computer graphics tutorials)
Introduction to python for Beginners
Hidden surface removal
Context free grammar
CATHODE RAY TUBE IN COMPUTER GRAPHICS
Planning in Artificial Intelligence
FLOW OF CONTROL-NESTED IFS IN PYTHON
Introduction to Basics of Python
Bresenham's line algo.
Fundamentals of Computer Design including performance measurements & quantita...
1.python interpreter and interactive mode
Asymptotic notations
Introduction to ai
Dempster shafer theory
Planning Agent
3. planning in situational calculas
Ad

Similar to List manipulation (20)

PPTX
PROLOG: Recursion And Lists In Prolog
PPTX
PROLOG: Recursion And Lists In Prolog
PPTX
Prolog -Cpt114 - Week3
DOCX
AI Lab Manual.docx
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPTX
Prolog 7-Languages
PPTX
Prolog: Arithmetic Operations In Prolog
PPTX
PROLOG: Arithmetic Operations In Prolog
PPT
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
PPT
Section3 Prologppt
PPTX
PROLOG: Introduction To Prolog
ODP
Scala as a Declarative Language
DOCX
List & Tuple questions with seperate questions
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
Prolog -Cpt114 - Week3
AI Lab Manual.docx
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog 7-Languages
Prolog: Arithmetic Operations In Prolog
PROLOG: Arithmetic Operations In Prolog
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
Section3 Prologppt
PROLOG: Introduction To Prolog
Scala as a Declarative Language
List & Tuple questions with seperate questions
Ad

More from chauhankapil (20)

PPTX
Gray level transformation
PPTX
Elements of visual perception
PPTX
JSP Client Request
PPTX
Jsp server response
PPTX
Markov decision process
PPTX
RNN basics in deep learning
PPTX
Introduction to generative adversarial networks (GANs)
PPTX
Bayesian probabilistic interference
PPTX
PPTX
Exception handling in java
PPTX
Knowledge acquistion
PPTX
Knowledge based system
PPTX
Introduction of predicate logics
PPTX
Types of inheritance in java
PPTX
Representation of syntax, semantics and Predicate logics
PPTX
Inheritance in java
PPTX
Propositional logic
PPTX
Constructors in java
PPTX
Methods in java
PPT
Circular linked list
Gray level transformation
Elements of visual perception
JSP Client Request
Jsp server response
Markov decision process
RNN basics in deep learning
Introduction to generative adversarial networks (GANs)
Bayesian probabilistic interference
Exception handling in java
Knowledge acquistion
Knowledge based system
Introduction of predicate logics
Types of inheritance in java
Representation of syntax, semantics and Predicate logics
Inheritance in java
Propositional logic
Constructors in java
Methods in java
Circular linked list

Recently uploaded (20)

PPTX
Software Engineering and software moduleing
PPTX
introduction to high performance computing
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
Artificial Intelligence
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPT
Total quality management ppt for engineering students
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
communication and presentation skills 01
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
Software Engineering and software moduleing
introduction to high performance computing
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Safety Seminar civil to be ensured for safe working.
Information Storage and Retrieval Techniques Unit III
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Management Information system : MIS-e-Business Systems.pptx
Artificial Intelligence
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
III.4.1.2_The_Space_Environment.p pdffdf
R24 SURVEYING LAB MANUAL for civil enggi
Total quality management ppt for engineering students
Categorization of Factors Affecting Classification Algorithms Selection
communication and presentation skills 01
distributed database system" (DDBS) is often used to refer to both the distri...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Exploratory_Data_Analysis_Fundamentals.pdf

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 first 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