-
Notifications
You must be signed in to change notification settings - Fork 0
SymPy vs. Sage
SymPy and Sage are Computer algebra systems.
- Computer Algebra System
- A software program that facilitates symbolic mathematics. The core functionality of a CAS is manipulation of mathematical expressions in symbolic form.
Sympy is a Python library for symbolic computation that aims to become a full-featured computer algebra system and to keep the code simple to promote extensibility and comprehensibility.
SymPy was created by Ondřej Čertík and the development began in 2006. In 2007, SymPy was realeased to the public. The latest stable release of SymPy is 0.7.1.
SymPy can be used
- Inside Python, as a library
- As an interactive command line, using IPython
- For programs (writing interpreted and compiled programs)
- And scripts (writing stand-alone Python scripts that use the SymPy library)
Sage (previously SAGE) is a mathematical software with features covering many aspects of mathematics, including algebra, number theory and calculus.
Sage was created by William A. Stein and the development began in 2005. The first public release was in the same year. The latest stable release of Sage is Sage 4.7.2.
Sage can be used in several ways:
- Notebook graphical interface - Interactive command line - Programs (writing interpreted and compiled programs) - Scripts (writing stand-alone Python scripts that use the Sage library)
Both SymPy and Sage are cost free open source CASes written entirely in Python (although Sage contains Cython code as well), the first one being released under a modified BSD license and the latter under a GNU GPL license.
One of the differences between SymPy and Sage is the fact that Sage comes with a GUI - the Notebook graphical interface. This Notebook is useful because it allows you to write and run code, display 2d and 3d plots and organize and share your work. The Notebook is run by typing notebook() after you cd into the Sage directory and run ./sage. The notebook() command starts the Sage notebook and opens your default browser to view it. However, SymPy can use plotting as well, by installing PyGlet.
System | Windows | Mac OS X | Linux | BSD | Solaris | Other |
SymPy | Yes | Yes | Yes | Yes | Yes | Any system that supports Python |
Sage | No | Yes | Yes | No | Yes | VMware image for MS-Windows users |
Sympy is distributed in various forms. It is possible to download source tarballs and packages from the Google Code page but it is also possible to clone the main Git repository or browse the code online. The only prerequisite is Python since Sympy is Python-based library. It is recommended to install IPython as well, for a better experience. Sage can be installed either from a pre-built binary tarball or from source. The binary method is fastest and has fewest prerequisites. The source method may take a long time (from 1 hour to 14 days), depending on the computer (it took about two weeks to build Sage on the T-Mobile G1 Android telephone).
System |
Formula editor |
Arbitrary precision |
Calculus | Solvers |
Graph theory |
Number theory |
Quantifier elimination |
Boolean algebra |
Tensors | |||||
Integration | Integral transforms | Equations | Inequalities | Diophantine equations | Differential equations | Recurrence relations | ||||||||
SymPy | No | Yes | Yes | No | Yes | Yes | No | Yes | Yes | No | Yes | No | Yes | Yes |
Sage | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
SymPy
To perform partial fraction decomposition apart(expr, x) must be used. To combine expressions, together(expr, x) is what you need. Here are some examples of these two and other common functions in ISymPy:
In [8]: 1/( (x**2+2*x+1)*(x**2-1) ) Out[8]: 1 ─────────────────────── ⎛ 2 ⎞ ⎛ 2 ⎞ ⎝x - 1⎠⋅⎝x + 2⋅x + 1⎠ In [9]: apart(1/( (x**2+2*x+1)*(x**2-1) ), x) Out[9]: 1 1 1 1 - ───────── - ────────── - ────────── + ───────── 8⋅(x + 1) 2 3 8⋅(x - 1) 4⋅(x + 1) 2⋅(x + 1) In [10]: together(1/(x**2+2*x) - 3/(x+y) + 1/(x+y+z)) Out[10]: x⋅(x + 2)⋅(x + y) - 3⋅x⋅(x + 2)⋅(x + y + z) + (x + y)⋅(x + y + z) ───────────────────────────────────────────────────────────────── x⋅(x + 2)⋅(x + y)⋅(x + y + z)
The evalf() method and the N() function can be used to evaluate expressions:
In [20]: pi.evalf() Out[20]: 3.14159265358979 In [23]: N(sqrt(2)*pi, 50) Out[23]: 4.4428829381583662470158809900606936986146216893757
Integrals can be used like regular expressions and support arbitrary precision:
In [24]: Integral(x**(-2*x), (x, 0, oo)).evalf(20) Out[24]: 2.0784499818221828310
Sage
Here are some examples of algebra in Sage:
1/( (x**2+2*x+1)*(x**2-1) ) 1/((x^2 - 1)*(x^2 + 2*x + 1)) expand((x-1)^2) x^2 - 2*x + 1 f = I + x - x simplify(f) I f = (cos(x)*sin(y))/sin(y)+(sin(x)*cos(y))/sin(x) simplify(f) cos(x) + cos(y)
In Sage, to return the exact value of expressions, n(), .n(digits) and numerical_approx(var, prec) are used:
n(pi) 3.14159265358979 N(sqrt(2)*pi, digits=50) 4.4428829381583662470158809900606936986146216893757 numerical_approx(pi, prec=200) 3.1415926535897932384626433832795028841971693993751058209749 f = x^(-2*x) f.integral(x, 1, +Infinity) integrate(x^(-2*x), x, 1, +Infinity) show(integrate(x^(-2*x), x, 1, +Infinity)) .. image:: int4.png
SymPy
Limits in SymPy have the following syntax: limit(function, variable, point). Here are some examples:
- limit of f(x)= sin(x)/x as x -> 0:: In [20]: from sympy import * In [21]: x = Symbol('x') In [22]: limit(sin(x)/x, x, 0) Out[22]: 1 - limit of f(x)= 2*x+1 as x -> 5/2:: In [24]: limit(2*x+1, x, 5/2) Out[24]: 6.00000000000000 x - limit of f(x)= (3+sin(x))*e as x -> ∞ In [26]: limit((3 + sin(x))*exp(x), x, oo) Out[26]: ∞
Sage:
The limit() function has this syntax: limit(ex, dir=None, taylor=False, algorithm=’maxima’, **argv):
x = var('x') f = (1+1/x)^x f.limit(x = oo) e f.limit(x = 5) 7776/3125 f.limit(x = I, taylor=True) (-I + 1)^I
SymPy:
In [1]: from sympy import * In [2]: x = Symbol('x') In [3]: diff(cos(x**3), x) Out[3]: 2 ⎛ 3⎞ -3⋅x ⋅sin⎝x ⎠ In [4]: diff(atan(2*x), x) Out[4]: 2 ──────── 2 4⋅x + 1 In [6]: diff(1/tan(x), x) Out[6]: 2 - tan (x) - 1 ───────────── 2 tan (x)
Sage:
var ('x') # declaration of variable x x f = cos(x**3); f cos(x^3) f.diff(x) -3*x^2*sin(x^3) show(f) # show() is one of the pprint functions in Sage .. image:: so1.png show(f.diff(x)) .. image:: so2.png f = atan(2*x); f arctan(2*x) f.diff(x) 2/(4*x^2 + 1) show(f) .. image:: so3.png show(f.diff(x)) .. image:: so4.png f = 1/tan(x); f 1/tan(x) f.diff(x) -(tan(x)^2 + 1)/tan(x)^2 show(f) .. image:: so5.png show(f.diff(x)) .. image:: so6.png
SymPy
The syntax for series expansion is: .series(var, point, order):
In [27]: from sympy import * In [28]: x = Symbol('x') In [29]: cos(x).series(x, 0, 14) Out[29]: 2 4 6 8 10 12 x x x x x x ⎛ 14⎞ 1 - ── + ── - ─── + ───── - ─────── + ───────── + O⎝x ⎠ 2 24 720 40320 3628800 479001600 In [30]: (1/cos(x**2)).series(x, 0, 14) Out[30]: 4 8 12 x 5⋅x 61⋅x ⎛ 14⎞ 1 + ── + ──── + ────── + O⎝x ⎠ 2 24 720
It is possible to make use of series(x*cos(x), x) by creating a wrapper around Basic.series().:
In [31]: from sympy import Symbol, cos, series In [32]: x = Symbol('x') In [33]: series(cos(x), x) Out[33]: 2 4 x x ⎛ 6⎞ 1 - ── + ── + O⎝x ⎠ 2 24
Sage
Series expansion can be used with the taylor(f, *args) function:
taylor(cos(x), x, 0, 14) -1/87178291200*x^14 + 1/479001600*x^12 - 1/3628800*x^10 + 1/40320*x^8 - 1/720*x^6 + 1/24*x^4 - 1/2*x^2 + 1 var('x, k') (x, k) taylor(sqrt (1 - k^2*sin(x)^2), x, 0, 6) -1/720*(45*k^6 - 60*k^4 + 16*k^2)*x^6 - 1/24*(3*k^4 - 4*k^2)*x^4 - 1/2*k^2*x^2 + 1
SymPy
The integrals module in SymPy implements methods calculating definite and undefinite integrals of expressions. Principal method in this module is integrate()
- integrate(f, x) returns the indefinite integral
- integrate(f, (x, a, b)) returns the definite integral
SymPy can integrate:
-
polynomial funtions:
In [6]: from sympy import * In [7]: import sys In [8]: sys.displayhook = pprint In [9]: x = Symbol('x') In [10]: integrate(x**2 + 2*x + 4, x) 3 x 2 ── + x + 4⋅x 3
-
rational funtions:
In [1]: integrate((x+1)/(x**2+4*x+4), x) Out[1]: 1 log(x + 2) + ───── x + 2
-
exponential-polynomial functions:
In [5]: integrate(5*x**2 * exp(x) * sin(x), x) Out[5]: 2 x 2 x x x 5⋅x ⋅ℯ ⋅sin(x) 5⋅x ⋅ℯ ⋅cos(x) x 5⋅ℯ ⋅sin(x) 5⋅ℯ ⋅cos(x) ────────────── - ────────────── + 5⋅x⋅ℯ ⋅cos(x) - ─────────── - ────────── 2 2 2 2
-
non-elementary integrals:
In [11]: integrate(exp(-x**2)*erf(x), x) ___ 2 ╲╱ π ⋅erf (x) ───────────── 4
Here is an example of a definite integral (Calculate [int_0^{pi/2} x^2cos{x},dx]):
In [1]: integrate(x**2 * cos(x), (x, 0, pi/2)) Out[1]: 2 π -2 + ── 4
Sage
Sage can integrate some simple functions on its own
-
polynomial functions:
f = x^2 + 2*x + 4 # ** and ^ represent the same thing f.integral(x) 1/3*x^3 + x^2 + 4*x
-
rational functions:
f = (x+1)/(x^2 + 4*x + 4) f.integral(x) 1/(x + 2) + log(x + 2)
-
exponential-polynomial functions:
f = 5*x^2 * exp(x) * sin(x) f.integral(x) 5/2*(x^2 - 1)*e^x*sin(x) - 5/2*(x^2 - 2*x + 1)*e^x*cos(x)
-
non-elementary integrals:
f = exp(-x**2)*erf(x) f.integral(x) 1/4*sqrt(pi)*erf(x)^2
The output of (int_0^{pi/2} x^2cos{x},dx) in Sage is:
f = x^2 * cos(x) f.integral(x, 0, pi/2) 1/4*pi^2 - 2
SymPy
In [1]: from sympy import Symbol, exp, I In [2]: x = Symbol("x") In [3]: exp(I*2*x).expand() Out[3]: 2⋅ⅈ⋅x ℯ In [4]: exp(I*2*x).expand(complex=True) Out[4]: -2⋅im(x) -2⋅im(x) ⅈ⋅ℯ ⋅sin(2⋅re(x)) + ℯ ⋅cos(2⋅re(x)) In [5]: x = Symbol("x", real=True) In [6]: exp(I*2*x).expand(complex=True) Out[6]: ⅈ⋅sin(2⋅x) + cos(2⋅x)
Sage
This is an example of a complex number in Sage:
C = ComplexField() I = C.0 b = 1.5 + 2.5*I loads(b.dumps()) == b True
SymPy
trigonometric
In [1]: cos(x-y).expand(trig=True) Out[1]: sin(x)⋅sin(y) + cos(x)⋅cos(y) In [2]: cos(2*x).expand(trig=True) Out[2]: 2 2⋅cos (x) - 1 In [3]: sinh(I*x**2) Out[3]: ⎛ 2⎞ ⅈ⋅sin⎝x ⎠
zeta function
In [4]: zeta(5, x**2) Out[4]: ⎛ 2⎞ ζ⎝5, x ⎠ In [5]: zeta(5, 2) Out[5]: ζ(5, 2) In [6]: zeta(4, 1) Out[6]: 4 π ── 90
factorials and gamma function
In [7]: a = Symbol('a') In [8]: b = Symbol('b', integer=True) In [9]: factorial(a) Out[9]: a! In [13]: gamma(b+2).series(b, 0, 3) Out[13]: 2 2 2 2 π ⋅b EulerGamma ⋅b 2 ⎛ 3⎞ 1 + b - EulerGamma⋅b + ───── + ────────────── - EulerGamma⋅b + O⎝b ⎠ 12 2
polynomials
In [14]: chebyshevt(8,x) Out[14]: 8 6 4 2 128⋅x - 256⋅x + 160⋅x - 32⋅x + 1 In [15]: legendre(3, x) Out[15]: 3 5⋅x 3⋅x ──── - ─── 2 2 In [16]: hermite(3, x**2) Out[16]: 6 2 8⋅x - 12⋅x
Sage
trigonometric
(cos(90)+sin(30)).n(100) -1.4361052402220319423532262217 (cos(3) + tan(3)).n(5) -1.1
zeta function
The example below returns the Riemann zeta function evaluated at a complex number:
i = ComplexField(30).gen() z = 1 + i z.zeta() 0.58215805981 - 0.92684856430*I zeta(z) 0.58215805981 - 0.92684856430*I
factorials and gamma function
The factorial(*args, coerce=True, hold=False, dont_call_method_on_arg=False) function return the factorial of n (the output is an integer or a symbolic expression).
x = var('x') factorial(10) 3628800
The gamma() function is used for other nonnegative numbers that are not integers:
factorial(3/4) gamma(7/4) factorial(2.3) 2.68343738195577
These examples return the Gamma function and the incomplete form of it, evaluated for a complex number:
i = ComplexField(30).0 (1+i).gamma() 0.49801566824 - 0.15494982828*I C, i = ComplexField(30).objgen() (1+i).gamma_inc(2 + 3*i) 0.0020969148645 - 0.059981913655*I
polynomials
x = polygen(QQ, 'x') chebyshev_U(2, x) 4*x^2 - 1
Special functions like chebyshev or bessel have only numerical use in Sage. For symbolic use, the Maxima interface included in Sage must be used directly:
maxima.eval("f:bessel_y(v, w)") 'bessel_y(v,w)'
SymPy
In isympy:
In [10]: f(x).diff(x, x) + f(x) Out[10]: 2 d f(x) + ───(f(x)) 2 dx In [11]: dsolve(f(x).diff(x, x) + f(x), f(x)) Out[11]: f(x) = C₁⋅sin(x) + C₂⋅cos(x)
Sage
You can use Sage to investigate ordinary differential equations. To solve the equation x'+x-1=0:
t = var('t') x = function('x', t) d = diff(x, t) + x - 1 desolve(d, [x, t]) (c + e^t)*e^(-t)
SymPy
In isympy:
In [3]: solve(x**3 + 2*x**3 - 1, x) Out[3]: ⎡ 2/3 2/3 6 ___ 2/3 6 ___ ⎤ ⎢3 3 ╲╱ 3 ⋅ⅈ 3 ╲╱ 3 ⋅ⅈ ⎥ ⎢────, - ──── - ───────, - ──── + ───────⎥ ⎣ 3 6 2 6 2 ⎦ In [5]: solve( [x**2 + 4*y**2 -2, -10*x + 2*y -15], [x, y]) Out[5]: ⎡⎛ ____ ____ ⎞ ⎛ ____ ____ ⎞⎤ ⎢⎜ 150 ╲╱ 23 ⋅ⅈ 15 5⋅╲╱ 23 ⋅ⅈ ⎟ ⎜ 150 ╲╱ 23 ⋅ⅈ 15 5⋅╲╱ 23 ⋅ ⎟⎥ ⎢⎜- ─── - ────────, ─── - ──────────⎟, ⎜- ─── + ────────, ─── + ────────── ⎟⎥ ⎣⎝ 101 101 202 101 ⎠ ⎝ 101 101 202 101 ⎠⎦
Sage
The solve() function solves equations. To use it, you must specify some variables, then the argumens to solve are an equation (or a system of equations), together with the variables for which to solve. The function is the same as the solve() from SymPy:
x = var('x') solve(x^3 + 2*x^3 - 1, x) [x == 1/6*(I*sqrt(3) - 1)*3^(2/3), x == 1/6*(-I*sqrt(3) - 1)*3^(2/3), x == 1/3*3^(2/3)]
SymPy
In SymPy, matrices are created as instances from the Matrix class:
In [1]: from sympy import Matrix In [2]: Matrix([ [1, 0 , 0], [0, 1, 0], [0, 0, 1] ]) Out[2]: ⎡1 0 0⎤ ⎢ ⎥ ⎢0 1 0⎥ ⎢ ⎥ ⎣0 0 1⎦
It is possible to slice submatrices, since this is Python:
In [4]: M = Matrix(2, 3, [1, 2, 3, 4, 5, 6]) In [5]: M[0:2,0:2] Out[5]: ⎡1 2⎤ ⎢ ⎥ ⎣4 5⎦ In [6]: M[1:2,2] Out[6]: [6] In [7]: M[:,2] Out[7]: ⎡3⎤ ⎢ ⎥ ⎣6⎦
One basic operation involving matrices is the determinant:
In [8]: M = Matrix(( [2, 5, 6], [4, 7, 10], [1, 0, 3] )) In [9]: M.det() Out[9]: -10
print_nonzero(symb='x') shows location of non-zero entries for fast shape lookup.
In [10]: M = Matrix(( [2, 0, 0, 1, 0], [3, 5, 0, 1, 0], [10, 4, 0, 1, 2], [1, 6, 0, 0, 0], [0, 4, 0, 2, 2] )) In [12]: M Out[12]: ⎡2 0 0 1 0⎤ ⎢ ⎥ ⎢3 5 0 1 0⎥ ⎢ ⎥ ⎢10 4 0 1 2⎥ ⎢ ⎥ ⎢1 6 0 0 0⎥ ⎢ ⎥ ⎣0 4 0 2 2⎦ In [13]: M.print_nonzero() [X X ] [XX X ] [XX XX] [XX ] [ X XX]
Matrix transposition with transpose():
In [14]: from sympy import Matrix, I In [15]: m = Matrix(( (1,2+I), (3,4) )) In [16]: m Out[16]: ⎡1 2 + ⅈ⎤ ⎢ ⎥ ⎣3 4 ⎦ In [17]: m.transpose() Out[17]: ⎡ 1 3⎤ ⎢ ⎥ ⎣2 + ⅈ 4⎦ In [19]: m.T == m.transpose() Out[19]: True
Sage
Sage provides standard constructions from linear algebra:
A = Matrix([[1, 0 , 0], [0, 1, 0], [0, 0, 1]]) [1 0 0] [0 1 0] [0 0 1]
det(x) returns the determinant of x:
M = MatrixSpace(QQ, 3, 3) A = M([2, 5, 6, 4, 7, 10, 1, 0, 3]) det(A) -10
SymPy
The geometry module can be used to create two-dimensional geometrical entities and query information about them. These entities are available
- Point
- Line, Ray, Segment
- Ellipse, Circle
- Polygon, RegularPolygon, Triangle
-
Check if points are collinear:
In [37]: from sympy import * In [38]: from sympy.geometry import * In [39]: x = Point(0, 0) In [40]: y = Point(3, 1) In [41]: z = Point(5, 5) In [42]: Point.is_collinear(x, y, z) Out[42]: False In [43]: Point.is_collinear(x, z) Out[43]: True
-
Segment declaration, slope, length, midpoint:
In [1]: import sympy In [2]: from sympy import Point In [3]: from sympy.abc import s In [4]: from sympy.geometry import Segment In [5]: Segment( (1, 2), (2, -3)) Out[5]: ((1,), (2,)) In [6]: s = Segment(Point(4, 3), Point(1, 1)) In [7]: s Out[7]: ((1,), (4,)) In [8]: s.points Out[8]: ((1,), (4,)) In [9]: s.slope Out[9]: 2/3 In [10]: s.length Out[10]: ____ ╲╱ 13 In [11]: s.midpoint Out[11]: (5/2,)
Sage
The point(points, **kwds) function return either a 2d or 3d point or sum of points. Here are some examples
point([(1,2), (1,3), (2,2)])
point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True)
SymPy
Using the .match method and the Wild class you can perform pattern matching on expressions. The method returns a dictionary with the needed substitutions. Here is an example:
In [11]: from sympy import * In [12]: x = Symbol('x') In [13]: y = Wild('y') In [14]: (10*x**3).match(y*x**3) Out[14]: {y: 10} In [15]: s = Wild('s') In [16]: (x**4).match(y*x**s) Out[16]: {s: 4, y: 1}
SymPy returns None if the match is unsuccessful:
In [19]: print (x+1).match(y**x) None
Sage
The wild(n=0) function returns the n-th wild-card for pattern matching and substitution:
x,y = var('x,y') w0 = SR.wild(0); w1 = SR.wild(1) pattern = sin(x)*w0*w1^2; pattern $0*$1^2*sin(x) f = atan(sin(x)*3*x^2); f arctan(3*x^2*sin(x)) f.has(pattern) True f.subs(pattern == x^2) arctan(x^2)
SymPy
There are many ways of printing mathematical expressions. Two of the most common methods are:
* Standard printing * Pretty printing
Standard printing is the return value of str(expression):
>>> from sympy import Integral # Python session >>> from sympy.abc import c >>> print c**3 c**3 >>> print 2/c 2/c >>> print Integral(c**2+2*c, c) Integral(c**2 + 2*c, c)
Pretty printing is a nice ascii-art printing with the help of a pprint function:
In [1]: from sympy import Integral, pprint # IPython session (pprint enabled by default) In [2]: from sympy.abc import c In [3]: pprint(c**3) 3 c In [4]: pprint(2/c) 2 ─ c In [5]: pprint(Integral(c**2+2*c, c)) ⌠ ⎮ ⎛ 2 ⎞ ⎮ ⎝c + 2⋅c⎠ dc ⌡
Sage
- There are three common ways to print expressions in Sage::
-
- Standard printing
- The show() function
- Pretty printing
Standard printing in Sage is almost identical with the printing from SymPy (Note that there is no print() function in Sage):
c = var('c') c^3 2/c 2/c integrate(c**2+2*c, c) 1/3*c^3 + c^2
The show() function is the same as the pprint() function from SymPy:
f = x^(-2*x) f.integral(x, 1, +Infinity) integrate(x^(-2*x), x, 1, +Infinity) show(integrate(x^(-2*x), x, 1, +Infinity))
The pretty_print() function can be considered similar to the show() function, but the output is slightly different (pretty_print() displays the integral on one line, whereas show() displays it on three lines.):
pretty_print(integrate(x^(-2*x), x, 1, +Infinity))
SymPy
PyGlet is required to use the plotting function of SymPy in 2d and 3d. Here is an example:
>>> from sympy import symbols, Plot, cos, sin >>> x, y = symbols('x y') >>> Plot(sin(x*10)*cos(y*5) - x*y) [0]: -x*y + sin(10*x)*cos(5*y), 'mode=cartesian'
Sage
In Sage, you can produce filled-in shapes by creating a list of points (L in the example below) and then use the polygon command to plot the shape with boundary formed by those points. For example, here is a blue hypotrochoid. By typing *show(p, axes=false), you can see this without any axes. Note that it is possible to add text to a plot:
L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100),\ 6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] p = polygon(L, rgbcolor=(1/8,1/4,1/2)) t = text("hypotrochoid", (5,4), rgbcolor=(1,0,0)) show(p+t, axes=false)
The function sin(x)/x has the following plot:
plot(sin(x)/x, x, -100, 100).show(ymin=-1)
SymPy and Sage are trying to become nice open source alternatives to Maple/Mathematica. Their goal is to be reasonably fast, easily extended with your own ideas, be callable from Python and could be used in real world problems. SymPy uses a different approach to achieve this goal, because it aims to be a lightweight normal Python module, whereas Sage aims to glue together every useful open source mathematics software package (that is why SymPy is included in Sage by default since version 2.7) and provide a transparent interface to all of them. Another advantage of SymPy is that since it is written in pure Python (and doesn't need anything else), it is perfectly multiplatform, it's small and easy to install and use.
You can choose to use either SymPy or Sage, depending on what your needs are. For more information you can go to the official sites of Sympy and Sage.