General Recursive DefinitionsRecursively Defined SetsBoolean ExpressionsStrings Not Containing the Substring 11The MIU SystemSlide 6Slide 7The MU PuzzleSlide 9Slide 10Slide 11Arithmetic ExpressionsSlide 13Slide 14Pointer ArithmeticSlide 16Slide 17Slide 18Recursively Defined FunctionsSlide 20Slide 21The Ackermann FunctionSlide 23Slide 24Slide 25Slide 26Slide 27General Recursive DefinitionsLecture 37Section 8.4Fri, Mar 25, 2005Recursively Defined SetsThe definition of a recursively defined set consists of three parts.Base – Specific objects are in the set.Recursion – Rules describing how to form new members from other members.Restriction – No other elements are in the set.Boolean ExpressionsDefine Boolean expressions as follows.Base – Each lowercase letter of the alphabet represents a Boolean expression and T and F are Boolean expressions.Recursion – If p and q are Boolean expressions, then so are p q, p q, p and (p).Restriction – There are no other Boolean expressions.Strings Not Containing the Substring 11Define a set of strings as follows.Base – , 0, and 1 are in the set.Recursion – If s is in the set, then so is 0s and 10s.Restriction – No other strings are in the set.The set consists of all strings that do not contain the substring 11.The MIU SystemDefine the strings in the MIU system as follows.Base – MI is in the MIU system.The MIU SystemRecursion•If xI is in the MIU system, then so is xIU.•If Mx is in the MIU system, then so is Mxx.•If xIIIy is in the MIU system, then so is xUy.•If xUUy is in the MIU system, then so is xUy.Restriction – There are no other strings in the MIU system.The MIU SystemDerive a few strings in the MIU system.MI MIUMI MII MIIII MUIMI MII MIIII MIIIIIIII MUIIIII MUUII MUIIThe MU PuzzleIs MU in the MIU system?The MU PuzzleLet n be the number of I’s in a string in the MIU system.If we apply Rule 1, then the resulting string still contains n I’s.If we apply Rule 2, then the resulting string contains 2n I’s.If we apply Rule 3, then the resulting string contains n – 3 I’s.If we apply Rule 4, then the resulting string still contains n I’s.The MU PuzzleInitially, n is 1.Only Rules 2 and 3 change the number of I’s.Thus, the following changes are possible.n 2n.n n – 3.The MU PuzzleThe first change will map A multiple of 3 to a multiple of 3, and A non-multiple of 3 to a non-multiple of 3.The second change will also map A multiple of 3 to a multiple of 3, and A non-multiple of 3 to a non-multiple of 3.Given that n = 1 in the initial string and 1 is not a multiple of 3, it is impossible to eliminate I from the strings.Arithmetic ExpressionsDefine a set of arithmetic expressions as follows.Base – Any number is an arithmetic expression.Arithmetic ExpressionsRecursion – If x and y are arithmetic expressions, then so are•x + y•x – y•x * y•x / y•(x)Restriction – There are no other arithmetic expressions.Arithmetic ExpressionsDerive the arithmetic expression(2 + 3) * (10 / 2 – 4)Pointer ArithmeticPointer- and integer-valued expressions may be defined recursively.BaseAny letter may represent a pointer-valued expression.Any letter may represent an integer-valued expression.Pointer ArithmeticRecursion – Let p and q be pointer-valued expressions and i and j be integer-valued expressions.i + j is an integer-valued expression.i – j is an integer-valued expressionp – q is an integer-valued expression.(i) is an integer-valued expression.Pointer Arithmeticp + i is a pointer-valued expression.p – i is a pointer-valued expression.(p) is a pointer-valued expression.Restriction – No other expressions are in the set.Pointer ArithmeticWhich expressions are legal expressions?Which are integer-valued and which are pointer-valued?p + (q + i)(p + q) + i(p – q) + i(p – q) + (r – s)(p + i) – (q – j)(p – (q – j)) + i(p – q) + (j + i)Recursively Defined FunctionsMathematical functions may be defined recursively.The classic example is the factorial function:0! = 1,n! = n (n – 1)! for all n 1.Recursively Defined FunctionsGiven the “successor” functionsucc(n) = n + 1,addition of nonnegative integers may be defined recursively.•sum(0, 0) = 0,•sum(m, 0) = succ(sum(m – 1, 0)) for all m 1,•sum(m, n) = succ(sum(m, n – 1)) for all n 1.Recursively Defined FunctionsGiven the sum() function just defined, how could we define multiplication of nonnegative integers?prod(m, n) = ?The Ackermann FunctionDefine the Ackermann functionA : Znonneg Znonneg Z+byA(0, n) = n + 1, n 0.A(m, 0) = A(m – 1, 1), m > 0.A(m, n) = A(m – 1, A(m, n – 1)), m > 0, n > 0.The Ackermann FunctionA(0, 0) = 1.A(0, 1) = 2.A(0, 2) = 3.A(0, 3) = 4.In general, A(0, n) = n + 1.The Ackermann FunctionA(1, 0) = A(0, 1) = 2.A(1, 1) = A(0, A(1, 0)) = A(0, 2) = 3.A(1, 2) = A(0, A(1, 1)) = A(0, 3) = 4.A(1, 3) = A(0, A(1, 2)) = A(0, 4) = 5.In general, A(1, n) = n + 2.The Ackermann FunctionA(2, 0) = A(1, 1) = 3.A(2, 1) = A(1, A(2, 0)) = A(1, 3) = 5.A(2, 2) = A(1, A(2, 1)) = A(1, 5) = 7.A(2, 3) = A(1, A(2, 2)) = A(1, 7) = 9.In general, A(2, n) = 2n + 3.The Ackermann FunctionA(3, 0) = A(2, 1) = 5.A(3, 1) = A(2, A(3, 0)) = A(2, 5) = 13.A(3, 2) = A(2, A(3, 1)) = A(2, 13) = 29.A(3, 3) = A(2, A(3, 2)) = A(2, 29) = 61.In general, A(3, n) = 2n + 3 – 3.The Ackermann FunctionA(4, 0) = A(3, 1) = 13.A(4, 1) = A(3, A(4, 0)) = A(3, 13) = 216 – 3= 65533.A(4, 2) = A(3, 65533) = 265533 – 3.A(4, 3) = ?A(4, 4) = ?A(5, 5) =
View Full Document