Affine arithmetic

From HandWiki
Revision as of 16:15, 6 February 2024 by John Stpola (talk | contribs) (linkage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Affine arithmetic (AA) is a model for self-validated numerical analysis. In AA, the quantities of interest are represented as affine combinations (affine forms) of certain primitive variables, which stand for sources of uncertainty in the data or approximations made during the computation. Affine arithmetic is meant to be an improvement on interval arithmetic (IA), and is similar to generalized interval arithmetic, first-order Taylor arithmetic, the center-slope model, and ellipsoid calculus — in the sense that it is an automatic method to derive first-order guaranteed approximations to general formulas.

Affine arithmetic is potentially useful in every numeric problem where one needs guaranteed enclosures to smooth functions, such as solving systems of non-linear equations, analyzing dynamical systems, integrating functions, differential equations, etc. Applications include ray tracing, plotting curves, intersecting implicit and parametric surfaces, error analysis (mathematics), process control, worst-case analysis of electric circuits, and more.

Definition

In affine arithmetic, each input or computed quantity x is represented by a formula [math]\displaystyle{ x = x_0 + x_1 \epsilon_1 + x_2 \epsilon_2 + {} }[/math][math]\displaystyle{ \cdots }[/math][math]\displaystyle{ {} + x_n \epsilon_n }[/math] where [math]\displaystyle{ x_0, x_1, x_2, }[/math][math]\displaystyle{ \dots, }[/math][math]\displaystyle{ x_n }[/math] are known floating-point numbers, and [math]\displaystyle{ \epsilon_1, \epsilon_2,\dots,\epsilon_n }[/math] are symbolic variables whose values are only known to lie in the range [-1,+1].

Thus, for example, a quantity X which is known to lie in the range [3,7] can be represented by the affine form [math]\displaystyle{ x = 5 + 2 \epsilon_k }[/math], for some k. Conversely, the form [math]\displaystyle{ x = 10 + 2 \epsilon_3 - 5 \epsilon_8 }[/math] implies that the corresponding quantity X lies in the range [3,17].

The sharing of a symbol [math]\displaystyle{ \epsilon_j }[/math] among two affine forms [math]\displaystyle{ x }[/math], [math]\displaystyle{ y }[/math] implies that the corresponding quantities X, Y are partially dependent, in the sense that their joint range is smaller than the Cartesian product of their separate ranges. For example, if [math]\displaystyle{ x = 10 + 2 \epsilon_3 - 6 \epsilon_8 }[/math] and [math]\displaystyle{ y = 20 + 3 \epsilon_4 + 4 \epsilon_8 }[/math], then the individual ranges of X and Y are [2,18] and [13,27], but the joint range of the pair (X,Y) is the hexagon with corners (2,27), (6,27), (18,19), (18,13), (14,13), (2,21) — which is a proper subset of the rectangle [2,18]×[13,27].

Affine arithmetic operations

Affine forms can be combined with the standard arithmetic operations or elementary functions, to obtain guaranteed approximations to formulas.

Affine operations

For example, given affine forms [math]\displaystyle{ x,y }[/math] for X and Y, one can obtain an affine form [math]\displaystyle{ z }[/math] for Z = X + Y simply by adding the forms — that is, setting [math]\displaystyle{ z_j }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ x_j + y_j }[/math] for every j. Similarly, one can compute an affine form [math]\displaystyle{ z }[/math] for Z = [math]\displaystyle{ \alpha }[/math]X, where [math]\displaystyle{ \alpha }[/math] is a known constant, by setting [math]\displaystyle{ z_j }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ \alpha x_j }[/math] for every j. This generalizes to arbitrary affine operations like Z = [math]\displaystyle{ \alpha }[/math]X + [math]\displaystyle{ \beta }[/math]Y + [math]\displaystyle{ \gamma }[/math].

Non-affine operations

A non-affine operation [math]\displaystyle{ Z }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ F(X,Y, }[/math][math]\displaystyle{ \dots }[/math][math]\displaystyle{ ) }[/math], like multiplication [math]\displaystyle{ Z }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ X Y }[/math] or [math]\displaystyle{ Z }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ \sin(X) }[/math], cannot be performed exactly, since the result would not be an affine form of the [math]\displaystyle{ \epsilon_i }[/math]. In that case, one should take a suitable affine function G that approximates F to first order, in the ranges implied by [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math]; and compute [math]\displaystyle{ z }[/math] [math]\displaystyle{ \gets }[/math] [math]\displaystyle{ G(x,y, }[/math][math]\displaystyle{ \dots }[/math][math]\displaystyle{ ) + z_k\epsilon_k }[/math], where [math]\displaystyle{ z_k }[/math] is an upper bound for the absolute error [math]\displaystyle{ |F-G| }[/math] in that range, and [math]\displaystyle{ \epsilon_k }[/math] is a new symbolic variable not occurring in any previous form.

The form [math]\displaystyle{ z }[/math] then gives a guaranteed enclosure for the quantity Z; moreover, the affine forms [math]\displaystyle{ x,y, }[/math][math]\displaystyle{ \dots }[/math][math]\displaystyle{ ,z }[/math] jointly provide a guaranteed enclosure for the point (X,Y,...,Z), which is often much smaller than the Cartesian product of the ranges of the individual forms.

Chaining operations

Systematic use of this method allows arbitrary computations on given quantities to be replaced by equivalent computations on their affine forms, while preserving first-order correlations between the input and output and guaranteeing the complete enclosure of the joint range. One simply replaces each arithmetic operation or elementary function call in the formula by a call to the corresponding AA library routine.

