recursive

# In general a function f is called recursively defined

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ned Functions One can define recursively defined functions for domains other than the nonnegative integers. In general, a function f is called recursively defined if and only if at least one value f(x) is defined in terms of another value f(y), where x and y are distinct elements. [However, we will typically consider recursively defined functions that have more structure than this definition suggests.] 16 Example 3: Ackermann Function n + 1 A(m, n) = A(m − 1, 1) A(m − 1, A(m, n − 1)) if m = 0, if m &gt; 0 and n = 0, if m &gt; 0 and n &gt; 0 The Ackermann function has particular significance in computability theory. The values of A(m,n) grow very, very quickly. 17 Ackermann Function (Cont.) # In Ruby, the Ackermann function can be defined as follows: def A(m,n) return n+1 if m==0 return A(m-1,1) if n==0 return A(m-1,A(m,n-1)) end # Now try calculating A(0,0), A(1,1), A(2,2), A(3,3), A(4,4) 18 Ackermann Function Example A(0,0) =&gt; 1 A(1,1) =&gt; A(0,A(1,0)) =&gt; A(0,A(0,1)) =&gt; A(0, 2) =&gt; 3 A(2,2) =&gt; A(1,A(2,1)) =&gt; A(1,A(1,A(2,0))) =&gt; A(1,A(1,A(1,1))) =&gt; A (1,A(1,A(0,A(1,0)))) =&gt; A(1,A(1,A(0,A(0,1)))) =&gt; A(1,A(1,A(0,2))) =&gt; A(1,A(1,3)) =&gt; A(1,A(0,A(1,2))) =&gt; A(1,A(0,A(0,A(1,1)))) =&gt; ... =&gt; A (1,A(0,A(0,3))) =&gt; A(1,A(0,4)) =&gt; A(1,5) =&gt; A(0,A(1,4)) =&gt; A(0,A (0,A(1,3))) =&gt; A(0,A(0,A(0,A(1,2)))) =&gt; A(0,A(0,A(0,4))) =&gt; A(0,A (0,5)) =&gt; A(0,6) =&gt; 7 19 Ackermann Function (Cont.) n + 1 A(m, n) = A(m − 1, 1) A(m − 1, A(m, n − 1)) if m = 0, if m &gt; 0 and n = 0, if m &gt; 0 and n &gt; 0 Why does the recursion terminate? Lexicographically order the pairs (m,n). So (m,n) &lt; (m’,n’) iff m&lt;m’ or (m=m’ and n&lt;n’). Note that arguments used in the RHS are lexicographically smaller than the arguments in the LHS. Thus, eventually we need to end up in case m=0, though it might take an extremely long time. 20 Structural Induction 21 Structural Induction Structural induction asserts a property about elements of an inductively defined set. The proof met...
View Full Document

## This note was uploaded on 03/24/2014 for the course CSCE 222 taught by Professor Math during the Fall '11 term at Texas A&M.

Ask a homework question - tutors are online