Simplify
A complicated mathematical expression can often be transformed into a form that is easier to understand.
The expr.simplify()
function tries expanding, factoring and applying many
other transformations to find a simple a simpler form of a symbolic expression.
Before the transformation rules are applied, the expression is put into a canonical form.
When a function is simplified, its arguments are simplified as well, unless the
argument is “held”. Which arguments are held is specified by the hold
property
of the function definition. In addition, any argument wrapped with a Hold
function will be held, that is, not simplified. Conversely, a held argument
wrapped with a ReleaseHold
function will not be held, and it will be
simplified.
Defining “Simpler”
An expression may be represented by several equivalent forms.
For example \( (x + 4)(x-5) \) and \(x^2 -x -20\) represent the same expression.
Determining which is “the simplest” depends on how the complexity is measured.
By default, the complexity of an expression is measured by counting the number of operations in the expression, and giving an increasing cost to:
- integers with fewer digits
- integers with more digits
- other numeric values
- add, multiply, divide
- subtract and negate
- square root and root
- exp
- power and log
- trigonometric function
- inverse trigonometric function
- hyperbolic functions
- inverse hyperbolic functions
- other functions
To influence how the complexity of an expression is measured, set the
costFunction
property of the compute engine to a function assigning a cost to
an expression.
Numeric Simplifications
The expr.simplify()
function will apply some numeric simplifications, such as
combining small integer and rational values, simplifying division by 1, addition
or subtraction of 0, etc…
It avoids making any simplification that could result in a loss of precision.
For example, \( 10^{300} + 1\) cannot be simplified without losing the least
significant digit, so expr.simplify()
will return the expression unmodified.
Using Assumptions
Assumptions are additional information available about some symbols, for example \( x > 0 \) or \(n \in \N\).
Some transformations are only applicable if some assumptions can be verified.
For example, if no assumptions about \(x \) is available the expression \( \sqrt{x^2} \) cannot be simplified. However, if an assumption that \( x \geq 0 \) is available, then the expression can be simplified to \( x \).