For smooth functions, the approximation errors made at each step are proportional to the square h2 of the width h of the input intervals. For this reason, affine arithmetic will often yield much tighter bounds than standard interval arithmetic (whose errors are proportional to h).

Roundoff errors

In order to provide guaranteed enclosure, affine arithmetic operations must account for the roundoff errors in the computation of the resulting coefficients [math]\displaystyle{ z_j }[/math]. This cannot be done by rounding each [math]\displaystyle{ z_j }[/math] in a specific direction, because any such rounding would falsify the dependencies between affine forms that share the symbol [math]\displaystyle{ \epsilon_j }[/math]. Instead, one must compute an upper bound [math]\displaystyle{ \delta_j }[/math] to the roundoff error of each [math]\displaystyle{ z_j }[/math], and add all those [math]\displaystyle{ \delta_j }[/math] to the coefficient [math]\displaystyle{ z_k }[/math] of the new symbol [math]\displaystyle{ \epsilon_k }[/math] (rounding up). Thus, because of roundoff errors, even affine operations like Z = [math]\displaystyle{ \alpha }[/math]X and Z = X + Y will add the extra term [math]\displaystyle{ z_k\epsilon_k }[/math].

The handling of roundoff errors increases the code complexity and execution time of AA operations. In applications where those errors are known to be unimportant (because they are dominated by uncertainties in the input data and/or by the linearization errors), one may use a simplified AA library that does not implement roundoff error control.

Affine projection model

Affine arithmetic can be viewed in matrix form as follows. Let [math]\displaystyle{ X_1,X_2, }[/math][math]\displaystyle{ \dots, }[/math][math]\displaystyle{ X_m }[/math] be all input and computed quantities in use at some point during a computation. The affine forms for those quantities can be represented by a single coefficient matrix A and a vector b, where element [math]\displaystyle{ A_{i,j} }[/math] is the coefficient of symbol [math]\displaystyle{ \epsilon_j }[/math] in the affine form of [math]\displaystyle{ X_i }[/math]; and [math]\displaystyle{ b_i }[/math] is the independent term of that form. Then the joint range of the quantities — that is, the range of the point [math]\displaystyle{ (X_1,X_2, }[/math][math]\displaystyle{ \dots, }[/math][math]\displaystyle{ X_m) }[/math] — is the image of the hypercube [math]\displaystyle{ U^n = [-1,+1]^n }[/math] by the affine map from [math]\displaystyle{ U^n }[/math] to [math]\displaystyle{ R^m }[/math] defined by [math]\displaystyle{ \epsilon }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ A \epsilon + b }[/math].

The range of this affine map is a zonotope bounding the joint range of the quantities [math]\displaystyle{ X_1,X_2, }[/math][math]\displaystyle{ \dots, }[/math][math]\displaystyle{ X_m }[/math]. Thus one could say that AA is a "zonotope arithmetic". Each step of AA usually entails adding one more row and one more column to the matrix A.

Affine form simplification

Since each AA operation generally creates a new symbol [math]\displaystyle{ \epsilon_k }[/math], the number of terms in an affine form may be proportional to the number of operations used to compute it. Thus, it is often necessary to apply "symbol condensation" steps, where two or more symbols [math]\displaystyle{ \epsilon_k }[/math] are replaced by a smaller set of new symbols. Geometrically, this means replacing a complicated zonotope P by a simpler zonotope Q that encloses it. This operation can be done without destroying the first-order approximation property of the final zonotope.

Implementation

Matrix implementation

Affine arithmetic can be implemented by a global array A and a global vector b, as described above. This approach is reasonably adequate when the set of quantities to be computed is small and known in advance. In this approach, the programmer must maintain externally the correspondence between the row indices and the quantities of interest. Global variables hold the number m of affine forms (rows) computed so far, and the number n of symbols (columns) used so far; these are automatically updated at each AA operation.

Vector implementation

Alternatively, each affine form can be implemented as a separate vector of coefficients. This approach is more convenient for programming, especially when there are calls to library procedures that may use AA internally. Each affine form can be given a mnemonic name; it can be allocated when needed, be passed to procedures, and reclaimed when no longer needed. The AA code then looks much closer to the original formula. A global variable holds the number n of symbols used so far.

Sparse vector implementation

On fairly long computations, the set of "live" quantities (that will be used in future computations) is much smaller than the set of all computed quantities; and ditto for the set of "live" symbols [math]\displaystyle{ \epsilon_j }[/math]. In this situation, the matrix and vector implementations are too wasteful of time and space.

In such situations, one should use a sparse implementation. Namely, each affine form is stored as a list of pairs (j,[math]\displaystyle{ x_j }[/math]), containing only the terms with non-zero coefficient [math]\displaystyle{ x_j }[/math]. For efficiency, the terms should be sorted in order of j. This representation makes the AA operations somewhat more complicated; however, the cost of each operation becomes proportional to the number of nonzero terms appearing in the operands, instead of the number of total symbols used so far.

This is the representation used by LibAffa.

References

External links

  • [1] Stolfi's page on AA.
  • [2] LibAffa, an LGPL implementation of affine arithmetic.
  • [3] ASOL, a branch-and-prune method to find all solutions to systems of nonlinear equations using affine arithmetic
  • [4] YalAA, an object-oriented C++ based template library for affine arithmetic (AA).
  • on GitHub (C++ library which can use affine arithmetic)