Lecture 10 Notes

Denition 1 example of a top down denition a non

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: values it is legal for the procedure to return. Definition 1 (Example of a Top-Down Definition) A non-negative integer n is in S whenever 0, or 3 ¢ ¡ 2. n 1. n S. S is the set of multiples of 3. This definition leads to a test:   A 9E§  ©¨¥ §   C A D9B§  1 !  §  7 8   @ § 9¤¡ # ¤" £¥    6§ 5!  4  § ¡§ £¡ 3©¨¥ ©¨¥ ¤  ¡¤!¥ 21¤¡ 1 ¤)£ ('%¨¥ !¥ § £ ¥ !$" § ©¨¥ "0 # & §  # ! § £ §  ¤¥ ¦¤§¢¨© ¢©¥ §¡ § ©§ ¥§ ¡ ¤¤  "¡¦¡§¥ ¡¨ ¦  ¤ in-S? usage: Here we have written a recursive procedure in Scheme that follows the definition. To determine whether n S, we first ask whether n 0. If it is, then the answer is true. Otherwise we need to see whether n 3 S. To do this, we first check to see whether (n 3) 0. If it is, then we can use our procedure to see whether it is in S. ¢ ¢ ¡ F 5 ¡ Two alternative ways of writing the same definition of S: Definition 2 (Example of a Bottom-Up Definition) Define the...
View Full Document

Ask a homework question - tutors are online