# Class 09: Computing with Symbols and Numbers

This outline is also available in PDF.

Held: Tuesday, 5 February 2008

Summary: We explore some of Scheme's standard numeric functions.

Related Pages:

Notes:

Overview:

• Types.
• Kinds of Numbers.
• Key Numeric Operations.

## Types

• As you may have noted in your first experiments with Scheme, Scheme assigns types to variables.
• For example, a value might be a number, or a string, or an image identifier, or a procedure, or a drawing, or ....
• Computer scientists often think of types in two different ways:
• Data-driven: A type is a set of values.
• Purpose-driven: A type provides information on the valid operations that may be applied to a piece of data.
• We will alternate between the two definitions.
• Many languages (particularly the ones you've reported being familiar with) require you to assign a type to a variable when you declare that variable.
• Scheme does not require you to assign types ot variables; it checks the type of each operand when it executes a procedure.
• Scheme also provides procedures that let you determine the type of a value.
• As the semester progresses, you will learn new types.

## Scheme's Numeric Types

• Instead of a general numbers type, Scheme provides a variety of kinds of numbers.
• Integers are numbers without a fractional component.
• Rational numbers can be expressed as the ratio of two integers.
• Real numbers appear somewhere on the number line.
• In mathematics, real numbers can be rational or irrational.
• In Scheme, real numbers are all rational.
• Complex numbers may include an imaginary component.
• Our version of Scheme does not support complex numbers, but we mention them anyway.
• You can (almost) always use an integer when a real is expected, but you cannot always use
• Scheme also represents some numbers exactly and some numbers inexactly. (That is, it approximates some numbers.)
• It certainly has to approximate irrational numbers.
• But it also approximates many other numbers.
• It may surprise you to see which numbers are represented inexactly. (We'll return to this issue later.)
• Some important numeric predicates (procedures that return true or false): number?, real?, integer?, exact?, and inexact?.

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

This document was generated by Siteweaver on Tue Apr 15 23:11:34 2008.
The source to the document was last modified on Thu Jan 17 16:44:12 2008.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2008S/Outlines/outline.09.html.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu