Sympy is pretty awesome. I use live.sympy.org a lot with my students because you can bookmark an entire interactive session as a (long) URL. For example, suppose you had to answer the following question. <i>Find the position of the object at t=3 seconds, if it starts from x_i=20[m], with v_i=10[m/s] and undergoes a constant acceleration of a=5[m/s^2].</i>
Ans: 72.5[m]. Sol.: <a href="http://bit.ly/1hJS9P3" rel="nofollow">http://bit.ly/1hJS9P3</a><p>Below are some more examples of cool stuff sympy can do.<p>Expand, factor, and solve polynomials:<p><pre><code> >>> P = (x-1)*(x-2)*(x-3)
>>> P.expand()
x**3 - 6*x**2 + 11*x - 6
>>> P.factor()
(x - 1)*(x - 2)*(x - 3)
>>> roots = solve(P,x)
>>> roots
[1, 2, 3]
</code></pre>
Derive the solutions of a quadratic equation:<p><pre><code> >>> solve( a*x**2 + b*x + c, x)
[(-b + sqrt(-4*a*c + b**2))/(2*a), -(b + sqrt(-4*a*c + b**2))/(2*a)]
</code></pre>
Compute symbolic outputs of trig functions:<p><pre><code> >>> sin(pi/6)
1/2
>>> cos(pi/6)
sqrt(3)/2
</code></pre>
Sympy knows about trig identities:<p><pre><code> >>> sin(x) == cos(x - pi/2)
True
>>> simplify( sin(x)*cos(y)+cos(x)*sin(y) )
sin(x + y)
>>> e = sin(x)**2 + cos(x)**2
>>> trigsimp(e)
1
</code></pre>
Find the solution to the simple harmonic oscillator differential equation (x''(t)+w^2x(t)=0):<p><pre><code> >>> sol = dsolve( diff(x(t),t,t) + w**2*x(t), x(t) )
>>> sol
x(t) == C1*sin(w*t) + C2*cos(w*t)
</code></pre>
For v4.1 of my math book, I'm going to add a short sympy tutorial. I'll post a printable version of it to HN when I release, so stay tuned ;)
Is there any way to ensure simplified expressions are only defined over the same range as the original expression?<p>My guess is no, but it is often important to understand that, for example, a polynomial fraction is not defined when the denominator is 0.<p>To use an example from the page,<p><pre><code> simplify((x**3 + x**2 - x - 1)/(x**2 + 2*x + 1))
</code></pre>
gives<p><pre><code> x - 1
</code></pre>
but should give<p><pre><code> x - 1; x != 1 + sqrt(2), x != 1 - sqrt(2)
</code></pre>
This is not always what you want to see, but it would be cool if you could turn it on :)
Appears to need a bit more robustification.<p><pre><code> >>> simplify(sqrt(x^2))
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/sympy/sympy/functions/elementary/miscellaneous.py", line 110, in sqrt
return C.Pow(arg, S.Half)
File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/sympy/sympy/core/cache.py", line 93, in wrapper
r = func(*args, **kw_args)
File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/sympy/sympy/core/power.py", line 119, in __new__
obj = b._eval_power(e)
AttributeError: 'Not' object has no attribute '_eval_power'</code></pre>
This is basically the sym() and simple() functions from Matlab, which is something I really felt wasn't nearly widespread enough. Knowing about this is fantastic and I'm going to use it heaps. Thanks!
If anyone from sympy is reading this:<p><pre><code> simplify(exp(x)/exp(x - 1))
</code></pre>
is causing a runtime error:<p><pre><code> RuntimeError: maximum recursion depth exceeded while calling a Python object</code></pre>