Function sequant::simplest_radical_form

Function Documentation

inline std::optional<RadicalForm> sequant::simplest_radical_form(const container::svector<std::pair<rational, rational>> &powers, unsigned max_trial_divisor = 1000, unsigned max_bits = default_max_folded_bits)

computes the simplest radical form of a product of rational powers of positive rationals

The bases are split by coprime_base(), each element with a non-integer exponent is factored by trial division up to max_trial_divisor (one with an integer exponent contributes only to the rational part and is left whole), and the exponents of each prime, and of the cofactor trial division leaves, are summed; a cofactor that is a perfect power is replaced by its root first. The integer part of each sum goes into the rational part, the fractional part into the radicand, and the root order is the lcm of the denominators of the fractional parts. The radicand is thus not divisible by the root_order-th power of a prime up to max_trial_divisor, nor of a larger prime whose power is the whole cofactor of an element, so the result depends only on the value of the product unless a cofactor has two or more distinct prime factors above max_trial_divisor and is not a perfect power.

Note

the search for the roots of a cofactor costs superlinearly in its size: a base of 20000 bits with no factor below max_trial_divisor and a non-integer exponent takes about a second

Parameters:
  • powers – [in] (base, exponent) pairs; every base must be positive

  • max_trial_divisor – [in] the largest divisor tried when factoring

  • max_bits – [in] the largest size, in bits, of the radicand and of the numerator and the denominator of the rational part; a larger result is refused rather than built (exponents with large coprime denominators produce one, since their lcm multiplies every exponent); a base whose integer part of the exponent alone would exceed it is refused before it is factored

Throws:

Exception – if a base is not positive

Returns:

the form, or null if it would exceed max_bits