3.9.1. qupulse.utils.numeric

Functions

_approximate_int(alpha_num, d_num, den)

Find the best fraction approximation of alpha_num / den with an error smaller d_num / den.

approximate_double(x, abs_err, fraction_type)

Return the fraction with the smallest denominator in (x - abs_err, x + abs_err).

approximate_rational(x, abs_err, fraction_type)

Return the fraction with the smallest denominator in (x - abs_err, x + abs_err)

smallest_factor_ge(n, min_factor[, brute_force])

Find the smallest factor of n that is greater or equal min_factor

qupulse.utils.numeric.approximate_double(x: float, abs_err: float, fraction_type: Type[numbers.Rational]) numbers.Rational[source]

Return the fraction with the smallest denominator in (x - abs_err, x + abs_err).

qupulse.utils.numeric.approximate_rational(x: numbers.Rational, abs_err: numbers.Rational, fraction_type: Type[numbers.Rational]) numbers.Rational[source]

Return the fraction with the smallest denominator in (x - abs_err, x + abs_err)

qupulse.utils.numeric.smallest_factor_ge(n: int, min_factor: int, brute_force: int = 5)[source]

Find the smallest factor of n that is greater or equal min_factor

Parameters
  • n – number to factorize

  • min_factor – factor must be larger this

  • brute_force – range(min_factor, min(min_factor + brute_force)) is probed by brute force

Returns

Smallest factor of n that is greater or equal min_factor