Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

SymPy: Python Symbolic Math Library for Research

SymPy in Python: install with pip or conda, create symbols, and derive and verify derivatives, integrals and limits with documented outputs.

Written and maintained by CASRAI Editorial Board

Last updated

SymPy is a Python library for symbolic mathematics (sympy.org). It manipulates formulas exactly, as expressions, instead of evaluating them to floating-point numbers. This page is for researchers who need to derive, simplify or check an equation in Python and want to know how to install SymPy, what its core functions return, and where it stops.

What SymPy is

The SymPy project describes itself as “a Python library for symbolic mathematics.” It is licensed under the BSD licence and, in the project’s words, “free both as in speech and as in beer.” Its only external dependency is mpmath, a library for arbitrary-precision arithmetic. The project site also links an online shell (live.sympy.org) for trying expressions without installing anything.

The practical difference from numerical libraries is the kind of answer you get back. A numerical routine returns a number for one set of inputs; a symbolic one returns a formula that holds for all of them. That makes SymPy useful for steps in a research workflow where the algebra itself is the result: a derivative to paste into a methods section, a closed-form integral, or a limit you want to check before coding a simulation.

Who runs it and what it covers

SymPy is an open-source project that publishes its documentation at docs.sympy.org. The official introductory tutorial is organised into Preliminaries, Introduction, Gotchas, and a features section covering Basic Operations, Printing, Simplification, Calculus, Solvers, Matrices and Advanced Expression Manipulation. The tutorial pages on calculus, solvers and expression manipulation are the ones most research users need first.

Install SymPy with pip or conda

The official installation page gives two routine routes. Use whichever matches how you already manage Python packages:

  • pip: pip install sympy
  • conda: conda install sympy (the page also lists Conda Forge)

The installation page also lists operating-system package managers such as apt and dnf, and states that SymPy “can be installed on virtually any computer that supports Python.” Because mpmath is required, pip and conda install it for you. The project’s home page still shows an older release number, so read the version from the documentation you are using (the current docs describe 1.14.0) and record it alongside your results.

Core functions: symbols, diff, integrate, limit, series

All examples below come from the official calculus tutorial. The setup is from sympy import * followed by x, y, z = symbols('x y z').

SymPy symbols

Python variables do not behave as mathematical unknowns by themselves. symbols('x y z') creates symbolic objects you can build expressions from; the tutorial has a “Gotchas” section to read before first use.

SymPy Derivative with diff

Differentiate with diff(expr, x). From the tutorial: diff(cos(x), x) returns -sin(x), and diff(x**4, x, 3) (the third derivative) returns 24*x. If you want an unevaluated derivative object, for example to display an equation before solving it, build Derivative(expr, x) and call .doit() to evaluate it.

Integrals

integrate(cos(x), x) returns sin(x). Definite integrals take a tuple: integrate(exp(-x), (x, 0, oo)) returns 1, and a double integral integrate(exp(-x**2 - y**2), (x, -oo, oo), (y, -oo, oo)) returns pi. Where no closed form is found the result stays unevaluated: the tutorial shows integrate(x**x, x) coming back as Integral(x**x, x).

Limits

limit(sin(x)/x, x, 0) returns 1. The tutorial also states that limit(x**2/exp(x), x, oo) returns 0 whereas substituting infinity with subs gives nan, so use limit rather than subs at singular points. One-sided limits take a direction: limit(1/x, x, 0, '+') returns oo and '-' returns -oo.

Series expansion

exp(sin(x)).series(x, 0, 4) returns 1 + x + x**2/2 + O(x**4); appending .removeO() drops the remainder term and gives x**2/2 + x + 1.

A derive-then-verify recipe for research work

The documented outputs above support a simple habit that guards against transcription errors in derivations:

  1. Declare symbols with symbols() and write the expression exactly as it appears in your derivation.
  2. Compute the derivative, integral, limit or series with the function that matches the operation.
  3. Compare the printed result with your hand derivation. If an integral comes back as an unevaluated Integral, treat that as “no closed form found by SymPy,” not as a result, and fall back to a numerical method.
  4. For behaviour at a singular point, use limit, not subs, as the tutorial warns.
  5. Record the SymPy version with the script so the check can be repeated.

Strengths and limits

  • Strength: free and permissively licensed. BSD licence, installed with one pip or conda command, with a single dependency (mpmath).
  • Strength: it lives in Python. Symbolic results sit in the same scripts as the rest of an analysis.
  • Limit: not every integral has a closed form it can find. The tutorial’s own x**x example stays unevaluated.
  • Limit: substitution is not a limit. subs(x, oo) can return nan where limit gives the answer.

SymPy also appears as a real-world codebase in software-engineering research: the original SWE-bench benchmark draws 386 of its 2,294 task instances from the SymPy repository, as covered in the SWE-bench guide.

Alternatives

Option What it is Where to read more
SymPy BSD-licensed Python library for symbolic mathematics; depends only on mpmath sympy.org, docs.sympy.org
SageMath Open-source mathematics software system, covered in a separate CASRAI guide SageMath: system architecture and research use
MATLAB Symbolic Math Toolbox Symbolic work in MATLAB, declared with syms MATLAB syms guide and MATLAB equation solver

FAQ

What is SymPy in Python?

SymPy is a free Python library for symbolic mathematics. You import it like any package and work with expressions instead of floating-point numbers.

How do I run pip install sympy?

Run pip install sympy; conda users run conda install sympy. Both bring in the mpmath dependency.

How do I create SymPy symbols?

Call symbols('x y z') and unpack the result into variables, as in the official tutorial.

How do I take a SymPy Derivative?

Use diff(expr, x), or build Derivative(expr, x) and call .doit(). For example diff(x**4, x, 3) returns 24*x.

Where can I find a SymPy tutorial or examples?

The official introductory tutorial at docs.sympy.org covers calculus, solvers, matrices and simplification with runnable examples.

Sources

  • SymPy project home page, sympy.org (read 2026-11-07).
  • SymPy documentation, Installation, docs.sympy.org/latest/install.html (read 2026-11-07).
  • SymPy documentation, Introductory Tutorial and Calculus page, docs.sympy.org/latest/tutorials/intro-tutorial/ (read 2026-11-07).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about SymPy: Python Symbolic Math Library for Research

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →