SymPy is an open-sourcePythonlibrary for symbolic computation. It provides computer algebra capabilities either as a standalone application, as a library to other applications, or live on the web as SymPy Live[2] or SymPy Gamma.[3] SymPy is simple to install and to inspect because it is written entirely in Python with few dependencies.[4][5][6] This ease of access combined with a simple and extensible code base in a well known language make SymPy a computer algebra system with a relatively low barrier to entry.
SymPy is free software and is licensed under the 3-clause BSD. The lead developers are Ondřej Čertík and Aaron Meurer. It was started in 2005 by Ondřej Čertík.[7]
Features
The SymPy library is split into a core with many optional modules.
Currently, the core of SymPy has around 260,000 lines of code[8] (it also includes a comprehensive set of self-tests: over 100,000 lines in 350 files as of version 0.7.5), and its capabilities include:[4][5][9][10][11]
SymEngine: a rewriting of SymPy's core in C++, in order to increase its performance. Work is currently in progress[as of?] to make SymEngine the underlying engine of Sage too.[14]
LaTeX Expression project: Easy LaTeX typesetting of algebraic expressions in symbolic form with automatic substitution and result computation.[21]
Symbolic statistical modeling: Adding statistical operations to complex physical models.[22]
Diofant: a fork of SymPy, started by Sergey B Kirpichev[23]
Dependencies
Since version 1.0, SymPy has the mpmath package as a dependency.
There are several optional dependencies that can enhance its capabilities:
gmpy: If gmpy is installed, SymPy's polynomial module will automatically use it for faster ground types. This can provide a several times boost in performance of certain operations.
matplotlib: If matplotlib is installed, SymPy can use it for plotting.
Sympy allows outputs to be formatted into a more appealing format through the pprint function. Alternatively, the init_printing() method will enable pretty-printing, so pprint need not be called. Pretty-printing will use unicode symbols when available in the current environment, otherwise it will fall back to ASCII characters.
>>> fromsympyimportpprint,init_printing,Symbol,sin,cos,exp,sqrt,series,Integral,Function>>>>>> x=Symbol("x")>>> y=Symbol("y")>>> f=Function("f")>>> # pprint will default to unicode if available>>> pprint(x**exp(x)) ⎛ x⎞ ⎝ℯ ⎠x >>> # An output without unicode>>> pprint(Integral(f(x),x),use_unicode=False) / | | f(x) dx | / >>> # Compare with same expression but this time unicode is enabled>>> pprint(Integral(f(x),x),use_unicode=True)⌠ ⎮ f(x) dx⌡ >>> # Alternatively, you can call init_printing() once and pretty-print without the pprint function.>>> init_printing()>>> sqrt(sqrt(exp(x))) ____4 ╱ x ╲╱ ℯ >>> (1/cos(x)).series(x,0,10) 2 4 6 8 x 5⋅x 61⋅x 277⋅x ⎛ 10⎞1 + ── + ──── + ───── + ────── + O⎝x ⎠ 2 24 720 8064