Fundamentals of CS I (CS151 2001S)

[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
**Primary**

[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
**Sets**

[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
**Links**

- Exercises
- Exercise 0: Preparation
- Exercise 1: Types of Numbers
- Exercise 2: The Type of a Square Root
- Exercise 3: More Types of Numbers
- Exercise 4: A Large Number
- Exercise 5: Inexact Roots
- Exercise 6: Inexact Fractions
- Exercise 7: Other Integer Procedures
- Exercise 8: Exploring Rationals
- Exercise 9: Rounding, Revisited
- Exercise 10: Other Numeric Predicates

- Notes

You may want to refer to the reading on numbers before or while you work on this lab.

Start DrScheme.

Have DrScheme confirm 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.

Confirm that the value DrScheme computes for `(sqrt 2)`

is an
inexact real that is also rational.

As you've just seen, some kinds of numbers are subsets of other kinds of numbers. Determine the relationships between the various kinds of numbers.

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

a. Have DrScheme find the square of the square root of 2 and subtract 2 from the result.

b. Ideally, the difference should be 0; why isn't it?

c. How big is the difference?

d. Will you have the same problem if you start with 4? Why or why not?

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

Scheme provides a number of numerical procedues that can
produce integer results.
We've already explored
`expt`

,
`abs`

,
`+`

,
`-`

, and
`*`

.

Here are some others. For each, try to figure (by experimentation, by discussing results with other students, and, eventually, by reading documentation) out how many parameters each procedure can take and what the procedure does. You may not be able to figure all of them out. Make sure to try a variety of values for each procedure, including positive and negative, integer and real.

a. `quotient`

b. `remainder`

c. `modulo`

d. `max`

e. `min`

f. `numerator`

g. `denominator`

h. `gcd`

i. `lcm`

j. `floor`

k. `ceiling`

l. `truncate`

m. `round`

Since you've found that DrScheme seems to represent every real number as a rational, it might be worth finding a way to see what that rational number is. Determine the numerator and denominator of the rational representation of the square root of 2.

For small numbers, the
`exact->inexact`

procedure produces about six digits after the decimal point. Figure out how
to get just two digits after the decimal point. You may need to use
multiplication, division, and some of the last procedures from the
previous exercise.

You need not implement your algorithm; simply come up with one you think will work.

We've already seen a variety of predicates (procedures that return
true or false) that can be applied to numbers. These predicates
include
`exact?`

,
`integer?`

, and
`real?`

.

By reading the Scheme documentation, identify other predicates that can be applied to numbers.

When you get stuck on this problem, it's probably worth skimming through
DrScheme's *Help Desk*. The numerical operations are documented
in section 6.2.5 of the Revised(5) Report on the Algorithmic Language
Scheme.

Wednesday, 31 January 2001 [Samuel A. Rebelsky]

- Created. Problems 1-6 were taken from an earlier laboratory on basic types. Problems 7-10 are new.

[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
**Primary**

[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
**Sets**

[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
**Links**

**Disclaimer**:
I usually create these pages on the fly. This means that they
are rarely proofread and may contain bad grammar and incorrect details.
It also means that I may update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Thu May 3 23:07:55 2001.

This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/numbers.html`

.

You may validate
this page's HTML.

The source was last modified Wed Jan 31 08:31:20 2001.