Documentation

CslibFrontier.Computability.PolyTime.FixedPointExp

Polynomial-time fixed-point approximations of π and exp(-z) #

Deterministic pure-ℕ fixed-point arithmetic certified under multi-tape Turing machine polynomial time (Turing.MultiTapeTM.ComputableInPolyTime) in unary precision qBits:

  1. Cslib.FixedPointExp.piApprox: Machin-formula fixed-point approximation of π to qBits fractional bits (using Real.four_mul_arctan_inv_5_sub_arctan_inv_239), with error at most 2 ^ (-qBits).
  2. Cslib.FixedPointExp.expNegSeries and Cslib.FixedPointExp.expNegPow: alternating Taylor series for exp(-z) on [0, 1] (certified via Real.exp_bound and Nat.factorial_mul_pow_le_factorial) and K-fold range-reduced powering for exp(-K * z).

Main definitions #

Main results #

1. Alternating arctan remainder bound #

2. Pure-ℕ alternating arctan (1 / d) fixed-point loop #

theorem Cslib.FixedPointExp.abs_div_two_pow_round_sub_le (raw g : ℕ) (hg : 1 ≤ g) :
|↑((raw + 2 ^ (g - 1)) / 2 ^ g) - ↑raw / 2 ^ g| ≤ 1 / 2

Rounding-to-nearest error of (raw + 2 ^ (g - 1)) / 2 ^ g against raw / 2 ^ g.

Pure-ℕ fixed-point Machin approximation to 2 ^ qBits * π with round-to-nearest downshift.

theorem Cslib.FixedPointExp.abs_piApprox_div_sub_pi_le (qBits : ℕ) :
|↑(piApprox qBits) / 2 ^ qBits - Real.pi| ≤ 2 ^ (-↑qBits)

Fixed-point π approximation error is at most 2 ^ (-qBits).

3. Pure-ℕ fixed-point exp(-z) and range-reduced powering #

Fixed-point approximation to 2 ^ qBits * exp(-zFp / 2 ^ qBits) using 2 * (qBits + 2) terms.

Range-reduced fixed-point approximation of exp(-K * zFp / 2 ^ qBits) via K-fold fixed-point multiplication (P_r * base) / 2 ^ qBits starting from 2 ^ qBits.

theorem Cslib.FixedPointExp.expNegSeries_le (qBits zFp : ℕ) :
expNegSeries qBits zFp ≤ 2 ^ qBits

expNegSeries qBits zFp stays in [0, 2 ^ qBits].

theorem Cslib.FixedPointExp.expNegPow_le (qBits zFp K : ℕ) :
expNegPow qBits zFp K ≤ 2 ^ qBits

expNegPow qBits zFp K stays in [0, 2 ^ qBits].

theorem Cslib.FixedPointExp.abs_exp_neg_sub_exp_neg_le {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) :

exp(-·) is 1-Lipschitz on [0, ∞).

theorem Cslib.FixedPointExp.abs_expNegSeries_div_sub_exp_le (qBits zFp : ℕ) (hz : zFp ≤ 2 ^ qBits) :
|↑(expNegSeries qBits zFp) / 2 ^ qBits - Real.exp (-(↑zFp / 2 ^ qBits))| ≤ (4 * (↑qBits + 2) + 1) / 2 ^ qBits

Fixed-point error bound for expNegSeries.

theorem Cslib.FixedPointExp.abs_expNegPow_div_sub_exp_le (qBits zFp K : ℕ) (hz : zFp ≤ 2 ^ qBits) {zReal : ℝ} (hzReal : 0 ≤ zReal) (hzErr : |zReal - ↑zFp / 2 ^ qBits| ≤ 2 / 2 ^ qBits) :
|↑(expNegPow qBits zFp K) / 2 ^ qBits - Real.exp (-↑K * zReal)| ≤ ↑K * (4 * (↑qBits + 2) + 4) / 2 ^ qBits

Fixed-point error bound for range-reduced expNegPow.