# SymPy — Computer Algebra System in Pure Python > SymPy performs symbolic mathematics in Python, handling algebra, calculus, equation solving, and more. It requires no external dependencies and runs anywhere Python runs. ## Install Save in your project root: # SymPy — Computer Algebra System in Pure Python ## Quick Use ```bash pip install sympy python -c " from sympy import symbols, diff, integrate, solve x = symbols('x') print(diff(x**3 + 2*x, x)) # 3*x**2 + 2 print(integrate(x**2, x)) # x**3/3 print(solve(x**2 - 4, x)) # [-2, 2] " ``` ## Introduction SymPy is a pure-Python library for symbolic mathematics. Unlike numerical libraries that compute with floating-point numbers, SymPy manipulates mathematical expressions symbolically — simplifying algebra, computing derivatives and integrals, solving equations, and generating LaTeX output, all without external dependencies. ## What SymPy Does - Performs symbolic differentiation, integration, and series expansion - Solves algebraic and differential equations symbolically - Simplifies, expands, and factors mathematical expressions - Computes limits, summations, and products in closed form - Generates LaTeX, MathML, and code output (C, Fortran, Python, Julia) ## Architecture Overview SymPy represents expressions as immutable tree structures where each node is a Python object (Symbol, Add, Mul, Pow, etc.). Operations build new trees rather than mutating existing ones. The library includes specialized modules for calculus, linear algebra, number theory, combinatorics, geometry, physics, and more. A code generation module (lambdify, codegen) bridges symbolic expressions to numerical evaluation via NumPy or compiled code. ## Self-Hosting & Configuration - Install via `pip install sympy` with zero external dependencies - Use `from sympy import *` for interactive exploration or import specific functions for scripts - Launch an enhanced interactive shell with `python -m sympy` (isympy) - Configure output with `init_printing()` for Unicode or LaTeX rendering in terminals and notebooks - Use `lambdify()` to convert symbolic expressions to fast NumPy-callable functions ## Key Features - Pure Python with no compiled dependencies — works on any platform including WebAssembly - Exact arithmetic with rational numbers, roots, and symbolic constants (pi, E, oo) - Matrix algebra with symbolic entries, eigenvalues, and Jordan form computation - Physics modules for classical mechanics, quantum mechanics, and optics - Code generation to C, Fortran, Julia, Rust, and optimized NumPy for production deployment ## Comparison with Similar Tools - **SciPy** — numerical computation with floating-point; SymPy gives exact symbolic answers - **Mathematica** — proprietary CAS with broader capabilities; SymPy is free and Python-native - **SageMath** — wraps multiple CAS engines; SymPy is lighter and embeddable in any Python project - **Maxima** — established open-source CAS in Lisp; SymPy integrates directly with the Python data science stack - **MATLAB Symbolic Toolbox** — proprietary add-on; SymPy provides equivalent functionality at no cost ## FAQ **Q: Is SymPy fast enough for large-scale computation?** A: SymPy is designed for symbolic work, not raw numerical speed. Use `lambdify()` to convert expressions to NumPy functions for fast numerical evaluation. **Q: Can SymPy replace Mathematica?** A: For many use cases, yes. SymPy handles core CAS operations. Some specialized Mathematica features may not have direct equivalents. **Q: How do I display equations in LaTeX?** A: Use `sympy.latex(expr)` to get the LaTeX string, or call `init_printing()` in Jupyter for automatic rendered output. **Q: Does SymPy work in Jupyter notebooks?** A: Yes. Call `init_printing()` at the start of your notebook for automatic LaTeX rendering of expressions. ## Sources - https://github.com/sympy/sympy - https://www.sympy.org/en/index.html --- Source: https://tokrepo.com/en/workflows/e1a21deb-40a1-11f1-9bc6-00163e2b0d79 Author: AI Open Source