SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python.
SymPy only depends on mpmath, a pure Python library for arbitrary floating point arithmetic, making it easy to use.
Installing sympy module:
pip install sympy
SymPy as a calculator:
SymPy defines following numerical types: Rational and Integer. The Rational class represents a rational number as a pair of two Integers, numerator and denominator, so Rational(1, 2) represents 1/2, Rational(5, 2) 5/2 and so on. The Integer class represents Integer number.
Example #1 :
value of a is :5/8 value of b is :3
SymPy uses mpmath in the background, which makes it possible to perform computations using arbitrary-precision arithmetic. That way, some special constants, like exp, pi, oo (Infinity), are treated as symbols and can be evaluated with arbitrary precision.
Example #2 :
value of p is :pi^3 value of q is :3.14159265358979 value of r is :2.71828182845905 value of s is :5.85987448204884 value of rslt is :oo True
In contrast to other Computer Algebra Systems, in SymPy you have to declare symbolic variables explicitly using Symbol() method.
Example #3 :
value of z is :2*x
The real power of a symbolic computation system such as SymPy is the ability to do all sorts of computations symbolically. SymPy can simplify expressions, compute derivatives, integrals, and limits, solve equations, work with matrices, and much, much more, and do it all symbolically. Here is a small sampling of the sort of symbolic power SymPy is capable of, to whet your appetite.
Example #4 : Find derivative, integration, limits, quadratic equation.
derivative of sin(x)*e^x : exp(x)*sin(x) + exp(x)*cos(x) indefinite integration is : exp(x)*sin(x) definite integration is : sqrt(2)*sqrt(pi)/2 limit is : 1 roots are : [-sqrt(2), sqrt(2)]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Getting started with Jupyter Notebook | Python
- Python | Getting started with psycopg2-PostGreSQL
- Getting started with Python for Automated Trading
- Getting Started with Plotly-Python
- Getting Started With ImageIO Library in Python
- Getting Started With Testing in Python
- ML | Getting Started With AlexNet
- Getting started with PySoundFile
- Check if a Thread has started in Python
- How Should a Machine Learning Beginner Get Started on Kaggle?
- MySQL-Connector-Python module in Python
- twitter-text-python (ttp) module - Python
- Import module in Python
- OS Module in Python with Examples
- struct module in Python
- Fraction module in Python
- Secrets | Python module to Generate secure random numbers
- Python calendar module | formatmonth() method
- Python | Writing to an excel file using openpyxl module
- Count frequencies of all elements in array in Python using collections module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : kartikiyer2892