1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 14 School of Innovation, Design and Engineering Mälardalen University 2012.

Slides:



Advertisements
Similar presentations
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
Advertisements

1. An Overview of Prolog.
Primitive Recursive Functions (Chapter 3)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
The Recursion Theorem Sipser – pages Self replication Living things are machines Living things can self-reproduce Machines cannot self reproduce.
Elementary Number Theory and Methods of Proof
February 19, 2015Applied Discrete Mathematics Week 4: Number Theory 1 The Growth of Functions Question: If f(x) is O(x 2 ), is it also O(x 3 )? Yes. x.
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Other Models of Computation. 2 Models of computation: Turing Machines Recursive Functions Post Systems Rewriting Systems.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Discrete Mathematics Recursion and Sequences
September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 1 Macros Now we want to use macros of the form: W  f(V 1, …,
Fundamentals of Python: From First Programs Through Data Structures
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
2.4 Sequences and Summations
INTRODUCTION TO THE THEORY OF COMPUTATION INTRODUCTION MICHAEL SIPSER, SECOND EDITION 1.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
Analysis of Algorithms
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
Great Theoretical Ideas in Computer Science for Some.
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14 Mälardalen University 2006.
Algorithm Design.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
1/32 This Lecture Substitution model An example using the substitution model Designing recursive procedures Designing iterative procedures Proving that.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14 Mälardalen University 2010.
1 Other Models of Computation Costas Busch - LSU.
Computability Go over homework problems. Godel numbering. Homework: prepare for midterm.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
CS 154 Formal Languages and Computability May 5 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
CS 550 Programming Languages Jeremy Johnson
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Francisco Antonio Doria
Analysis of Algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
CS 326 Programming Languages, Concepts and Implementation
Polynomial + Fast Fourier Transform
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Lecture 7 Functions.
Other Models of Computation
Algorithm design and Analysis
The Metacircular Evaluator
Functional Programming
This Lecture Substitution model
Extended Introduction to Computer Science
Applied Discrete Mathematics Week 9: Integer Properties
Streams, Delayed Evaluation and a Normal Order Interpreter
Formal Languages, Automata and Models of Computation
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Recursion Taken from notes by Dr. Neil Moore
Chapter 3: Selection Structures: Making Decisions
This Lecture Substitution model
6.001 SICP Interpretation Parts of an interpreter
Introduction to the Lab
This Lecture Substitution model
Recursive Functions.
Presentation transcript:

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 14 School of Innovation, Design and Engineering Mälardalen University 2012

2 Content Recursive Functions Primitive Recursion Ackermann function &  -recursive functions Relations Among Function Classes

3 Recursion In computer programming, recursion is related to performing computations in a loop.

Visualisation of a recursive structure 4 A Sierpinksi carpet is a famous fractal objects in mathematics. Creating one is an iterative procedure. Start with a square, divide it into nine equal squares and remove the central one. That leaves eight squares around a central square hole. In the next iteration, repeat this process with each of the eight remaining squares and so on (see above).

5 Recursion used in Problem Modelling Reducing the complexity by Breaking up computational sequence into its simplest forms. Synthesizing components into more complex objects by replicating simple component sequences over and over again.

6 "A reduction is a way of converting one problem into another problem in such a way that a solution to the second problem can be used to solve the first problem." Michael Sipser, Introduction to the Theory of Computation

7 Self-referential definitions can be dangerous if we're not careful to avoid circularity. This is why our definition of recursion includes the word well-defined. (Recursion can be seen as a concept of well-defined self- reference.) *Gertrude Stein: ''A rose is a rose is a rose''

8 We can write a pseudocode to determine whether somebody is an immigrant: FUNCTION isAnImmigrant(person): IF person immigrated herself, THEN: return true ELSE: return isAnImmigrant(person's parent) END IF This is a recursive function, since it uses itself to compute its own value. Recursive definition: an immigrant…

9 Functions From math classes, we have seen many ways of defining and combining numerical functions. Inverse Composition Derivatives Iteration (iterated function is composed with itself) …. etc.

10 Functions Look at what happens when we use only some of these. - How can we define standard interesting functions? - How do these relate to e.g. TM computations? We have seen TMs as functions. They are awkward! As alternative, look at a more intuitive definition of functions.

11 Notation For brevity, we will limit ourselves to functions on natural numbers Notation will also use n-tuples of numbers

12 Natural Numbers Start with standard recursive definition of natural numbers (Peano axioms) A natural number is either 0 or successor(n), where n is a natural number.

13 What is a recurrence? A recurrence is a well-defined mathematical function written in terms of itself. It is a mathematical function defined recursively.

14 Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,... The first two numbers of the sequence are both 1, while each following number is the sum of the two numbers before it. (We arrived at 55 as the tenth number, since it is the sum of 21 and 34, the eighth and ninth numbers.)

15 F is called a recurrence, since it is defined in terms of itself evaluated at other values.

16 A recursive process is one in which objects are defined in terms of other objects of the same type. Using some sort of recurrence relation*, the entire class of objects can then be built up from a few initial values and a small number of rules. Recursion & Recurrence (*Recurrence is a mathematical function defined recursively.)

17 Computable Functions Any computable function can be programmed using while-loops (i.e., "while something is true, do something else"). For-loops (which have a fixed iteration limit) are a special case of while-loops. (Computable functions could of course also be coded using a combination of for- and while-loops. )

18 Total Function A function defined for all possible input values. Primitive Recursive Function A function which can be implemented using only for- loops.

19 An example function DomainRange

20 Building functions from basic ones Based on C Busch, RPI, Models of Computation

21 Zero function: Successor function: Projection functions: Basic Primitive Recursive Functions

22 Building functions Composition

23 Composition, Generally Given

24 Primitive Recursion “Template” For primitive recursive functions recursion is in only one argument.

25 Any function built from the basic primitive recursive functions is called Primitive Recursive Function.

26 Basic Primitive Zero function (a constant function) Example

27 Basic Primitive Identity function Recursive definition

28 Basic Primitive Successor function

29 Using Basic Primitive Zero function and a Successor function we can construct Constant functions etc..

30 Example

31 A Primitive Recursive Function (projection) (successor function)

32 Example

33 Example

34 Basic Primitive Predecessor function

35 Predecessor Predecessor is a primitive recursive function with no direct self-reference.

36 Subtraction

37 Example

38 Multiplication

39 Example

40 A Primitive Recursive Function,exponentiation

41 Example

42 Primitive Recursion in Logic A predicate (Boolean function) with output in the set {0,1} which is interpreted as {yes, no}, can be used to define standard functions. –Logical connectives , , , , … –Numeric comparisons=, <, , … –Bounded existential quantification  i  n, f(i) –Bounded universal quantification  i  n, f(i) –Bounded minimizationmin i i  n, f(i) where result = 0 if f(i) never true within bounds.

43 Recursive Predicates and

44 More Recursive Predicates

45 More Recursive Predicates...

46 Example Recursive predicates can combine into powerful functions. What does this compute? Tests primality! A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

47 Function

48 our construction primitive recursive template

49 Division example: x/4

50 Division as Primitive Recursion

51 Division example: x/4

52 Division as Primitive Recursion

53 Recursive Predicate

54 Recursive Predicate

55 Theorem The set of primitive recursive functions is countable. Proof Each primitive recursive function can be encoded as a string. Enumerate all strings in proper order. Check if a string is a function.

56 There is a function that is not primitive recursive. Proof ( by Cantor diagonal argument ) Enumerate the primitive recursive functions Theorem

57 Define function differs from every is not primitive recursive END OF PROOF

58 A specific function that is not primitive recursive: Ackermann’s function: Grows very fast, faster than any primitive recursive function

59 The Ackermann function is the simplest example of a well defined total function which is computable but not primitive recursive, providing a counterexample to the belief in the early 1900s that every computable function was also primitive recursive.

60 Recursive Functions Ackermann’s function is a Recursive Function

61 Primitive recursive functions Recursive Functions

62 Primitive Recursion: Extended Example Needs following building blocks: –constants –addition –multiplication –exponentiation –subtraction A polynomial function:

63 Addition add(0,n)= add(m+1,n)= n succ(add(m,n)) Multiplication: mult(0,n)= mult(m+1,n)= 0 add(mult(m,n),n)

64 Exponentiation: exp(0,n)= exp(m+1,n)= 1 mult(exp(m,n),n) = one(n) Subtraction sub(0,n)= sub(m+1,n)= 0=zero(n) succ(sub(m,n))

65 Primitive Recursion: Extended Example f = sub ◦ (add ◦ (f 1,f 2 ), f 3 ) f 1 (x,y) = mult(3,exp(7,x))f 1 = mult ◦ (three, exp ◦ (seven)) f 2 (x,y) = mult(x,y)f 2 = mult f 3 (x,y) = mult(7,exp(2,y))f 3 = mult ◦ (seven, exp ◦ (two)) f(x,y) = sub(add(f 1 (x,y),f 2 (x,y)),f 3 (x,y))

66 Primitive Recursion All primitive recursive functions are total. i.e., they are defined for all values. Primitive recursion lack some interesting functions: “True” subtraction– when using natural numbers. “True” division– undefined when divisor is 0. Trigonometric functions– undefined for some values. …

67 Partial Recursive vs. Recursive A function is partial recursive  it can be defined by the previous constructions. A function is recursive  it is partial recursive and total.

68 Division: div(m,n) =  m  n  div(m,n) = min i, sub(succ(m),add(mult(i,n),n)) = 0 div(m,n) = minimum i such that i  mni  mn i  n  m-(n-1) i  n+n  m+1 (m+1) – (i  n+n)  0 (m+1)  (i  n+n) = 0 Example

69 Relations Among Function Classes Functions  TMs –Define TMs in terms of the function formers. –Straightforward, but long. TMs  Functions –Define functions where subcomputations encode TM behavior. –Simple encoding scheme. –Straightforward, but very messy. partial recursive = recognizable recursive = decidable primitive recursive

70 Additional Examples of Primitive Recursion A recursive function is a function that calls itself by using its own name within its function body. Even

71 Factorials

72 Is a number a square? Forward recursion (  -recursion)

73

74