CSC151 2007S, Class 06: Numeric Values Admin: * No Emily on Tuesdays; be patient. * Due: HW 3 * Did you get the subtle hint? * For some reason, every semester I forget to write the following: If you want to ask a question on a homework, please put the word QUESTION or HELP in the subject of the email. If I just get an email like "HW3" or "Exam 1", I assume that you're submitting it. * Homework 4 is now ready. It is due on Friday. * Two readings for Wednesday: Characters in Scheme and Strings in Scheme. Overview: * Types. * Review of Reading: Numbers, Kinds of Numbers, and Numeric Operations. * Lab. * Reflection. /Types/ * Observation: Scheme thinks of each value as being in a particular "type" or "kind" * Scheme limits the values on which you can use operations (+ (list 1 2 3) (list 4 45 6)) * You will therefore need to do the same. * Current goal: Learn about the kinds of values that exist and the available operations. /Numbers/ * You can do "anything" (any common numerical operations) with numbers in Scheme * +, -, *, / ... * sin cos tan * ... * Scheme has lots of different kinds of numbers * Complex, integer * And you can ask Scheeme to tell you about what kind you have * Scheme has exact and inexact numbers * Irrational numbers cannot be represented exactly. * Scheme simulates such numbers as rational numbers. * You can conserve computer memory by using an inexact representation for a rational number. * Scheme can convert using exact->inexact and inexact->exact * We can compare numbers with <, <=, =, >, >=, (and !=) * Test whether an equation we've written works correctly. * When we learn how to do conditionals, we can use these in those conditionals. /Lab Q&A/ * Can we combine queries? (list (complex? x) (< 0 x )) * Also (and (complex? x) (< 0 x)) Gives you #t if all are true Gives you false if any are false (or (complex? x) (< 0 x)) Gives you #t if any are true Gives you false if all are false * Modulo ... A different way of counting * In typical arithmetic, we count up and up and up and up * In some systems, we have a cap. Suppose we know no number larger than 5. We might say 0 1 2 3 4 5 MANY * In modulo arithmetic, we start again at 0 once we've reached the cap. Suppose we know no number larger than 5 (our modulo is then 6), we count 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 ... /Reflection/ * Why did I have you explore the various named procedures in this way? * To help you understand the subtle differences between these procedures. * Sometimes you need to read the documentation. * Documentation usually sucks. * Sometimes you need to learn by tinkering. * You need to think broadly about tinkering. * round * How many parameters? 1 * What types? real number (not complex) * What does it do? rounds to a nearby whole number. * (round 9/2) * (round 11/2) * 4 6 * 5 6 * 5 5 * 4 5 * remainder * How many parameters? * What types? * What if a parameter is negative? (remainder 10 -3) (remainder -10 3) * modulo * How does it differ from remainder? * max * How many parameters? * What types? * lcm * How many parameters? * What types?