exponentiation.precision_ledger module¶
Module for storing and computing the required number of terms in Taylor approximations of the exponentiation function in order to bound the absolute error.
- class exponentiation.precision_ledger.PrecisionLedger[source]¶
Bases:
object
Object for computing and storing the required number of terms in the Taylor approximation of an exponentiation to achieve a certain precision.
- nr_terms(base, bit_precision, nr_terms_cap=15)[source]¶
Returns the number of terms in the Taylor approximation of an exponentiation to achieve a certain precision.
More precisely, returns the number n required to approximate base**z by the finite sum of ln(base)**i / i! for i from 0 to n where the absolute error is bounded.
- Parameters:
base (
int
) – Base of the exponentiation.bit_precision (
int
) – Require an 2 ** -bit_precision upper bound on the absolute error of the approximation for all exponents with modulus at most one.nr_terms_cap (
int
) – Upper bound on the number of terms that is returned.
- Return type:
int
- Returns:
Minimum number of terms in the Taylor approximation to satisfy accuracy constraints.
- class exponentiation.precision_ledger.PrecisionLedgerIndex(base, bit_precision, nr_terms_cap)[source]¶
Bases:
object
Multi-key index for entries in the PrecisionLedger.
- base:
int
¶
- bit_precision:
int
¶
- nr_terms_cap:
int
¶
- base:
- class exponentiation.precision_ledger.PrecisionLedgerResult(nr_terms)[source]¶
Bases:
object
Stores computational results for the PrecisionLedger.
- nr_terms:
int
¶
- nr_terms:
- exception exponentiation.precision_ledger.PrecisionNrTermsException[source]¶
Bases:
Exception
Required precision was not achieved with given maximum amount of terms.
- exponentiation.precision_ledger.calculate_max_sum_index(base, bit_precision, nr_terms_cap)[source]¶
Compute the number of terms of the Taylor approximation of base ** z so that the absolute error is at most 2 ** -self.bit_precision.
Guarantees hold for $|z|<1$.
- Parameters:
base (
int
) – Base of the exponentiation.nr_terms_cap (
int
) – Upper bound on the number of terms that is returned.
- Return type:
int
- Returns:
Minimal number of terms in the Taylor approximation to achieve the desired precision.
- Raises:
PrecisionNrTermsException – Raised when required precision cannot be reached