-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
nsimplify.tex
21 lines (20 loc) · 771 Bytes
/
nsimplify.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
The \texttt{nsimplify} function in SymPy
(a wrapper of \texttt{identify} in mpmath)
attempts to find a simple symbolic
expression that evaluates to the same numerical value as the given
input.
It works by applying a few simple transformations
(including square roots, reciprocals, logarithms and exponentials) to
the input and, for each transformed value,
using the PSLQ algorithm~\cite{Ferguson1999} to search for
a matching algebraic number or optionally a linear combination
of user-provided base constants (such as $\pi$).
\begin{verbatim}
>>> t = 1 / (sin(pi/5)+sin(2*pi/5)+sin(3*pi/5)+sin(4*pi/5))**2
>>> nsimplify(t)
-2*sqrt(5)/5 + 1
>>> nsimplify(pi, tolerance=0.01)
22/7
>>> nsimplify(1.783919626661888, [pi], tolerance=1e-12)
pi/(-1/3 + 2*pi/3)
\end{verbatim}