3.8.1. qupulse.utils.numeric

Functions

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

approximate_double(x: float, abs_err: float, fraction_type: Type[Rational]) Rational[source]

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

approximate_rational(x: Rational, abs_err: Rational, fraction_type: Type[Rational]) Rational[source]

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

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