SymPy

from Wikipedia, the free encyclopedia
SymPy

Sympy logo.svg
Basic data

Maintainer Community project initiated by Aaron Meurer
developer Aaron Meurer
Publishing year 2007
Current  version 1.6.2
( August 9, 2020 )
operating system Platform independence
programming language python
category Computer algebra system
License BSD license
sympy.org

SymPy is a Python - library for symbolic mathematical calculations. The computer algebra - functions are offered as

SymPy enables calculations and representations in the context of simple symbolic arithmetic up to differential and integral calculus as well as algebra , discrete mathematics and quantum physics . If desired, the results can be output in the text typesetting system language TeX .

SymPy is free software and is under the new BSD license . The leading developers are Ondřej Čertík and Aaron Meurer .

The SymPy library consists of a basic system that can be expanded with optional modules. The basic system, also known as the core, comprises around 260,000 lines of code. Of these, more than 100,000 lines are intended for extensive self-tests.

Skills

SymPy includes numerous math functions. The following overview shows the basic capabilities of the basic system as well as the possibility of modular extensions.

Basic system

Polynomials

Analytics

Solving equations

Discrete Math

matrix

geometry

  • Points, lines, rays, segments, ellipses, circles, polygons, ...
  • Intersections
  • Tangency
  • similarity

Graphical representation (plotting)

The Matplotlib or Pyglet library is required to graphically display the curves and diagrams . Otherwise there is the visualization of text-based using the installed in the system fonts .

  • Coordinate models
  • Geometric entities
  • two- and three-dimensional representation
  • Interactive interface
  • multicolored representations

physics

statistics

Combinatorics

Output formats

  • Source code formats: ASCII / Unicode pretty-printing , TeX
  • Program code: C , Fortran , Python

Performance improvement

  • Gmpy uses the SymPy polynomial module for faster soil types, which lead to a significant increase in the performance of certain calculations.

Examples

These examples can be interactive e.g. B. be executed in IDLE .

PrettyPrint formatting

>>>from sympy import pprint, Symbol, sin, exp, sqrt, series

>>>x = Symbol("20")

>>>#PPrint benutzt standardmäßig Unicodezeichen
>>>pprint( 10**exp(x),use_unicode=True)
   20
    
10

>>>#Gleiche Darstellung ohne Unicodes
>>>pprint( 10**exp(x),use_unicode=False)
  / 20\
  \e  /
10

>>>#Reihenentwicklung
>>>pprint((1/sin(x)).series(x, 0, 4))
              3
1    20   720       4
── + ── + ───── + O20 
20   6     360

>>>#Wurzel
>>>pprint(sqrt((10**x)))
   ______
     20
╲╱  10

Plotting

Sympy Plottingexample.png
>>> from sympy import symbols, cos,sin
>>> from sympy.plotting import plot3d

>>> x,y = symbols('x y')
>>> plot3d(sin(3*x)*cos(5*y)+y, (x, -2, 2), (y, -2, 2))

Multiplying out terms

from sympy import init_printing, Symbol, expand, pprint
init_printing()

a = Symbol('a')
b = Symbol('b')
e = (a + b)**5

pprint(e)
print("=")
pprint(e.expand())

Solving algebraic equations

from sympy.solvers import solve
from sympy import Symbol
x = Symbol('x')

print("Lösung von: x**2 - 1 = 0 ")
print(solve(x**2 - 1, x))

print("Lösung von: x**2 - 6*x + 9 = 0 ")
print(solve(x**2 - 6*x + 9, x))

Integrate

from sympy import *

init_printing()
x = Symbol('x')
pprint(integrate(x**2 + 7*x + 5, x))

Number theory

from sympy.ntheory import factorint
print("Primfaktorzerlegung der Zahl 2000 = (2**4) * (5**3) ")
print(factorint(2000))
print("65537 ist eine Primzahl")
print(factorint(65537))

print("Primzahlen im Bereich 60 bis 90 ausgeben")
from sympy import sieve
print([i for i in sieve.primerange(60, 90)])

Calculating with matrices

from sympy import *
M = Matrix(([1,2,3],[4,5,6],[7,8,10]))

print("Addition von Matrizen")
pprint(M+M)

print("Multiplikation von Matrizen")
pprint(M*M)

print("Determinante")
pprint(M.det())

print("inverse")
pprint(M.inv(method="LU"))

literature

Web links

Individual evidence

  1. Release 1.6.2 . August 9, 2020 (accessed August 16, 2020).
  2. ^ SymPy Live
  3. ^ SymPy Gamma
  4. a b About Sympy. Retrieved August 1, 2018 .
  5. ^ The SymPy Open Source Project on Open Hub. Retrieved August 3, 2018 .