|
sigma
1.0.0
|
An interval is fully described by its two bounds, and every other quantity Sigma reports for it is derived from them. In particular the median, \( (a + b)/2 \), is the only central value an interval can offer, so using an interval implicitly assumes that the best estimate of the enclosed quantity sits exactly halfway between the bounds and that the uncertainty is symmetric about it.
That assumption fails in two ways, and both are common. The first is that the uncertainty of a quantity is often genuinely asymmetric. Let \( x \) have the best estimate \( 0 \) and be known to lie in \( [-1, 1] \). The interval extension of \( \exp \) is exact, and gives \( [e^{-1}, e] \), whose median is \( \cosh(1) \approx 1.543 \). The best estimate of \( \exp(x) \) is \( e^0 = 1 \), which is nowhere near the middle of the result.
The second is that the median of a result is not the result of computing with the medians. Let \( X = [-1, 3] \), with median \( 1 \), and form \( X \cdot X \). The interval product is \( [-3, 9] \), whose median is \( 3 \), while the computation applied to the best estimate gives \( 1 \cdot 1 = 1 \). The bounds widened because of the dependency problem described on the interval page, and the median moved with them. In an iterative calculation this is worse than a loose bound: a procedure that feeds the median of one step into the next is no longer iterating the original equations, so the central value drifts away from the answer the same procedure gives in ordinary floating point. In the worst case it no longer converges at all.
Both problems go away if the central value is stored instead of derived. This page describes a representation that keeps the lower bound, the upper bound, and a central value as three independent pieces of state.
The representation is the triplex number, introduced in the 1960s and built into the programming language Triplex-ALGOL 60. A triplex number is an interval together with a Mittelwert (mean value). It was originally motivated by the two problems above, seen from the floating-point side. First, a result computed in ordinary floating point and the same result computed with intervals cannot be compared, and the floating-point value need not even lie in the interval. Second, because rounding errors largely cancel, the leading digits of a floating-point result can be correct even when the corresponding interval cannot determine its sign. An interval alone throws that information away. Sigma adopts the name triplex.
A more recent representation, the asymmetric interval number (AIN), stores the same three numbers but interprets the central value differently. In an AIN the central value is an expectation. Each AIN is assigned an auxiliary probability density, uniform on each side of the central value, which is chosen so that its mean is the central value. The central value of \( g(X) \) is then the expectation of \( g \) under that density, which requires an integral for every operation. The integral has a closed form for some functions and must be evaluated by quadrature for others, such as \( X^Y \). Sigma does not adopt the AIN rule, for three reasons. It replaces a cheap scalar evaluation with an integral for every operation. It imposes a density that was not part of the input and is not what the true distribution becomes after a sequence of operations. And it gives up comparability with ordinary floating point, which is the property that makes the central value useful in an iterative calculation.
A triplex number is an ordered triple
\begin{equation} \normalsize X = \langle a, m, b \rangle \qquad a \leq m \leq b \label{eq:tp-def} \end{equation}
where \( [a, b] \) is an interval in the sense of the interval page and \( m \) is the nominal value, a distinguished member of that interval. The interval carries the guarantee: every possible value of the quantity lies in \( [a, b] \). The nominal value carries the best estimate: the value the computation would produce if every input were exactly its nominal value. Nothing relates \( m \) to the bounds beyond the ordering of Eq. \(\eqref{eq:tp-def}\). In general
\begin{equation} \normalsize m \neq \frac{a + b}{2} \label{eq:tp-not-median} \end{equation}
and Eq. \(\eqref{eq:tp-not-median}\) is the whole point of the type.
The original Mittelwert translates as "mean value", and Sigma's Uncertain class calls the corresponding quantity its mean, but in neither case is it a statistical expectation. Sigma therefore calls it the nominal value, in the sense used in metrology: the value of a quantity computed from the nominal values of its inputs. The nominal value of \( f(X) \) is \( f(m) \), which is also what the linear error propagation of the Background page uses for its mean, and which differs from the expectation of \( f \) whenever \( f \) is nonlinear.
Because the nominal value need not be central, a triplex number has two radii rather than one, measuring the distance from the nominal value to each bound
\begin{equation} \normalsize r_{-}(X) = m - a \qquad r_{+}(X) = b - m \label{eq:tp-radii} \end{equation}
and the equivalent radius form of a triplex number stores exactly these: \( m - r_{-} \leq x \leq m + r_{+} \). The width \( b - a = r_{-} + r_{+} \) and the median \( (a + b)/2 \) are defined as for an interval. The median remains the midpoint of the set, and by Eq. \(\eqref{eq:tp-not-median}\) it is not the nominal value.
The bounds may be closed, as in Interval, or possibly open, as in GeneralInterval (see the general interval page). With open bounds, the nominal value must still be a member of the set, so it may not coincide with an open bound. A degenerate triplex number \( \langle v, v, v \rangle \) has two closed bounds and represents the exactly known value \( v \).
Triplex arithmetic is two independent computations carried out side by side. The bounds are computed exactly as for an interval, with the same outward rounding, so the enclosure property of interval arithmetic holds unchanged. The nominal value is computed in ordinary floating point from the operand nominal values
\begin{equation} \normalsize \langle a, m_x, b \rangle \circ \langle c, m_y, d \rangle = \left\langle \mathrm{lo}\left([a, b] \circ [c, d]\right),\; \mathrm{fl}\left(m_x \circ m_y\right),\; \mathrm{hi}\left([a, b] \circ [c, d]\right) \right\rangle \label{eq:tp-binary} \end{equation}
where \( \mathrm{lo} \) and \( \mathrm{hi} \) are the bounds of the interval result and \( \mathrm{fl} \) denotes the round-to-nearest result. A unary function \( f \) works the same way, with nominal value \( \mathrm{fl}(f(m)) \).
Eq. \(\eqref{eq:tp-binary}\) keeps the ordering of Eq. \(\eqref{eq:tp-def}\) for the four arithmetic operations with closed bounds and finite nominal values. Since \( m_x \in [a, b] \) and \( m_y \in [c, d] \), the exact \( m_x \circ m_y \) lies in the exact interval result, and the outward rounded bounds are representable numbers on either side of it. Rounding to nearest cannot carry the nominal value past a representable number that brackets it. With open bounds it can land on an excluded endpoint, so the widening/closing rule below also applies to arithmetic. Elementary functions have another hazard: the math library's \( f(m) \) may be off by a few units in the last place. When this pushes the nominal value outside the computed bounds, or onto an open bound, the implementation widens the bound to include the nominal value, and closes it if it was open. It does not move the nominal value. Widening never invalidates an enclosure, and leaving the nominal value alone keeps the property below exact.
The one exception is a nominal value that is not finite. Ordinary floating point can overflow where the interval does not fail: scaling \( \langle 10^{308}, 10^{308}, 10^{308} \rangle \) by \( 2 \) gives the floating-point nominal value \( +\infty \), and an infinite or NaN nominal value cannot be a member of any interval, since an infinite bound is never a member. The triplex keeps such a nominal value anyway. It is what the plain floating-point computation produces, so keeping it preserves the comparability property below, and it reports the overflow instead of hiding it. The membership invariant of Eq. \(\eqref{eq:tp-def}\) is waived for a non-finite nominal value, no widening is attempted (an infinite bound stays unbounded), and callers can test for this case with std::isfinite(nominal()). Construction still requires a finite nominal value in the set.
Applying Eq. \(\eqref{eq:tp-binary}\) to every operation gives the central guarantee of the type:
The nominal value of a triplex computation is, bit for bit, the result of the same computation performed in ordinary floating point on the input nominal values.
This is the comparability property, and it is what fixes the drift described at the top of this page. Returning to that example, \( \langle -1, 1, 3 \rangle \cdot \langle -1, 1, 3 \rangle = \langle -3, 1, 9 \rangle \). The bounds still suffer the dependency problem, but the nominal value is exactly the floating-point answer. Likewise \( X - X \) has the needlessly wide bounds of the interval case, but its nominal value is exactly zero. The dependency problem cannot affect the nominal value, because a single scalar evaluation has no second copy of \( X \) to decorrelate from.
The elementary functions inherit their domains from the underlying interval type without change. The nominal value lies in the argument interval, so if the interval function accepts the argument, then \( f(m) \) is defined. Division by an interval containing zero throws, as it does for intervals, even when the divisor's nominal value is nonzero.
Triplex arithmetic adds information to the interval but does not tighten it. The bounds are exactly the bounds Interval would produce, so the dependency problem and the \( O(h) \) overestimation discussed on the interval page apply unchanged. What changes is that the interval no longer has to supply a best estimate. The nominal value is exact in the sense above, the asymmetry of the uncertainty is visible through the two radii of Eq. \(\eqref{eq:tp-radii}\), and a calculation that iterates on the nominal value iterates the same equations it would in ordinary floating point.
Two things the nominal value is not should be stated plainly. It is not rigorous: it carries the rounding error of ordinary floating point, and only the bounds are guaranteed. And, as noted in the definition, it is not the statistical mean of the result.
Triplex arithmetic is orthogonal to the dependency tracking of affine arithmetic and Taylor models. Those representations tighten the bounds, while a triplex number keeps an unbiased central value alongside whatever bounds it is given. Combining the two is possible, but it is outside the scope of this design.
sigma::Triplex<IntervalType> is built by composition on an interval type, just as ThresholdedAffine is built on Affine. IntervalType is either Interval<U> or GeneralInterval<U>, and value_t is its value_t. Triplex holds an IntervalType and a value_t nominal value, so a closed triplex does not pay for open bounds. The interval supplies the bounds, any openness, emptiness, outward rounding, and domain checking. Triplex adds only the nominal value and the invariant of Eq. \(\eqref{eq:tp-def}\). Each operation delegates the bounds to the corresponding interval operation, computes the nominal value with the corresponding std function, and then applies the widening rule described above. That rule is the only place the two interval types differ, and it goes through one small helper that widens an interval to include a point, which for a GeneralInterval also closes the bound the point lands on.
Storing the bounds, rather than the nominal value and the two radii of the radius form, is deliberate. With the bounds stored, all of the rounding-aware code in Interval and detail_/policies.hpp is reused as is. With the radii stored, the outward rounding would have to be redone for the radii. The radius form spends fewer digits, but that advantage matters for hand-written decimal triples, not for double.
One implementation hazard is specific to this type. The bounds are computed under directed rounding, and the nominal value must be computed in round-to-nearest, or it stops matching the floating-point result. Interval's operations restore the rounding mode before they return, so the nominal value is evaluated after the interval operation and outside any rounding guard. A unit test checks the guarantee of the previous section directly, by comparing the nominal value of a nontrivial triplex expression for exact equality with the same expression evaluated in plain double.
The interface mirrors Interval where the concepts coincide, and departs from it where they don't:
The files follow the existing layout: include/sigma/triplex/triplex.hpp, the operations split into basic, exponents, trigonometry, and hyperbolic headers under include/sigma/triplex/operations/, an eigen_compat.hpp that specializes Eigen::NumTraits as Interval does, an include in sigma/sigma.hpp, and tests under tests/unit_tests/triplex/. The convenience typedefs TPFloat and TPDouble name the closed instantiations, Triplex<Interval<float>> and Triplex<Interval<double>>, since TFloat and TDouble already name Taylor instantiations. The general instantiations are written out in full until there is a need for typedefs.
The design leaves out several things that would be straightforward to add later: