J u m p t o c o n t e n t
M a i n m e n u
M a i n m e n u
N a v i g a t i o n
● M a i n p a g e
● C o n t e n t s
● C u r r e n t e v e n t s
● R a n d o m a r t i c l e
● A b o u t W i k i p e d i a
● C o n t a c t u s
● D o n a t e
C o n t r i b u t e
● H e l p
● L e a r n t o e d i t
● C o m m u n i t y p o r t a l
● R e c e n t c h a n g e s
● U p l o a d f i l e
S e a r c h
Search
A p p e a r a n c e
● C r e a t e a c c o u n t
● L o g i n
P e r s o n a l t o o l s
● C r e a t e a c c o u n t
● L o g i n
P a g e s f o r l o g g e d o u t e d i t o r s l e a r n m o r e
● C o n t r i b u t i o n s
● T a l k
( T o p )
1
F e a t u r e s
T o g g l e F e a t u r e s s u b s e c t i o n
1 . 1
C o r e c a p a b i l i t i e s
1 . 2
P o l y n o m i a l s
1 . 3
C a l c u l u s
1 . 4
S o l v i n g e q u a t i o n s
1 . 5
D i s c r e t e m a t h
1 . 6
M a t r i c e s
1 . 7
G e o m e t r y
1 . 8
P l o t t i n g
1 . 9
P h y s i c s
1 . 1 0
S t a t i s t i c s
1 . 1 1
C o m b i n a t o r i c s
1 . 1 2
P r i n t i n g
2
R e l a t e d p r o j e c t s
3
D e p e n d e n c i e s
4
U s a g e e x a m p l e s
T o g g l e U s a g e e x a m p l e s s u b s e c t i o n
4 . 1
P r e t t y - p r i n t i n g
4 . 2
E x p a n s i o n
4 . 3
A r b i t r a r y - p r e c i s i o n e x a m p l e
4 . 4
D i f f e r e n t i a t i o n
4 . 5
P l o t t i n g
4 . 6
L i m i t s
4 . 7
D i f f e r e n t i a l e q u a t i o n s
4 . 8
I n t e g r a t i o n
4 . 9
S e r i e s
4 . 1 0
L o g i c a l r e a s o n i n g
4 . 1 0 . 1
E x a m p l e 1
4 . 1 0 . 2
E x a m p l e 2
5
S e e a l s o
6
R e f e r e n c e s
7
E x t e r n a l l i n k s
T o g g l e t h e t a b l e o f c o n t e n t s
S y m P y
1 0 l a n g u a g e s
● C a t a l à
● D e u t s c h
● E s p a ñ o l
● F r a n ç a i s
● 日 本 語
● P o r t u g u ê s
● Р у с с к и й
● С р п с к и / s r p s k i
● T ü r k ç e
● 中 文
E d i t l i n k s
● A r t i c l e
● T a l k
E n g l i s h
● R e a d
● E d i t
● V i e w h i s t o r y
T o o l s
T o o l s
A c t i o n s
● R e a d
● E d i t
● V i e w h i s t o r y
G e n e r a l
● W h a t l i n k s h e r e
● R e l a t e d c h a n g e s
● U p l o a d f i l e
● S p e c i a l p a g e s
● P e r m a n e n t l i n k
● P a g e i n f o r m a t i o n
● C i t e t h i s p a g e
● G e t s h o r t e n e d U R L
● D o w n l o a d Q R c o d e
● W i k i d a t a i t e m
P r i n t / e x p o r t
● D o w n l o a d a s P D F
● P r i n t a b l e v e r s i o n
I n o t h e r p r o j e c t s
● W i k i m e d i a C o m m o n s
A p p e a r a n c e
F r o m W i k i p e d i a , t h e f r e e e n c y c l o p e d i a
Python library for symbolic computation
Not to be confused with
SimPy , a discrete-event simulation language.
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 arithmetic to calculus , 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 ]
Basic arithmetic: *, /, +, -, **
Simplification
Expansion
Functions : trigonometric , hyperbolic , exponential , roots , logarithms , absolute value , spherical harmonics , factorials and gamma functions , zeta functions , polynomials , hypergeometric , special functions, etc.
Substitution
Arbitrary precision integers , rationals and floats
Noncommutative symbols
Pattern matching
Polynomials
[ edit ]
Calculus
[ edit ]
Solving equations
[ edit ]
Discrete math
[ edit ]
Matrices
[ edit ]
Geometry
[ edit ]
Plotting
[ edit ]
Note, plotting requires the external Matplotlib or Pyglet module.
Coordinate models
Plotting Geometric Entities
2D and 3D
Interactive interface
Colors
Animations
Physics
[ edit ]
Statistics
[ edit ]
Combinatorics
[ edit ]
Printing
[ edit ]
[ edit ]
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? ] to make SymEngine the underlying engine of Sage too.[14]
mpmath: a Python library for arbitrary-precision floating-point arithmetic [15]
SympyCore: another Python computer algebra system[16]
SfePy: Software for solving systems of coupled partial differential equations (PDEs) by the finite element method in 1D, 2D and 3D.[17]
GAlgebra: Geometric algebra module (previously sympy.galgebra).[18]
Quameon: Quantum Monte Carlo in Python.[19]
Lcapy: Experimental Python package for teaching linear circuit analysis .[20]
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
[ edit ]
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.
Pyglet : Alternative plotting package.
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 ) = ───────────
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 ]
^ "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 .
External links
[ edit ]
R e t r i e v e d f r o m " https://en.wikipedia.org/w/index.php?title=SymPy&oldid=1203824488 "
C a t e g o r i e s :
● C o m p u t e r a l g e b r a s y s t e m s o f t w a r e f o r L i n u x
● C o m p u t e r a l g e b r a s y s t e m s o f t w a r e f o r m a c O S
● C o m p u t e r a l g e b r a s y s t e m s o f t w a r e f o r W i n d o w s
● F r e e c o m p u t e r a l g e b r a s y s t e m s
● F r e e m a t h e m a t i c s s o f t w a r e
● F r e e s o f t w a r e p r o g r a m m e d i n P y t h o n
● P y t h o n ( p r o g r a m m i n g l a n g u a g e ) s c i e n t i f i c l i b r a r i e s
H i d d e n c a t e g o r i e s :
● A r t i c l e s w i t h s h o r t d e s c r i p t i o n
● S h o r t d e s c r i p t i o n i s d i f f e r e n t f r o m W i k i d a t a
● A l l a r t i c l e s w i t h v a g u e o r a m b i g u o u s t i m e
● V a g u e o r a m b i g u o u s t i m e f r o m A u g u s t 2 0 2 1
● A r t i c l e s w i t h e x a m p l e P y t h o n ( p r o g r a m m i n g l a n g u a g e ) c o d e
● T h i s p a g e w a s l a s t e d i t e d o n 5 F e b r u a r y 2 0 2 4 , a t 1 7 : 4 2 ( U T C ) .
● T e x t i s a v a i l a b l e u n d e r t h e C r e a t i v e C o m m o n s A t t r i b u t i o n - S h a r e A l i k e L i c e n s e 4 . 0 ;
a d d i t i o n a l t e r m s m a y a p p l y . B y u s i n g t h i s s i t e , y o u a g r e e t o t h e T e r m s o f U s e a n d P r i v a c y P o l i c y . W i k i p e d i a ® i s a r e g i s t e r e d t r a d e m a r k o f t h e W i k i m e d i a F o u n d a t i o n , I n c . , a n o n - p r o f i t o r g a n i z a t i o n .
● P r i v a c y p o l i c y
● A b o u t W i k i p e d i a
● D i s c l a i m e r s
● C o n t a c t W i k i p e d i a
● C o d e o f C o n d u c t
● D e v e l o p e r s
● S t a t i s t i c s
● C o o k i e s t a t e m e n t
● M o b i l e v i e w