sympy

Perform exact symbolic mathematics in Python including algebra, calculus, equation solving, and code generation.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/ricfulop/cba-agentic-engineering-bootstrap --skill sympy-ricfulop
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sympy
Source: https://github.com/ricfulop/cba-agentic-engineering-bootstrap/tree/main/skills/sympy
Command: npx skills add https://github.com/ricfulop/cba-agentic-engineering-bootstrap --skill sympy-ricfulop

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires sympy, numpy, scipy, matplotlib, and includes references (resource) components.

What problem does it solve? Numerical libraries like NumPy return floating-point approximations, which lose exactness for tasks like solving equations analytically, computing symbolic derivatives and integrals, or simplifying algebraic expressions. This Skill provides guidance for using SymPy to compute exact mathematical results symbolically in Python. ## Core Features & Use Cases - Symbolic Algebra and Calculus: Simplify expressions, compute derivatives, integrals, limits, and series expansions with exact results like sqrt(2) instead of 1.414. - Equation Solving and Linear Algebra: Solve algebraic, differential, and systems of equations, plus matrix operations including eigenvalues, decompositions, and symbolic inverses. - Code Generation and Output: Convert symbolic expressions to fast NumPy functions via lambdify, generate C/Fortran code, and produce LaTeX output for documents. - Use Case: Derive the equations of motion for a pendulum symbolically using Lagrangian mechanics, then lambdify the result into a NumPy function for fast numerical simulation over thousands of timesteps. ## Quick Start Ask the AI to solve an equation or compute an integral symbolically with SymPy, for example: solve x^2 - 5x + 6 = 0 and then convert the result into a NumPy function with lambdify.

Frequently Asked Questions about sympy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I solve equations symbolically in Python?

Use SymPy's solveset for algebraic equations, linsolve for linear systems, nonlinsolve for nonlinear systems, and dsolve for differential equations. Define symbols first with symbols('x'), then call solveset(x**2 - 4, x) to get exact solutions like {-2, 2}.

When should I use SymPy instead of NumPy?

Use SymPy when you need exact symbolic results such as sqrt(2), analytical derivatives, or closed-form equation solutions. Prefer NumPy or SciPy when floating-point approximations are sufficient, since numerical libraries are far faster for large-scale computation.

How do I convert a SymPy expression to a fast numerical function?

Use lambdify to convert a symbolic expression into a NumPy-compatible function, for example f = lambdify(x, expr, 'numpy'). This avoids slow loops of subs() and evalf() and lets you evaluate the expression over entire NumPy arrays efficiently.

Why does SymPy give unexpected decimal results in my expression?

Writing 0.5 * x creates a floating-point approximation instead of an exact rational. Use Rational(1, 2) or S(1)/2 to keep arithmetic exact, and call evalf() only when you explicitly need a numerical value.

Can SymPy generate C or Fortran code from expressions?

Yes, sympy.utilities.codegen.codegen produces C or Fortran source from symbolic expressions, and autowrap compiles the result into a callable Python function. A C or Fortran compiler is required for autowrap and ufuncify workflows.

Is it safe to parse user input with SymPy parse_expr?

No, parse_expr uses eval internally and must never run on unsanitized input. Pass a local_dict of predefined symbols, restrict to standard_transformations, validate length and characters, and reject strings containing __, import, or assignment syntax.