Integer arithmetic on a binary interval grid #
At precision fractional bits, an integer coefficient z represents z / 2^precision.
Intervals are the existing Interval Int, and each operation takes the scale as an argument
instead of storing it in the interval. Coefficients have unbounded magnitude, so arithmetic cannot
overflow.
Addition, subtraction, and negation are exact. Multiplication rounds the smallest and largest integer products with signed shifts. Division uses four integer quotients and rejects a divisor interval containing zero. Values are decoded to rationals at the interface, never between arithmetic steps.
The endpoint construction follows S. M. Rump,
Verification methods: Rigorous results using floating-point
arithmetic, Acta Numerica 19 (2010), §§5.1–5.3.
BinaryGridProof proves containment for arbitrary real members of the input intervals.
Positive integer scale 2 ^ precision of a grid with precision fractional bits.
Instances For
Exact rational interpretation of an integer coefficient on the binary grid.
Instances For
Floor of z / 2^precision. The signed shift rounds negative values downward too.
Instances For
Ceiling of z / 2^precision, obtained by negating a downward-rounded negative.
Instances For
Integer floor and ceiling of a / b, for a nonzero denominator of either sign.
One signed floor division supplies both endpoints. Testing the integer product detects exact division without computing another quotient or a rational greatest common divisor.
Instances For
Divide using scaled integer numerators, returning none for a denominator containing zero.
The four corner divisions round outward on the same grid as the input endpoints. No rational normalization occurs in this operation.
Instances For
Square with a nonnegative lower bound, including for intervals that cross zero.
Using the range of the square avoids the negative lower endpoint produced by treating the two occurrences of the input as independent factors.
Instances For
Repeated squaring for the endpoint evaluations in BinaryGrid.pow.
With the squaring in its own helper, the public operation can use monotonicity before interval evaluation. The exponent-one branch avoids multiplying by a scaled representation of one.
Instances For
Natural powers with logarithmically many interval operations.
Odd powers are increasing, so their lower and upper bounds come from evaluating at each endpoint. Even powers use the absolute-value interval. These choices avoid treating repeated occurrences of the input as independent values. Each evaluation still rounds outward at intermediate steps. Exponents zero and one are exact, and a point interval needs one repeated-squaring evaluation.