Interval arithmetic is a technique used to determine upper bounds for the absolute error in an algorithm, properly considering all roundoff errors in the calculation. It is based on the fact that the real number system modelled by a computer is effectively viewed as an interval with machine representable endpoints in which the exact result lies. All real numbers that enter into a numerical calculation, initial, intermediate, and final, are most often unknown. At best, an interval is known that contains the exact answer. Extending the arithmetic operations used in a numerical algorithm to operate on intervals produces intervals that are guaranteed to contain the exact solution. This type of analysis can be readily implemented in Fortran 90 with its support for derived types and generic functions and operators. It also illustrates several advanced numerical manipulation functions new to Fortran 90 that simplify the implementation and increase portability.
In section 1.4, the following module was used to illustrate generic functions applied to a derived type.
module IntervalArithmetic
type interval
real a ! Left endpoint
real b ! Right endpoint
end type interval
interface operator (+)
module procedure addIntervals
end interface
contains
function addIntervals( first, second )
type( interval ) addIntervals
type( interval ), intent( in ) :: first, second
! Numerically, the left and right endpoints of the interval
! sum should be rounded down and up, respectively, to
! ensure that numbers in the two intervals are also in the
! sum. This has been omitted to simplify the example.
addIntervals = interval( first%a + second%a, &
first%b + second%b )
end function addIntervals
end module IntervalArithmetic
As pointed out in the comments preceding the calculation of the interval sum, this implementation is simplistic and could give incorrect results if used in a rounding error analysis. An accurate approach is explained below.
Let M be the set of all machine representable reals and let
denote interval addition. Then, the interval sum,
, must be the smallest interval containing the
exact sums,
and
, with machine representable
endpoints,
and c2. More precisely,
,
where
and the `+' operator represents
exact addition without roundoff or constraints of finite
precision.