sympy Getting started with sympy 'Hello World'


Example

Sympy is a Python library for doing symbolic — rather than numeric — calculations.

For instance, consider the quadratic equation in x,

x**2 + HELLO * x + WORLD = 0

where HELLO and WORLD are constants. What's the solution of this equation?

In Python, using Sympy we can code,

from sympy import symbols, solve, latex

x, HELLO, WORLD = symbols('x, HELLO, WORLD')
print ( latex ( solve ( x**2 + HELLO * x + WORLD, x ) ) )

Since I made a call to Latex the solutions are almost ready for publication! Sympy provides the two of them packed in a list. Here's one:

one solution

If you need to do more work on an expression then you would leave out the call to latex.