Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Features  



1.1  Core capabilities  





1.2  Polynomials  





1.3  Calculus  





1.4  Solving equations  





1.5  Discrete math  





1.6  Matrices  





1.7  Geometry  





1.8  Plotting  





1.9  Physics  





1.10  Statistics  





1.11  Combinatorics  





1.12  Printing  







2 Related projects  





3 Dependencies  





4 Usage examples  



4.1  Pretty-printing  





4.2  Expansion  





4.3  Arbitrary-precision example  





4.4  Differentiation  





4.5  Plotting  





4.6  Limits  





4.7  Differential equations  





4.8  Integration  





4.9  Series  





4.10  Logical reasoning  



4.10.1  Example 1  





4.10.2  Example 2  









5 See also  





6 References  





7 External links  














SymPy






Català
Deutsch
Español
Français

Português
Русский
Српски / srpski
Türkçe

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


SymPy
Developer(s)SymPy Development Team
Initial release2007; 17 years ago (2007)
Stable release

1.12[1] / 10 May 2023; 14 months ago (2023-05-10)

Repository
Written inPython
Operating systemCross-platform
TypeComputer algebra system
LicenseNew BSD License
Websitewww.sympy.org Edit this on Wikidata

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[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 includes features ranging from basic symbolic arithmetictocalculus, algebra, discrete mathematics, and quantum physics. It is capable of formatting the result of the computations as LaTeX code.[4][5]

SymPy is free software and is licensed under the New BSD license. The lead developers are Ondřej Čertík and Aaron Meurer. It was started in 2005 by Ondřej Čertík.[7]

Features

[edit]

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]

Core capabilities

[edit]

Polynomials

[edit]

Calculus

[edit]

Solving equations

[edit]

Discrete math

[edit]

Matrices

[edit]

Geometry

[edit]

Plotting

[edit]

Note, plotting requires the external MatplotliborPyglet module.

Physics

[edit]

Statistics

[edit]

Combinatorics

[edit]

Printing

[edit]
[edit]

Dependencies

[edit]

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

There are several optional dependencies that can enhance its capabilities:

Usage examples

[edit]

Pretty-printing

[edit]

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.

>>> from sympy import pprint, 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

Expansion

[edit]
>>> from sympy import init_printing, Symbol, expand
>>> init_printing()
>>>
>>> a = Symbol("a")
>>> b = Symbol("b")
>>> e = (a + b) ** 3
>>> e
(a + b)³
>>> e.expand()
a³ + 3⋅a²⋅b + 3⋅a⋅b²  + b³

Arbitrary-precision example

[edit]
>>> from sympy import Rational, pprint
>>> e = 2**50 / Rational(10) ** 50
>>> pprint(e)
1/88817841970012523233890533447265625

Differentiation

[edit]
>>> from sympy import init_printing, symbols, ln, diff
>>> init_printing()
>>> x, y = symbols("x y")
>>> f = x**2 / y + 2 * x - ln(y)
>>> diff(f, x)
 2⋅x    
 ─── + 2
y
>>> diff(f, y)
2
   x    1
 - ── - ─
    2   y
y
>>> diff(diff(f, x), y)
 -2⋅x
 ────
2
y

Plotting

[edit]
Output of the plotting example
>>> from sympy import symbols, cos
>>> from sympy.plotting import plot3d
>>> x, y = symbols("x y")
>>> plot3d(cos(x * 3) * cos(y * 5) - y, (x, -1, 1), (y, -1, 1))
<sympy.plotting.plot.Plot object at 0x3b6d0d0>

Limits

[edit]
>>> from sympy import init_printing, Symbol, limit, sqrt, oo
>>> init_printing()
>>> 
>>> x = Symbol("x")
>>> limit(sqrt(x**2 - 5 * x + 6) - x, x, oo)
-5/2
>>> limit(x * (sqrt(x**2 + 1) - x), x, oo)
1/2
>>> limit(1 / x**2, x, 0)

>>> limit(((x - 1) / (x + 1)) ** x, x, oo)
 -2

Differential equations

