Numbers

Exercise 1

Confirm, using DrScheme, that 3/4 is a rational number but not an integer and that the square root of -1 is a complex number but not a real number.

Exercise 2

Confirm that the value DrScheme computes for (sqrt 2) is an inexact real number that is also rational.

Exercise 3

Develop a predicate natural-number? that takes one argument, which might be anything, and determines whether that argument is an exact non-negative integer. Begin, as usual, by writing out sample calls -- you'll need at least six.

Exercise 4

Write a Scheme numeral for 1.507 times ten to the fifteenth power, as an exact number. Have DrScheme evaluate the numeral.

Exercise 5

Have DrScheme compute the square of the square root of 2 and subtract 2 from the result. Ideally, the difference should be 0; why isn't it? How big is the difference?

Exercise 6

Write a Scheme numeral for one-third, as an inexact number. Have DrScheme evaluate the numeral.

Exercise 7

Use Scheme to find the reciprocal of 3/5.

Exercise 8

Develop a Scheme procedure log10 that takes any positive real number as argument and returns an approximation to its common (base ten) logarithm, computing it by the method suggested in the reading. Use your procedure to confirm that the common logarithm of one million is 6.

Exercise 9

Develop a Scheme procedure named != that takes two numbers as arguments and determines whether they are unequal. Here are a couple of sample calls:

> (!= 4/7 8/14)
#f
> (!= -1 1)
#t

Exercise 10

Contemporary arithmetic textbooks are full of tedious-looking exercises like ``Find the smallest number that is an exact multiple of 1732, 680, and 2520.'' Scheme has primitive gcd (``greatest common divisor'' and lcm (``least common multiple'') procedures for such computations.

Have DrScheme find the smallest number that is an exact multiple of 1732, 680, and 2520.

Exercise 11

Once around the circle is an angle of 360 degrees or, equivalently, 2pi radians. Develop a Scheme procedure degrees->radians that takes the measure of an angle in degrees and converts it to radians (by multiplying or dividing by an appropriate conversion factor).

Note: Since pi is irrational, the value of a call to this procedure is almost always an approximation rather than an exact value. You'll probably find, however, that (degrees->radians 0) is exactly 0.

Exercise 12

Scheme doesn't provide a cotangent procedure cot. Develop one, using the fact that the cotangent of a number is the reciprocal of its tangent. Hint: This procedure has a nontrivial precondition.

Exercise 13

An integer m evenly divides an integer n if the remainder left over when n is divided by m is zero. Define a Scheme predicate evenly-divides? that takes two arguments, both assumed to be integers (and the second assumed to be non-zero), and returns #t if the first evenly divides the second and #f if it does not.


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~stone/courses/scheme/labs/numbers.xhtml

created September 4, 1997
last revised August 8, 2001

John David Stone (stone@cs.grinnell.edu)