Documentation

CslibFrontier.Foundations.Algebra.Polynomial.DyadicSignApproximation

Rational approximation of the sign on a dyadic interval #

The normalized difference of the two reflected evaluations of the integer sign product is exact at zero. For nonzero inputs of magnitude between 2 ^ B and its reciprocal, the error is at most 2 / 3 ^ (2 * s). The denominator is positive everywhere by the sign product bound.

Adapted from RationalSignProduct and RationalSignError in lean-canny at commit 970f28a5ecefc1327402ade16c068aa4b1b2c183.

noncomputable def Polynomial.dyadicSignApprox (B s : ℕ) (x : ℝ) :

Approximate the sign by the difference of the reflected product values divided by their sum.

@[simp]

The normalized difference is zero at the origin.

theorem Polynomial.abs_dyadicSignApprox_sub_sign_le (B s : ℕ) {x : ℝ} (hx : x = 0 ∨ (2 ^ B)⁻¹ ≤ |x| ∧ |x| ≤ 2 ^ B) :
|dyadicSignApprox B s x - ↑(SignType.sign x)| ≤ 2 * (3 ^ (2 * s))⁻¹

The normalized ratio approximates the sign with uniform exponential error for either sign on the dyadic range, and it also accepts zero.

theorem Polynomial.abs_dyadicSignApprox_sub_sign_le_inv_four_mul_succ (B m : ℕ) {x : ℝ} (hx : x = 0 ∨ (2 ^ B)⁻¹ ≤ |x| ∧ |x| ≤ 2 ^ B) :
|dyadicSignApprox B (m + 1) x - ↑(SignType.sign x)| ≤ (4 * (↑m + 1))⁻¹

For a list of m tests, repetition m + 1 brings the per-test error within the tolerance of the squared-error score.