[edit]
>>> from sympy import init_printing, Symbol, Function, Eq, dsolve, sin, diff
>>> init_printing()
>>>
>>> x = Symbol("x")
>>> f = Function("f")
>>>
>>> eq = Eq(f(x).diff(x), f(x))
>>> eq
d
──(f(x)) = f(x)
dx
>>>    
>>> dsolve(eq, f(x))
x
f(x) = C₁⋅ℯ

>>>
>>> eq = Eq(x**2 * f(x).diff(x), -3 * x * f(x) + sin(x) / x)
>>> eq
 2 d                      sin(x)
x ⋅──(f(x)) = -3⋅x⋅f(x) + ──────
   dx                       x   
>>>
>>> dsolve(eq, f(x))
C₁ - cos(x)
f(x) = ───────────   

Integration

[edit]
>>> from sympy import init_printing, integrate, Symbol, exp, cos, erf
>>> init_printing()
>>> x = Symbol("x")
>>> # Polynomial Function
>>> f = x**2 + x + 1
>>> f
2
x  + x + 1
>>> integrate(f, x)
 3    2    
x    x     
── + ── + x
3    2     
>>> # Rational Function
>>> f = x / (x**2 + 2 * x + 1)
>>> f
x
────────────
2
x  + 2⋅x + 1

>>> integrate(f, x)
1
log(x + 1) + ─────
             x + 1
>>> # Exponential-polynomial functions
>>> f = x**2 * exp(x) * cos(x)
>>> f
 2  x       
x ⋅ℯ ⋅cos(x)
>>> integrate(f, x)
 2  x           2  x                         x           x       
x ⋅ℯ ⋅sin(x)   x ⋅ℯ ⋅cos(x)      x          ℯ ⋅sin(x)   ℯ ⋅cos(x)
──────────── + ──────────── - x⋅ℯ ⋅sin(x) + ───────── - ─────────
     2              2                           2           2    
>>> # A non-elementary integral
>>> f = exp(-(x**2)) * erf(x)
>>> f
2
 -x        
ℯ   ⋅erf(x)
>>> integrate(f, x)

  ___    2   
╲╱ π ⋅erf (x)
─────────────
4

Series

[edit]
>>> from sympy import Symbol, cos, sin, pprint
>>> x = Symbol("x")
>>> e = 1 / cos(x)
>>> pprint(e)
1
──────
cos(x)
>>> pprint(e.series(x, 0, 10))
     2      4       6        8         
    x    5⋅x    61⋅x    277⋅x     ⎛ 10⎞
1 + ── + ──── + ───── + ────── + O⎝x  ⎠
    2     24     720     8064          
>>> e = 1/sin(x)
>>> pprint(e)
1
──────
sin(x)
>>> pprint(e.series(x, 0, 4))
3
1   x   7⋅x     ⎛ 4⎞
─ + ─ + ──── + O⎝x ⎠
x   6   360

Logical reasoning

[edit]

Example 1

[edit]
>>> from sympy import *
>>> x = Symbol("x")
>>> y = Symbol("y")
>>> facts = Q.positive(x), Q.positive(y)
>>> with assuming(*facts):
...     print(ask(Q.positive(2 * x + y)))
True

Example 2

[edit]
>>> from sympy import *
>>> x = Symbol("x")
>>> # Assumption about x
>>> fact = [Q.prime(x)]
>>> with assuming(*fact):
...     print(ask(Q.rational(1 / x)))
True

See also

[edit]

References

