While performing any calculations, our computers will represent any real number using a finite number of binary digits. This yields a limited amount of possible numbers, which are commonly referred to as machine numbers.

Here, we discuss different representations of numbers, and the consequences of these representations with regard to error.

Binary Machine Numbers

While we see numbers in (commonly) decimal form, this is not how machines see them! Below, we discuss how the most common representation of numbers in machines, and potential sources of error they can create.

IEEE Standard 754

The most common representation of numbers in machines is the IEEE Standard 754, the floating point representation of numbers.

Under this standard, a real number will be represented in the following format:

  • denotes the sign of the number, which determines whether is positive or negative.
  • denotes the mantissa, which takes on some value between .
  • denotes the exponent (characteristic), which takes on some positive integer value.
  • denotes the bias, which offsets the exponent value to allow for an (approximately) equivalent number of positive and negative powers of 2.

Note that this standard essentially represents in the base-2 equivalent of the scientific notation we’re used to.

In our machine, the number of bits allocated to represent each part of a number depends on the number of bits allocated for the number (bias is predetermined based off this allocation).

For our purposes, we will assume a 64 bit number, otherwise known as a double. Using this standard, a number would be represented as follows (let represent bits taking on 0 or 1):

Sign ()Exponent ()Mantissa ()

Note we read the binary for the exponent from the right to left, but read the mantissa left to right.

Where the following bit counts (and corresponding values) would be assigned:

Symbol# BitsValue
None
1 Bit or
11 Bits
52 Bits

Note that offsets the exponent to allow an approximately equal number of positive and negative powers of 2.

Error

Note that it’s simply not possible to represent all real numbers with this representation. To this degree, there are “gaps” in the real numbers representable, and the computer will round to the closest real number during floating point arithmetic. This is fine in most use-cases, but creates error, which is discussed later.

Special Numbers

By virtue of the limited number of bits we can use to represent a real number, it’s simply not possible to represent all numbers.

To address this, the machine reserves the exponent values and for special numbers, which represent numbers outside of the representable number range.

  • represents the special number (depending on sign), which is treated as a very small number.
  • represents the special number (depending on sign), which is treated as a very large number.

Note that the smallest possible positive number we can represent is on

so any real number smaller than this is simply given the special number , known as an underflow.

Similarly, the largest possible positive number we can represent is on

so any real number larger than this is simply given the special number , known as an overflow.

There are equivalent underflows and overflows for negative numbers.

Artithmetic with these special number is defined, and follows logical reasoning if we think of these special numbers as very small or very large values.

Don’t think of as , instead think of it as a very small number.

For some calculations that we can’t be sure about, like , the machine assigns the special number NaN (not a number).

Some examples are given below.

Example: Arithmetic with Special Numbers

Decimal Machine Numbers

While computers represent numbers in binary, us humans (more often than not) work with numbers in decimal. This too, however, can create error, which is described below.

Scientific Notation

Any can be represented as

Where . This is often known as scientific notation. We call normalizing the operation of converting a number into its equivalent scientific notation.

Example: Scientific Notation

We can normalize the following numbers as so:

-Digit Normalized Form

Note that it’s often not possible to represent all digits of a number. So, for these numbers, we often approximate them using their -digit normalized floating point decimal form, which limits the number of a number’s digits in the decimal form.

To obtain this form, we either perform:

  • Chopping, where we remove
  • Rounding, where we add 1 to if , and chop.

Example: Chopping vs Rounding

Suppose we have , which is approximately , and let . Then,

  • With chopping, we would represent as .
  • With rounding, we would represent as .

By virtue of removing digits, this chopping / rounding process creates error.

Error

Error Definitions

Due to the infinite number of real numbers possible, error is inevitable. Whether through rounding, or imprecision in instruments, we will (in many cases) obtain numbers that only approximate the actual value.

Below, we discuss the various types of error and their implications. Let be approximated by . Then, the error, absolute error, and relative error are defined as follows:

We will use the notation to denote the relative error of .

Note that the relative error acts as a sort of normalization on the error value, which can be used to compare errors with one another.

Let be an integer. If we can bound our relative error at or under the value ,

We say that approximates to significant digits.

Error can be really handy in analyzing algorithms / operations! See the below example.

Example: Error in Chopping and Rounding

Recall the chopping operation from decimal machine numbers.

