Lecture 10 Notes

# Denition 1 example of a top down denition a non

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: values it is legal for the procedure to return. Deﬁnition 1 (Example of a Top-Down Deﬁnition) 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 deﬁnition leads to a test:   A 9E§  ©¨¥ §   C A D9B§  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 deﬁnition. To determine whether n S, we ﬁrst 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 ﬁrst 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 deﬁnition of S: Deﬁnition 2 (Example of a Bottom-Up Deﬁnition) Deﬁne the...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online