[edit]
  1. ^ "Releases - sympy/sympy". Retrieved 6 September 2022 – via GitHub.
  • ^ "SymPy Live". live.sympy.org. Retrieved 2021-08-25.
  • ^ "SymPy Gamma". www.sympygamma.com. Retrieved 2021-08-25.
  • ^ a b c "SymPy homepage". Retrieved 2014-10-13.
  • ^ a b c Joyner, David; Čertík, Ondřej; Meurer, Aaron; Granger, Brian E. (2012). "Open source computer algebra systems: SymPy". ACM Communications in Computer Algebra. 45 (3/4): 225–234. doi:10.1145/2110170.2110185. S2CID 44862851.
  • ^ Meurer, Aaron; Smith, Christopher P.; Paprocki, Mateusz; Čertík, Ondřej; Kirpichev, Sergey B.; Rocklin, Matthew; Kumar, AMiT; Ivanov, Sergiu; Moore, Jason K. (2017-01-02). "SymPy: symbolic computing in Python" (PDF). PeerJ Computer Science. 3: e103. doi:10.7717/peerj-cs.103. ISSN 2376-5992.
  • ^ "SymPy vs. Mathematica · sympy/Sympy Wiki". GitHub.
  • ^ "Sympy project statistics on Open HUB". Retrieved 2014-10-13.
  • ^ Gede, Gilbert; Peterson, Dale L.; Nanjangud, Angadh; Moore, Jason K.; Hubbard, Mont (2013). Constrained multibody dynamics with Python: From symbolic equation generation to publication. ASME 2013 International Design Engineering Technical Conferences and Computers and Information in Engineering Conference. American Society of Mechanical Engineers. pp. V07BT10A051. doi:10.1115/DETC2013-13470. ISBN 978-0-7918-5597-3.
  • ^ Rocklin, Matthew; Terrel, Andy (2012). "Symbolic Statistics with SymPy". Computing in Science & Engineering. 14 (3): 88–93. Bibcode:2012CSE....14c..88R. doi:10.1109/MCSE.2012.56. S2CID 18307629.
  • ^ Asif, Mushtaq; Olaussen, Kåre (2014). "Automatic code generator for higher order integrators". Computer Physics Communications. 185 (5): 1461–1472. arXiv:1310.2111. Bibcode:2014CoPhC.185.1461M. doi:10.1016/j.cpc.2014.01.012. S2CID 42041635.
  • ^ "Assumptions Module — SymPy 1.4 documentation". docs.sympy.org. Retrieved 2019-07-05.
  • ^ "Continuum Mechanics — SymPy 1.4 documentation". docs.sympy.org. Retrieved 2019-07-05.
  • ^ "GitHub - symengine/symengine: SymEngine is a fast symbolic manipulation library, written in C++". GitHub. Retrieved 2021-08-25.
  • ^ "mpmath - Python library for arbitrary-precision floating-point arithmetic". mpmath.org. Retrieved 2021-08-25.
  • ^ "GitHub - pearu/sympycore: Automatically exported from code.google.com/p/sympycore". GitHub. January 2021. Retrieved 2021-08-25.
  • ^ Developers, SfePy. "SfePy: Simple Finite Elements in Python — SfePy version: 2021.2+git.13ca95f1 documentation". sfepy.org. Retrieved 2021-08-25.
  • ^ "GitHub - pygae/galgebra: Symbolic Geometric Algebra/Calculus package for SymPy". GitHub. Retrieved 2021-08-25.
  • ^ "Quameon - Quantum Monte Carlo in Python". quameon.sourceforge.net. Retrieved 2021-08-25.
  • ^ "Welcome to Lcapy's documentation! — Lcapy 0.76 documentation". 2021-01-16. Archived from the original on 2021-01-16. Retrieved 2021-08-25.
  • ^ "LaTeX Expression project documentation — LaTeX Expression 0.3.dev documentation". mech.fsv.cvut.cz. Retrieved 2021-08-25.
  • ^ "Symbolic Statistics with SymPy". ResearchGate. Retrieved 2021-08-25.
  • ^ "Diofant's documentation — Diofant 0.13.0a4.dev13+g8c5685115 documentation". diofant.readthedocs.io. Retrieved 2021-08-25.
  • [edit]
    Retrieved from "https://en.wikipedia.org/w/index.php?title=SymPy&oldid=1203824488"

    Categories: 
    Computer algebra system software for Linux
    Computer algebra system software for macOS
    Computer algebra system software for Windows
    Free computer algebra systems
    Free mathematics software
    Free software programmed in Python
    Python (programming language) scientific libraries
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
    All articles with vague or ambiguous time
    Vague or ambiguous time from August 2021
    Articles with example Python (programming language) code
     



    This page was last edited on 5 February 2024, at 17:42 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki