Download
recursive functions n.
Skip this Video
Loading SlideShow in 5 Seconds..
Recursive Functions PowerPoint Presentation
Download Presentation
Recursive Functions

Recursive Functions

342 Views Download Presentation
Download Presentation

Recursive Functions

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Recursive Functions

  2. Outline • Introduction • Primitive Recursive Models • Definition • Examples • Incomplete and Complete Models • Ackermann’s Function • μ-Recursive Functions • Conclusion

  3. Introduction • A recursive function is one that calls upon itself to determine the solution • Fibonacci Numbers • F(0) = 1, F(1) = 1 • F(n+1) = F(n) + F(n-1) for all n > 0 • Can be utilized to resolve many problems (in fact, μ-Recursion is as powerful as a Turing Machine) • Gödel developed general notion of recursive functions • Made no claims on their strength, however

  4. Primitive Recursion • First level of recursive functions • Is an algorithm, has a finite number of steps to it • Relies on simple axioms to build other functions • Can be written very formally or informally • Starting out there are no negative numbers • We will define subtraction less than zero to be zero • Term was said to be coined by Rózsa Péter.

  5. Defined functions • Constant Function - Ca(x1,…,xn) = a • No matter what the arguments, always return a • Identity Function - Iin (x1,…,xn) = xi • Given argument X1 through Xn, return Xi • A projection function • Successor Function – S(x) = x+1 • Advance the argument x by 1

  6. Function Rules • Composition - F(x1,…,xn) = G(H1(x1,…,xn), … , Hk(x1,…,xn)) • A function can be defined as some function G acting on a composition of functions H1 to Hk. All carry the same input • Iteration – The main Primitive Recursion Rule F(0, x1,…,xn) = G(x1,…,xn) F(y+1, x1,…,xn) = H(y, x1,…,xn, F(y, x1,…,xn)) • Give a starting rule to the function F(0,x1,….xn) • Create a rule of y+1 that may act on input y • Think back to Fibonacci definition

  7. Formal Example, Addition (y+x) • +(0,y) = I11 (y) • 0+y = y, our basic rule • +(x+1,y) = H(x,y,+(x,y)) • Where H(a,b,c) = S(I33 (a,b,c)) • =S(C) = S(+(x,y) )= x+y+1 • Basically +(x+1,y) is the function x+y incremented by 1

  8. Informal example, Addition • Add(0,x) = x • Add(n+1,x) = add(n,x)+1 • Much easier to understand, but not proper to the language • Some teachings had it the other way around to get a handle on how to formalize a function

  9. Subtraction (y-x) • Informal Example: • Pred(0) = 0 • Pred(n+1) = n //Like S function • Sub(0,y) = y • Sub(x+1,y) = pred(Sub(x,y)) • Formal Example: • Pred(0) = C0(0) • Pred(n+1) = I12 (n,pred(n)) • Sub(0,y) = I11 (y) • Sub(x+1,y) = pred(I33 (x,y,sub(x,y))

  10. Last Formal Example, Multiplication (x * y) • Basically, multiplication of (x+1)*y is the same as the multiplication of x*y + y • 5 * 3 = 4 * 3 + 3 • *(0,y) = C0(Y) • *(x+1,y) = +(I33(x,y,*(x,y)) , I23(x,y,*(x,y)))

  11. More Functionality • X!: • 0! = 1 • (X+1)! = (x + 1) * x! • X == 0 • [0 == 0] = 1 • [(X+1) == 0] = 0 • X == Y • [X == Y] = [(X – Y) + (Y – X) == 0] • X <= Y • [X <= Y] = [(X – Y) == 0] • ~X • ~X = 1-X or (X == 0) • All conditional statements are defined in the notes

  12. Bounded Minimization • A step toward the μ-Recursive Functions. • Defines a new operator to add to the list, μz where z is under some bounds. • Formal Definition: f(x) = m z (z ≤ x) [ P(z) ] if  such a z, = x+1, otherwise Can show f is primitive recursive by: f(0) = 1-P(0) f(x+1) = f(x) if f(x) ≤ x = x+2-P(x+1) otherwise • For some primitive recursive function P(z), find the minimal z that satisfies the function or return x+1 if the boundary is passed. • Also can define a z < x in the same fashion, it returns x instead of x+1 if there does not exist a z.

  13. Examples • x // y: Whole Number Division rounded up • x // 0 = 0 • x // (y+1) = mz (z < x) [(z+1)*(y+1) > x] • X | Y: X is a divisor of Y • x | y = ((y // x) * x) == y • Because we round up, x is only a divisor of y if it equals itself in the division causing it to cancel out leaving only y • FirstFactor(x): Return first factor of x > 1 • FirstFactor(x) = mz ( 2 <= z <= x) [ z | x] or 0 if none • IsPrime(x) • isPrime(x) = FirstFactor(x) == x && (x > 1) • Pi :Prime(i) • Prime(0) = 2 • Prime(x+1) = mz (prime(x) < z <= prime(x)!+1) [ isPrime(z)]

  14. Some Useful Functions • X^Y: • x^0 = 1 • x^(y+1) = x * x^y • Exp(x,i): The exponent of Pi in x • Exp(x,i) = mz (z < x) [ ~(Pi^(z+1) | x)] • Find the minimal exponent of Pi that is not a divisor of X

  15. An Encoding Function • pair(x,y) = <x,y> = 2x (2y + 1) – 1 • This can be inversed to pull out X (<z>2)and Y (<z>1) <z>1 = exp(z+1,0) <z>2 = ((( z + 1 ) // 2 <z>1 ) – 1 ) // 2 • Numbers can be stacked in this method <x,y,z> = <x,<y,z>> • With this stack, numbers can be popped off forming memory <2,3> = 2^2 * (2*3 + 1) – 1 = 27 <27>1 = exp(28,0) = ~(2^3 | 28) = Returns 3 <27>2 = ((28 // 2^3) – 1) // 2 = (4-1) // 2 = 3 // 2 = Returns 2

  16. Primitive Recursion is not complete • A variation on Cantor’s diagonal argument shows there are more computable functions than primitive recursive functions. • Take a matrix of the computably numerated primitive recursive functions on the rows and all natural numbers as the columns. • The value at i,j is the primitive recursive function i acting on input j. Fi(j) • Consider the diagonal function g(x) = S(fx(X)) that goes through the diagonal of this table and adds one. • This function is “computable (by the above), but clearly no primitive recursive function exists which computes it as it differs from each possible primitive recursive function by at least one value”.

  17. Ackermann’s Function • This is an example of a recursive function that is not primitive recursive. • It grows too fast for a for loop. “For example A(4,2) contains 19,729 decimal digits” A(x,y) = y + 1 if x = 0 A(x,y) = A(x-1,1) if y = 0 A(x,y) = A(x-1,A(x,y-1)) Otherwise

  18. μ-Recursive Functions • A complete model, defines the unbounded minimization • Same as μz but with no bounding conditions after it • In the event that the function halts on the input, a z is returned • Otherwise, z continues forever and the function never halts • F(x) = μz (1 == 0) will never halt • This can handle Ackermann’s Function and recursive functions beyond primitive recursion

  19. Conclusion • With the μ-Recursive functions, a complete system has been built • This is shown later as all systems are reduced to all others • This functionality has resulted in some interesting programming languages and very powerful algorithms.