sympy

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

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill sympy-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sympy
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/sympy
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill sympy-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Numerical libraries return approximations, but many scientific and engineering tasks require exact symbolic results like sqrt(2) instead of 1.414. This Skill guides symbolic computation with SymPy so equations, integrals, and matrix operations produce exact mathematical answers. ## Core Features & Use Cases - Symbolic Algebra and Calculus: Simplify expressions, compute derivatives, integrals, limits, and series expansions with exact arithmetic. - Equation Solving and Linear Algebra: Solve algebraic, differential, and systems of equations, plus matrix operations, eigenvalues, and decompositions. - Physics and Code Generation: Model classical mechanics and quantum systems, then convert expressions to NumPy functions, C/Fortran code, or LaTeX output. - Use Case: Derive the equations of motion for a pendulum symbolically using Lagrangian mechanics, then lambdify the result into a fast NumPy function for simulation. ## Quick Start Use the sympy skill to solve the equation x^2 - 5x + 6 = 0 symbolically and verify the solutions.

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 pass the equation and variable to the appropriate solver.

How to compute derivatives and integrals with SymPy?

Use diff(expr, x) for derivatives and integrate(expr, x) for indefinite integrals, or integrate(expr, (x, a, b)) for definite ones. SymPy returns exact symbolic results like x**3/3 rather than decimal approximations.

SymPy vs NumPy: when should I use each?

SymPy provides exact symbolic results for algebra and calculus, while NumPy handles fast numerical arrays. A common pattern is deriving expressions symbolically in SymPy, then using lambdify to convert them into NumPy functions for high-performance evaluation.

Why does SymPy give wrong results with decimal numbers?

Writing 0.5*x creates a floating-point approximation instead of an exact value. Use Rational(1, 2) or S(1)/2 for exact rational arithmetic so simplification and solving remain precise.

Why is SymPy slow when evaluating expressions in a loop?

Repeatedly calling subs() and evalf() is slow because each call runs symbolic machinery. Convert the expression once with lambdify(x, expr, 'numpy') to get a compiled numerical function that evaluates arrays quickly.

Can SymPy generate C or Fortran code from expressions?

Yes, sympy.utilities.codegen.codegen produces C and Fortran source from symbolic expressions, and autowrap compiles them into callable Python functions. The latex() function also generates LaTeX output for documentation.