Removable singularities in floating point
The coefficients of the rotations' and the rigid motions' maps are smooth at the identity, but their closed forms divide by a power of the angle there; each is computed by a series below a cutoff and its closed form above, and the cutoff is set by how the error of a sine and a cosine, relative or absolute, is amplified by that division.
The exponential of a rotation, its logarithm and their Jacobians are smooth maps, and their formulas are not: each has a coefficient such as whose closed form is at the identity, the point computations visit most. The singularity is removable: the coefficient extends smoothly through , and its power series says how. This note lists the coefficients, says how each is computed so that its value and its derivatives are right on both sides of the identity, and works out what decides where the series should hand over to the closed form. The answer depends on how accurately the machine computes a sine.
The coefficients#
The coefficients of the rotations and of the rigid motions are each a function of , with the angle of a rotation vector, or for the logarithm of and , with .
| coefficient | closed form | series | used by |
|---|---|---|---|
| the exponential (6) | |||
| the exponential | |||
| the Jacobians (9) | |||
| the Jacobians | |||
| their inverses (10) | |||
| , | the logarithm (7) | ||
| the motions’ Jacobians (6) | |||
| the motions’ Jacobians |
The series of is that of , and that of is for , expanded in . Other spaces have coefficients of the same kind: the volume of the exponential chart of a sphere, for one, is a power of , and its logarithm is computed the same way.
A series below a cutoff#
Each coefficient is computed by its series, truncated, where its argument is below a cutoff, and by its closed form above it. Three things have to be right for the result to be the smooth function it stands for, in its derivatives as well as its value.
The series is a function of the same arguments. A derivative is taken of the formula that was evaluated, so the series must depend on its arguments as the function does. The coefficients in are functions of and their series are polynomials in it. The logarithm’s coefficient depends on and on , and its series keeps both. On the sphere , and a series in alone would have the right values, but it would have no derivative in , and second derivatives along the sphere, which move at second order, would be wrong. The logarithm’s series also holds near the identity only, for and ; near the closed form is used, and what it has there is the logarithm’s own cut, which no series removes.
The series keeps enough terms. It keeps at least the terms through , so that derivatives of second order at the identity are exact, and beyond that as many as make its truncation error at the cutoff smaller than the rounding of the closed form there.
Neither formula is evaluated where it is undefined. When both formulas are computed and one is then chosen, as a computation over many values at once does, the one not chosen must still be finite, since a reverse pass multiplies its derivative by zero, and zero times an undefined number is undefined. So the closed form is given a harmless argument where the series is chosen, and the series, where it can be undefined, as the logarithm’s is at , a harmless one where the closed form is.
Relative and absolute error#
A computed value carries an error, the difference between what the machine returns and the exact value at the same, already rounded, input. Write for the unit roundoff of the arithmetic, in single precision and in double. A function has relative error when its computed value is with , and absolute error when it is with . The two differ only where is small, which is exactly where a removable singularity is computed, since near .
A mathematical library’s sine is accurate relative to its value, to within a few . That is not a law of nature. An implementation built for throughput, as a graphics processor’s often is, may promise only an absolute error for its sine and for its cosine, each many times . Near the two kinds of error hardly differ. Near they differ by the factor .
How the error reaches a closed form#
Every closed form of the table but the logarithm’s is
with a polynomial whose own partial derivatives in its second and third arguments do not vanish at : has and , and has and . The numerator cancels to . The error of the sine and the cosine does not. With the computed and , to first order in the errors,
so that under absolute errors , with bounded near and , while under relative ones, and , the sine’s part is smaller by the factor .
Derivatives make it worse. Automatic differentiation evaluates each step’s derivative formula at the computed values, so it differentiates the formula as written, never the rounding, and the -th derivative of (1) in is another expression of the same form: a polynomial in , and over , since each derivative in is and lowers the order of the numerator’s cancellation by two. Its error is therefore at most
Against a sine of relative accuracy, a sine of absolute accuracy loses the factor in every closed form whose numerator holds a sine with a coefficient that does not cancel, as ’s and ’s do, and nothing in those that hold only a cosine, as ’s and ’s do. With in single precision that factor is : about at , in a second derivative of that is already divided by .
Three kinds of map are spared. One without a cancelling numerator, such as a rotation’s matrix, its action on a vector, or the exponential’s , carries into its value once. The logarithm’s divides by the angle of a point, and an of relative accuracy loses nothing. And the argument itself, computed from with a relative error of a few roundings, costs no more than a relatively accurate sine does: where the numerator and the power are formed from the same computed , the closed form is evaluated consistently at a nearby argument, and its error is , bounded near .
Where to put the cutoff#
The closed form is used above a cutoff and the series below it. Two conditions decide , and they pull in opposite directions.
The closed form above the cutoff. Take each order of derivative that is computed, and each map that uses the coefficient , and let be the factor by which the map multiplies ’s -th derivative. Then
where is the error the coefficient may contribute and the absolute error of the sine and the cosine on the least accurate machine the computation must run on. The bound decreases in , so a larger cutoff always meets it, and by (2) a machine with a relatively accurate sine meets it wherever one with the absolute error does. How far a cutoff must rise for a sine of absolute error to do no worse than a relatively accurate one did at is, by the same scaling, the factor , which is largest where is smallest. It is a guide only, since it drops .
The series below it. The series truncated after terms, with remainder , must meet the rounding of the most precise arithmetic in use at the cutoff, in its value and its derivatives:
The series of , , , and are entire, with terms falling like , so every cutoff can be met with enough terms: at in double precision, about ten. ’s series converges for , with terms falling by , and that of for , with terms falling by . Either radius bounds the cutoff away from it, and the number of terms grows as the cutoff nears it. A series costs a product and a sum per term.
One cutoff serves every machine. The first condition is hardest in the least precise arithmetic with the least accurate sine, and the second in the most precise arithmetic. A cutoff that meets the first for the one and the second for the other meets both everywhere else, so a formula need not know which machine it runs on. For the entire series such a cutoff always exists. Raising it costs terms, and nothing else.
Built on by
- Rotations and rigid motions The crate skoro-spatial declares the rotations, the rigid motions and the extended poses as embedded types stored as quaternions up to sign, with the Cayley chart, global on each group, and declared volumes, so that they carry the normal in whatever sign their quaternions are given, and writes their maps as composites whose derivatives are the core's.