Skip to content

Simplifications Guidelines

Ondřej Čertík edited this page Jul 11, 2019 · 2 revisions

Simplification Guidelines

SymEngine does a few very simple simplifications automatically, for example x+x will get simplified to 2*x, or abs(abs(x)) will get simplified to abs(x). This is done when the expression is constructed, and so a SymEngine expression cannot represent x+x or abs(abs(x)), this is checked by the is_canonical methods which are called from the constructor in Debug mode.

Question: What are the guidelines to determine which simplifications to do automatically before the expression is constructed (such as x+x->2*x or abs(abs(x))->abs(x)) and which to do as part of "simplify" or other functionality that operates on the SymEngine expression tree once it is constructed?

Answer: For functions, do any fast operations that result in a simpler expression. So, abs(abs(x)) should be simplified to abs(x) as the check is fast and results in a simpler expression, so we do it before the expression is even constructed. tan(pi/24) -> -2 + sqrt(6) - sqrt(5 - 2 sqrt(6)) is fast, but not simpler and therefore we do not do it automatically. cos(asin(x/sqrt(x^2+y^2))) -> sqrt(1 - x^2/(x^2 + y^2)) is simpler, but not fast to check, so we do not do it automatically either. The latter two substitutions are implemented as functions in SymEngine that can do these when the user calls them on an already constructed expression.