forked from sympy/sympy-paper
/
simplification.tex
43 lines (36 loc) · 1.67 KB
/
simplification.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
% polynomial expressions
% functions
% expand( ), factor( ), collect( ), together( ), apart( )
%% maybe a table best suits this part.
% simplification: simplify, sqrt denest, fu, trigsimp
The generic way to simplify an expression is by calling the \texttt{simplify}
function.
It must be emphasized that simplification is not an unambiguously defined
mathematical operation~\cite{Carette2004understanding}.
The \texttt{simplify} function applies several simplification routines along
with heuristics to make the output expression as ``simple'' as possible.
It is often preferable to apply more directed simplification functions. These
apply very specific rules to the input expression and are typically able to make
guarantees about the output. For instance, the \texttt{factor} function,
given a polynomial with rational coefficients in several variables,
is guaranteed to
produce a factorization into irreducible factors. Table~\ref{simplify-table}
lists common simplification functions.
\begin{longtable}[htbc]{lp{0.83\linewidth}}
\caption{Some SymPy Simplification Functions\label{simplify-table}}\\
\toprule
\verb|expand| & expand the expression \\
\verb|factor| & factor a polynomial into irreducibles \\
\verb|collect| & collect polynomial coefficients \\
\verb|cancel| & rewrite a rational function as $p/q$ with common factors
canceled \\
\verb|apart| & compute the partial fraction decomposition of a rational function
\\
\verb|trigsimp| & simplify trigonometric expressions~\cite{fu2006automated} \\
\bottomrule
\end{longtable}
Substitutions are performed using the \texttt{.subs} method.
\begin{verbatim}
>>> (sin(x) + x**2 + 1).subs(x, y + 1)
(y + 1)**2 + sin(y + 1) + 1
\end{verbatim}