SymPy

{{Short description|Python library for symbolic computation}}

{{distinguish|text=SimPy, a discrete-event simulation language}}

{{Infobox software

| name = SymPy

| logo = File:Sympy logo.svg

| developer = SymPy Development Team

| released = {{Start date and age|2007}}

| latest release version = 1.13.3{{cite web|url=https://github.com/sympy/sympy/releases|title=Releases - sympy/sympy|via=GitHub|accessdate=20 March 2025}}

| latest release date = {{Start date and age|2024|09|18|df=yes}}

| programming language = Python

| operating system = Cross-platform

| genre = Computer algebra system

| license = 3-clause BSD

}}

SymPy is an open-source Python library 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{{Cite web|title=SymPy Live|url=https://live.sympy.org/|access-date=2021-08-25|website=live.sympy.org}} or SymPy Gamma.{{Cite web|title=SymPy Gamma|url=https://www.sympygamma.com/|access-date=2021-08-25|website=www.sympygamma.com}} SymPy is simple to install and to inspect because it is written entirely in Python with few dependencies.{{cite web|url=http://sympy.org|title=SymPy homepage|accessdate=2014-10-13}}

{{cite journal

| last1 = Joyner

| first1 = David

| last2 = Čertík

| first2 = Ondřej

| last3 = Meurer

| first3 = Aaron

| last4 = Granger

| first4 = Brian E.

| year = 2012

| title = Open source computer algebra systems: SymPy

| journal = ACM Communications in Computer Algebra

| volume = 45

| issue = 3/4

| pages = 225–234

| doi = 10.1145/2110170.2110185

| s2cid = 44862851

}}{{Cite journal|last1=Meurer|first1=Aaron|last2=Smith|first2=Christopher P.|last3=Paprocki|first3=Mateusz|last4=Čertík|first4=Ondřej|last5=Kirpichev|first5=Sergey B.|last6=Rocklin|first6=Matthew|last7=Kumar|first7=AMiT|last8=Ivanov|first8=Sergiu|last9=Moore|first9=Jason K.|date=2017-01-02|title=SymPy: symbolic computing in Python|journal=PeerJ Computer Science|language=en|volume=3|pages=e103|doi=10.7717/peerj-cs.103|issn=2376-5992|url=http://dspace5.zcu.cz/bitstream/11025/29246/1/peerj-cs-103-1.pdf|doi-access=free}} 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 includes features ranging from basic symbolic arithmetic to calculus, algebra, discrete mathematics, and quantum physics. It is capable of formatting the result of the computations as LaTeX code.

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.{{Cite web|url=https://github.com/sympy/sympy/wiki/SymPy-vs.-Mathematica|title=SymPy vs. Mathematica · sympy/Sympy Wiki|website=GitHub}}

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{{cite web|url=https://www.openhub.net/p/sympy|title=Sympy project statistics on Open HUB|accessdate=2014-10-13}} (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:

{{cite conference

| last1 = Gede

| first1 = Gilbert

| last2 = Peterson

| first2 = Dale L.

| last3 = Nanjangud

| first3 = Angadh

| last4 = Moore

| first4 = Jason K.

| last5 = Hubbard

| first5 = Mont

| year = 2013

| title = Constrained multibody dynamics with Python: From symbolic equation generation to publication

| conference = ASME 2013 International Design Engineering Technical Conferences and Computers and Information in Engineering Conference

| pages = V07BT10A051

| publisher = American Society of Mechanical Engineers

| doi = 10.1115/DETC2013-13470

| url = http://proceedings.asmedigitalcollection.asme.org/proceeding.aspx?articleid=1830918

| isbn = 978-0-7918-5597-3

| url-access= subscription

}}

{{cite journal

| last1 = Rocklin

| first1 = Matthew

| last2 = Terrel

| first2 = Andy

| year = 2012

| title = Symbolic Statistics with SymPy

| journal = Computing in Science & Engineering

| volume = 14

| issue = 3

| pages = 88–93

| doi = 10.1109/MCSE.2012.56

| bibcode = 2012CSE....14c..88R

| s2cid = 18307629

}}

{{cite journal

| last1 = Asif

| first1 = Mushtaq

| last2 = Olaussen

| first2 = Kåre

| year = 2014

| title = Automatic code generator for higher order integrators

| journal = Computer Physics Communications

| volume = 185

| issue = 5

| pages = 1461–1472

| doi = 10.1016/j.cpc.2014.01.012

| arxiv= 1310.2111

| bibcode= 2014CoPhC.185.1461M

| s2cid = 42041635

}}

=Core capabilities=

=Polynomials=

=Calculus=

=Solving equations=

=Discrete math=

=Matrices=

=Geometry=

=Plotting=

Note, plotting requires the external Matplotlib or Pyglet module.

  • Coordinate models
  • Plotting Geometric Entities
  • 2D and 3D
  • Interactive interface
  • Colors
  • Animations

=Physics=

=Statistics=

=Combinatorics=

=Printing=

Related projects

  • SageMath: an open source alternative to Mathematica, Maple, MATLAB, and Magma (SymPy is included in Sage)
  • SymEngine: a rewriting of SymPy's core in C++, in order to increase its performance. Work is currently in progress{{As of?|date=August 2021}} to make SymEngine the underlying engine of Sage too.{{Cite web|title=GitHub - symengine/symengine: SymEngine is a fast symbolic manipulation library, written in C++|url=https://github.com/symengine/symengine|access-date=2021-08-25|website=GitHub|language=en}}
  • mpmath: a Python library for arbitrary-precision floating-point arithmetic{{Cite web|title=mpmath - Python library for arbitrary-precision floating-point arithmetic|url=https://mpmath.org/|access-date=2021-08-25|website=mpmath.org}}
  • SympyCore: another Python computer algebra system{{Cite web|title=GitHub - pearu/sympycore: Automatically exported from code.google.com/p/sympycore|url=https://github.com/pearu/sympycore|access-date=2021-08-25|website=GitHub|date=January 2021|language=en}}
  • SfePy: Software for solving systems of coupled partial differential equations (PDEs) by the finite element method in 1D, 2D and 3D.{{Cite web|last=Developers|first=SfePy|title=SfePy: Simple Finite Elements in Python — SfePy version: 2021.2+git.13ca95f1 documentation|url=http://sfepy.org/doc-devel/index.html|access-date=2021-08-25|website=sfepy.org|language=en}}
  • GAlgebra: Geometric algebra module (previously {{Not a typo|sympy.galgebra}}).{{Cite web|title=GitHub - pygae/galgebra: Symbolic Geometric Algebra/Calculus package for SymPy|url=https://github.com/pygae/galgebra|access-date=2021-08-25|website=GitHub|language=en}}
  • Quameon: Quantum Monte Carlo in Python.{{Cite web|title=Quameon - Quantum Monte Carlo in Python|url=http://quameon.sourceforge.net/|access-date=2021-08-25|website=quameon.sourceforge.net}}
  • Lcapy: Experimental Python package for teaching linear circuit analysis.{{Cite web|date=2021-01-16|title=Welcome to Lcapy's documentation! — Lcapy 0.76 documentation|url=http://lcapy.elec.canterbury.ac.nz/|access-date=2021-08-25|archive-url=https://web.archive.org/web/20210116185108/http://lcapy.elec.canterbury.ac.nz/|archive-date=2021-01-16}}
  • LaTeX Expression project: Easy LaTeX typesetting of algebraic expressions in symbolic form with automatic substitution and result computation.{{Cite web|title=LaTeX Expression project documentation — LaTeX Expression 0.3.dev documentation|url=http://mech.fsv.cvut.cz/~stransky/software/latexexpr/doc/|access-date=2021-08-25|website=mech.fsv.cvut.cz}}
  • Symbolic statistical modeling: Adding statistical operations to complex physical models.{{Cite web|title=Symbolic Statistics with SymPy|url=https://www.researchgate.net/publication/260585491|access-date=2021-08-25|website=ResearchGate|language=en}}
  • Diofant: a fork of SymPy, started by Sergey B Kirpichev{{Cite web|title=Diofant's documentation — Diofant 0.13.0a4.dev13+g8c5685115 documentation|url=https://diofant.readthedocs.io/en/latest/|access-date=2021-08-25|website=diofant.readthedocs.io}}

Dependencies

Since version 1.0, SymPy has the mpmath package as a dependency.

There are several optional dependencies that can enhance its capabilities:

  • {{Not a typo|gmpy}}: If {{Not a typo|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.
  • Pyglet: Alternative plotting package.

See also

{{Portal|Free and open-source software|Mathematics}}

References

{{Reflist}}