Struct RapidSimplifyVisitor

Struct Documentation

struct RapidSimplifyVisitor

Public Functions

inline void operator()(ExprPtr &expr)
inline bool simplify_product(ExprPtr &expr)

simplifies a Product by:

  • fusing its rational Powers into one, and its Variable factors into one per Variable

  • flattening subproducts

  • factoring in constants

Parameters:

expr – [inout] (shared_ptr to ) a Product

inline bool simplify_sum(ExprPtr &expr)

simplifies a Sum … generally Sum::{ap,pre}pend simplify automatically, but the user code may transform sums in a way that the same simplifications need to be applied here

inline bool simplify_power(ExprPtr &expr)

simplifies a lone Power as simplify_product() would one inside a Product: folds it if possible, else brings it to the same form, so that e.g. 2^(3/2) becomes 2 2^(1/2) and merges with it in a Sum

Parameters:

expr – [inout] (shared_ptr to ) a Power

inline bool simplify(ExprPtr &expr)
Returns:

true if any simplifications were performed

Public Static Functions

static inline ExprPtr fuse_rational_powers(const Product &product)

fuses the Powers of product with positive real Constant bases into simplest radical form (see simplest_radical_form()): the rational part of their value is multiplied into the scalar, the rest becomes a single Power R^(1/D). The scalar itself is never fused in, so the rational part of the value always sits in the scalar and the radicand depends only on the value; numerically equal Products thus hash and compare equal, and terms that differ by a rational factor merge when the Sum is next rebuilt, as by canonicalize() and hence simplify() (rapid_simplify() leaves summands it has just made identical side by side). Powers with negative, complex or Variable bases are left alone, and a Product whose form would exceed the size cap of simplest_radical_form() is left whole, none of its Powers fused.

Parameters:

product – [in] a Product

Returns:

the fused Product, or null if product is already in this form

static inline ExprPtr fuse_variable_powers(const Product &product)

fuses the factors of product that are a Variable or a Power of one into one factor per Variable: the exponents are summed, a bare Variable counting as 1, grouped by label and by the conjugation of the base combined with that of the Power (as in Power::operator*=). A sum of 0 drops the factor, 1 gives the bare Variable, anything else a Power of the Variable, with the conjugation on the Variable in either case, so (x^2)* becomes (x*)^2. Fused factors keep the position of their first occurrence.

Parameters:

product – [in] a Product

Returns:

the fused Product, or null if product is already in this form