If we chop for -digits on the normalized number , we will obtain the result . Let’s find the relative error of this operation.

We know that as the number was normalized, , and . So, our relative error with chopping is

Thus, if we chop on any normalized number, our relative error will be at most .

Similarly, we can show that with rounding, we find a relative error less than .

Machine Epsilon

The machine epsilon, denoted , is the smallest machine number which, when added to 1, does not give 1.

Formally, its the smallest machine number such that

For our 64-bit representation, we can find our machine epsilon as .

An interesting property of the machine epsilon is that for any , the relative error produced by its representation on the machine is less than the machine epsilon. Thus, the machine epsilon essentially serves as a “measure” of how close we can represent numbers on a machine.

Error Propagation

Condition Numbers

Consider a map where , which could represent some sort of operation on .

If has an error, and is approximated by such that its relative error is , then what is the relative error in the result (denoted )?

We find this relative error. Assume is a close approximation of . Then,

As shown above, the resultant relative error in can be found in terms of the relative error in , where the coefficient is called the condition number of at , .

The condition number tells us the degree in which ‘s relative error increased / decreased as a result of the function, and thus provides a good measure in which an error will propagate as a result of a function.

  • If , the function doesn’t create a major change in ‘s relative error, and we say the function is well conditioned.
  • If , the function greatly increases ‘s relative error in , and we say that the funciton is ill-conditioned.

See the below examples, where we use the condition number for analysis.

Example: Well Conditioned Function

Suppose . We find its condition number for as

Because the condition number is 1 for all , we say that is well conditioned for all , as for all the relative error in the output is approximately equal to the relative error in the input .

Propagation in Multiplication / Division

Let’s consider error propagation for the standard multiplication and division operations: and . As both cases are similar, we will only perform analyiss on .

Suppose we have the product , where and are approximated by and (respectively). What is the relative error created by this operation?

Let be this relative error.

We found an upper bound for our error, .

Given that and are reasonably small (we have good approximations of and ), this simplifies to a bound of . In other words, the error after taking the product of and is the sum of their errors, which is perfectly reasonable!

Propagation in Addition

Let’s now consider error propagation with regard to addition and subtraction: and . Just like before, we will only show analysis for , as follows similarly.

Suppose we take the sum , where and are approximated by and (respectively). What is the relative error created by this operation?

Let be this relative error.

Like before, we’ve found a bound for our error. Unlike before, however, we see that our error now depends on our choices of and !

Let’s do a case analysis on the various chioces of and .

  1. Case 1: Consider the case where and have the same sign. Then, because

    We have a weighted sum of and ! So, our error is bound under .

  2. Case 2: Consider the case where and have opposite signs and different magnitudes. Our coefficients sum yield a value close to 1, so we have a similar case as before!

  3. Case 3: Consider the case where and have opposite signs and similar magnitudes.

    This means that , which would cause our coefficients to tend towards infinity! This would cause our relative error to skyrocket.

We can see from the case analysis that when and have different signs but similar magnitudes, our addition becomes unstable. In fact, this is a well known phenomenom known as subtractive (catastrophic) cancellation, where the cancellation of 2 similar numbers creates lots of error!

Subtractive cancellation is often one of the main sources of errors in algorithms.

Machine Algorithms

Consider a function . Say this function is represented on a machine by .

Some functions, like the trigonometric functions, are approximted on a machine using Taylor series.

Then, given an input , the machine does the following to obtain an output:

  1. Conversion to Machine Number: First, the number needs to be representable on a machine, so the machine approximates it with its closest machine number. This operation has maximum error .
  2. Function Calculation: Then, the number is passed through the function approximation . This operation (ideally) has error equal to the function’s condition number, .
  3. Conversion to Machine Number: Finally, the result needs to be converted back into the closest machine number! This operation, like step (1), has maximum error .

The reason why we have to convert in step (3), is because operations will often temporarily allocate more bits to numbers for precision, which are removed after the operation.

Let be our approximation of , after conversion to a machine number. Then, this entire process would give us the error

This is known as unavoidable error, because even if our function is represented perfectly, the nature of number representation and error propagation will always create this error.

However, in practice, the function approximations aren’t always perfect! Instead, the function approximation typically yields some scaling constant , giving us error

We say our function (algorithm) is numerically stable if is not very large, meaning we do not create much error apart from the unavoidable error.

See the below example.