Python SymPy — A Short Primer

What’s SymPy Anyway?

SymPy is a Python library for symbolic computation. So instead of approximating the result of the square root of 2, it keeps the square root intact—using a symbolic representation. This helps in further processing and can lead to situations where Python has introduced a floating point precision error without need. Here’s a basic example:

import sympy

print(sqrt(3))
# sqrt(3)

The result is NOT an approximated square root of 3 like in the math package:

import math

print(math.sqrt(3))
# 1.7320508075688772

An Interactive Example

You can try it yourself in the interactive code shell:

(Just click the image to create your own code!)

How to Install SymPy?

To install SymPy in Python,

Continue reading the original article