All published worksheets from http://sagenb.org
Image: ubuntu2004
Lab 1: Representing real numbers
Principles:
-
aid the students in doing hand computations,
-
check their answers,
-
visualize their answers,
-
help them generalize to world-size problems
This means that our number above actually represented a whole range of numbers. The range of numbers between 1.0 and the next number above it is related to the machine epsilon, which is used in a number of contexts to understand how precise a machine can be and estimate roundoff errors.
A finite system
Let's imagine we have a 2-bit mantissa and a 2-bit exponent. Then all of our machine numbers look like , where and can each be or , and can be .
Question: List all possible numbers in our set.
Answer: (double-click to edit)
or as fractions
The distribution of these numbers is interesting. Let's plot them on the real line.
Note that the numbers are unevenly spaced. In fact, count how many numbers are in , and how many are in , and between . What do you notice? Is there a pattern, and why?
Answer:
Note that there is no machine number representing 1.1. In order to deal with machine arithmetic, the machine needs to decide how to represent 1.1. We notate the machine's version of 1.1 as ( stands for "float", as in "floating point approximation").
What are the reasonable possibilities for ? What would you choose, and why?
Answer:
The gap around zero is called the "hole at zero". Where does this come from? (Subnormal numbers fill this gap in IEEE 754-2008.)
Answer:
What happens if we do on the machine? In other words, what is ?
Answer:
What is ?
Answer:
What is , as the machine does it? (first write down all applicable , then calculate the result.)
Answer:
Rounding Modes
Look up in Wikipedia what the possible rounding modes are for IEEE 754-2008. For each of these rounding modes, what is ? (To answer this for some of the rounding modes, you'll need to know what the mantissas for 3 and 3.5 are.)
Answer:
Relative Error
What is the relative error of the approximation and 1.1? (See the definition from last class or at the bottom of p. 19 of the text.)
Answer:
What is the maximum relative error for a number such that ? This relative error is called the machine epsilon, and is often denoted with the Greek epsilon or .
Answer:
What is the maximum relative error for a number such that ?
Answer:
What about the maximum relative error for a number such that ?
Answer:
Do you notice a pattern? What about the maximum relative error for a number such that ?
Answer:
What is the machine epsilon for a 53-bit number? (Work it out by hand, from what you know about the exponent range, and verify the next computation.)
So intuitively, what does it mean if you do several computations using 53-bit precision floating point numbers (i.e., double precision) and the results differ by about , or if you get an answer that is about ?
You can read about two disasters in history coming from ignoring numerical issues here: http://www.ima.umn.edu/~arnold/455.f96/disasters.html