Correctness of Payne-Hanek reduction #
reduceWindow_spec proves that every window of at least two bits reduces m * 2 ^ e, for
m > 0: x * 2/π = 4 j + quadrant + (fraction + η) / 2 ^ scale with 0 ≤ η < 2 m
(QuarterTurns.Reduces). The proof splits the cached T ≤ 2/π * 2 ^ N < T + 2 into its bits above,
inside and below the window: the bits above contribute a multiple of four, the window gives the
fraction, and the bits below together with the error of T give η. The fraction has magnitude at
most half a quarter turn (abs_fraction_reduceWindow_le).
An accepted reduction has the sign of the true remainder and relative error at most 2 ^ -bits
(QuarterTurns.Reduces.exists_remainder). With r the reduced argument in radians, the sine and
cosine of x are those of r rotated by the quadrant
(QuarterTurns.Reduces.exists_sin_cos_eq_rotate). The computed argument
q.argumentNumerator precision / 2 ^ (scale + precision) is within
error / 2 ^ scale * π/2 + |fraction| / 2 ^ scale * 2 ^ (1 - precision) of r
(QuarterTurns.abs_argument_sub_le), and its rotated sine and cosine are within the same bound of
those of x (QuarterTurns.Reduces.abs_sin_sub_rotate_le and its cosine form).
reduce returns the reduction of one of its attempts (exists_reduce_eq_reduceWindow),
so it reduces its argument too (reduce_spec), with error 2 m and a fraction of at most
half a quarter turn. It returns an accepted reduction when some attempt within its fuel is accepted
(accepts_reduce). fuelWithin? keeps every attempt within its level limit
(fuelWithin?_spec) and gives no fuel exactly when the first window exceeds that limit
(fuelWithin?_eq_none_iff).
q reduces x: x * 2/π = 4 j + quadrant + (fraction + η) / 2 ^ scale for an integer j and some
η with 0 ≤ η < error.
Instances For
The window #
The level of a window holds at least e + window + 6 bits of 2/π.
Accepted reductions #
An accepted reduction has a nonzero fraction that keeps its sign: for 0 ≤ η < error,
fraction + η has the sign of fraction, and η * (2 ^ (bits + 1) - 1) ≤ |fraction + η|.
An accepted reduction gives the remainder f of x * 2/π, in units of 2 ^ -scale quarter turns,
to a relative error of 2 ^ -bits and with its sign.
Quadrants #
The sine and cosine after whole quarter turns are the rotated sine and cosine.
With r = (fraction + η) / 2 ^ scale * π/2 the reduced argument, the sine and cosine of x are
those of r rotated by the quadrant.
Error of the computed argument #
The computed argument q.argumentNumerator precision / 2 ^ (scale + precision) is within
error / 2 ^ scale * π/2 + |fraction| / 2 ^ scale * 2 / 2 ^ precision of the reduced argument
(fraction + η) / 2 ^ scale * π/2, for 0 ≤ η < error.
The sine of a reduced x is within error / 2 ^ scale * π/2 + |fraction| / 2 ^ scale * 2 / 2 ^ precision of the rotated sine of the computed argument
q.argumentNumerator precision / 2 ^ (scale + precision).
The cosine form of QuarterTurns.Reduces.abs_sin_sub_rotate_le.
Attempts #
Every attempt window has at least twenty bits.
Later attempts have wider windows.
Wider windows read the same or a higher level.
reduce returns the reduction of one of its attempts.
reduce returns an accepted reduction when some attempt within the fuel is accepted.
fuelWithin? keeps every attempt within the level limit: a result count is at most fuel, and
every attempt up to it reads a level of at most limit.
fuelWithin? gives no fuel exactly when the first window reads a level above limit.