1 / 27

General Recursive Definitions

General Recursive Definitions. Lecture 37 Section 8.4 Fri, Mar 25, 2005. Recursively Defined Sets. The 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.

luther
Télécharger la présentation

General Recursive Definitions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. General Recursive Definitions Lecture 37 Section 8.4 Fri, Mar 25, 2005

  2. Recursively Defined Sets • The 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.

  3. Boolean Expressions • Define 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.

  4. Strings Not Containing the Substring 11 • Define 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.

  5. The MIU System • Define the strings in the MIU system as follows. • Base – MI is in the MIU system.

  6. The MIU System • Recursion • 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.

  7. The MIU System • Derive a few strings in the MIU system. • MI  MIU • MI  MII  MIIII  MUI • MI  MII  MIIII  MIIIIIIII  MUIIIII  MUUII  MUII

  8. The MU Puzzle • Is MU in the MIU system?

  9. The MU Puzzle • Let 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.

  10. The MU Puzzle • Initially, 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.

  11. The MU Puzzle • The 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.

  12. Arithmetic Expressions • Define a set of arithmetic expressions as follows. • Base – Any number is an arithmetic expression.

  13. Arithmetic Expressions • Recursion – 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.

  14. Arithmetic Expressions • Derive the arithmetic expression (2 + 3) * (10 / 2 – 4)

  15. Pointer Arithmetic • Pointer- and integer-valued expressions may be defined recursively. • Base • Any letter may represent a pointer-valued expression. • Any letter may represent an integer-valued expression.

  16. Pointer Arithmetic • Recursion – 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 expression • p – q is an integer-valued expression. • (i) is an integer-valued expression.

  17. Pointer Arithmetic • p + 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.

  18. Pointer Arithmetic • Which 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)

  19. Recursively Defined Functions • Mathematical functions may be defined recursively. • The classic example is the factorial function: • 0! = 1, • n! = n (n – 1)! for all n  1.

  20. Recursively Defined Functions • Given the “successor” function succ(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.

  21. Recursively Defined Functions • Given the sum() function just defined, how could we define multiplication of nonnegative integers? • prod(m, n) = ?

  22. The Ackermann Function • Define the Ackermann function A : ZnonnegZnonneg Z+ by • A(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.

  23. The Ackermann Function • A(0, 0) = 1. • A(0, 1) = 2. • A(0, 2) = 3. • A(0, 3) = 4. • In general, A(0, n) = n + 1.

  24. The Ackermann Function • A(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.

  25. The Ackermann Function • A(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.

  26. The Ackermann Function • A(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.

  27. The Ackermann Function • A(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) = ?

More Related