跳到主要内容
SkillVault logo SkillVault
免费 ChatGPT GPTs Claude Code Cursor

sympy

Use this skill when working with symbolic mathematics in Python. This skill should be used for symbolic computation tasks including solving equations algebraically, performing calculus operations (derivatives, integrals, limits), manipulating algebraic expressions, working with matrices symbolically, physics calculations, number theory problems, geometry computations, and generating executable code from mathematical expressions. Apply this skill when the user needs exact symbolic results rather than numerical approximations, or when working with mathematical formulas that contain variables and parameters.

0 次下载 0 次浏览 更新于 Oct 31, 2026 v1.0.0
sympy skill cover

下方技能配置(提示词、变量、安装步骤)保留英文原文。.aiskill 文件直接面向 AI 智能体,统一使用英文以确保跨平台行为一致。

概述

Use this skill when working with symbolic mathematics in Python. This skill should be used for symbolic computation tasks including solving equations algebraically, performing calculus operations (derivatives, integrals, limits), manipulating algebraic expressions, working with matrices symbolically, physics calculations, number theory problems, geometry computations, and generating executable code from mathematical expressions. Apply this skill when the user needs exact symbolic results rather than numerical approximations, or when working with mathematical formulas that contain variables and parameters.

Source: https://github.com/DenDen047/claude-scientific-skills · HTTPS://GITHUB.COM/SYMPY/SYMPY/BLOB/MASTER/LICENSE · © 2025 K-Dense Inc.

系统提示词

定义智能体角色、规则与输出格式的指令块。

system-prompt.txt
# SymPy - Symbolic Mathematics in Python

## Overview

SymPy is a Python library for symbolic mathematics that enables exact computation using mathematical symbols rather than numerical approximations. This skill provides comprehensive guidance for performing symbolic algebra, calculus, linear algebra, equation solving, physics calculations, and code generation using SymPy.

## When to Use This Skill

Use this skill when:
- Solving equations symbolically (algebraic, differential, systems of equations)
- Performing calculus operations (derivatives, integrals, limits, series)
- Manipulating and simplifying algebraic expressions
- Working with matrices and linear algebra symbolically
- Doing physics calculations (mechanics, quantum mechanics, vector analysis)
- Number theory computations (primes, factorization, modular arithmetic)
- Geometric calculations (2D/3D geometry, analytic geometry)
- Converting mathematical expressions to executable code (Python, C, Fortran)
- Generating LaTeX or other formatted mathematical output
- Needing exact mathematical results (e.g., `sqrt(2)` not `1.414...`)

## Core Capabilities

### 1. Symbolic Computation Basics

**Creating symbols and expressions:**
```python
from sympy import symbols, Symbol
x, y, z = symbols('x y z')
expr = x**2 + 2*x + 1

# With assumptions
x = symbols('x', real=True, positive=True)
n = symbols('n', integer=True)
```

**Simplification and manipulation:**
```python
from sympy import simplify, expand, factor, cancel
simplify(sin(x)**2 + cos(x)**2)  # Returns 1
expand((x + 1)**3)  # x**3 + 3*x**2 + 3*x + 1
factor(x**2 - 1)    # (x - 1)*(x + 1)
```

**For detailed basics:** See `references/core-capabilities.md`

### 2. Calculus

**Derivatives:**
```python
from sympy import diff
diff(x**2, x)        # 2*x
diff(x**4, x, 3)     # 24*x (third derivative)
diff(x**2*y**3, x, y)  # 6*x*y**2 (partial derivatives)
```

**Integrals:**
```python
from sympy import integrate, oo
integrate(x**2, x)              # x**3/3 (indefinite)
integrate(x**2, (x, 0, 1))      # 1/3 (definite)
integrate(exp(-x), (x, 0, oo))  # 1 (improper)
```

**Limits and Series:**
```python
from sympy import limit, series
limit(sin(x)/x, x, 0)  # 1
series(exp(x), x, 0, 6)  # 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
```

**For detailed calculus operations:** See `references/core-capabilities.md`

### 3. Equation Solving

**Algebraic equations:**
```python
from sympy import solveset, solve, Eq
solveset(x**2 - 4, x)  # {-2, 2}
solve(Eq(x**2, 4), x)  # [-2, 2]
```

**Systems of equations:**
```python
from sympy import linsolve, nonlinsolve
linsolve([x + y - 2, x - y], x, y)  # {(1, 1)} (linear)
nonlinsolve([x**2 + y - 2, x + y**2 - 3], x, y)  # (nonlinear)
```

**Differential equations:**
```python
from sympy import Function, dsolve, Derivative
f = symbols('f', cls=Function)
dsolve(Derivative(f(x), x) - f(x), f(x))  # Eq(f(x), C1*exp(x))
```

**For detailed solving methods:** See `references/core-capabilities.md`

### 4. Matrices and Linear Algebra

**Matrix creation and operations:**
```python
from sympy import Matrix, eye, zeros
M = Matrix([[1, 2], [3, 4]])
M_inv = M**-1  # Inverse
M.det()        # Determinant
M.T            # Transpose
```

**Eigenvalues and eigenvectors:**
```python
eigenvals = M.eigenvals()  # {eigenvalue: multiplicity}
eigenvects = M.eigenvects()  # [(eigenval, mult, [eigenvectors])]
P, D = M.diagonalize()  # M = P*D*P^-1
```

**Solving linear systems:**
```python
A = Matrix([[1, 2], [3, 4]])
b = Matrix([5, 6])
x = A.solve(b)  # Solve Ax = b
```

**For comprehensive linear algebra:** See `references/matrices-linear-algebra.md`

### 5. Physics and Mechanics

**Classical mechanics:**
```python
from sympy.physics.mechanics import dynamicsymbols, LagrangesMethod
from sympy import symbols

# Define system
q = dynamicsymbols('q')
m, g, l = symbols('m g l')

# Lagrangian (T - V)
L = m*(l*q.diff())**2/2 - m*g*l*(1 - cos(q))

# Apply Lagrange's method
LM = LagrangesMethod(L, [q])
```

**Vector analysis:**
```python
from sympy.physics.vector import ReferenceFrame, dot, cross
N = ReferenceFrame('N')
v1 = 3*N.x + 4*N.y
v2 = 1*N.x + 2*N.z
dot(v1, v2)  # Dot product
cross(v1, v2)  # Cross product
```

**Quantum mechanics:**
```python
from sympy.physics.quantum import Ket, Bra, Commutator
psi = Ket('psi')
A = Operator('A')
comm = Commutator(A, B).doit()
```

**For detailed physics capabilities:** See `references/physics-mechanics.md`

### 6. Advanced Mathematics

The skill includes comprehensive support for:

- **Geometry:** 2D/3D analytic geometry, points, lines, circles, polygons, transformations
- **Number Theory:** Primes, factorization, GCD/LCM, modular arithmetic, Diophantine equations
- **Combinatorics:** Permutations, combinations, partitions, group theory
- **Logic and Sets:** Boolean logic, set theory, finite and infinite sets
- **Statistics:** Probability distributions, random variables, expectation, variance
- **Special Functions:** Gamma, Bessel, orthogonal polynomials, hypergeometric functions
- **Polynomials:** Polynomial algebra, roots, factorization, Groebner bases

**For detailed advanced topics:** See `references/advanced-topics.md`

### 7. Code Generation and Output

**Convert to executable functions:**
```python
from sympy import lambdify
import numpy as np

expr = x**2 + 2*x + 1
f = lambdify(x, expr, 'numpy')  # Create NumPy function
x_vals = np.linspace(0, 10, 100)
y_vals = f(x_vals)  # Fast numerical evaluation
```

**Generate C/Fortran code:**
```python
from sympy.utilities.codegen import codegen
[(c_name, c_code), (h_name, h_header)] = codegen(
    ('my_func', expr), 'C'
)
```

**LaTeX output:**
```python
from sympy import latex
latex_str = latex(expr)  # Convert to LaTeX for documents
```

**For comprehensive code generation:** See `references/code-generation-printing.md`

## Working with SymPy: Best Practices

### 1. Always Define Symbols First

```python
from sympy import symbols
x, y, z = symbols('x y z')
# Now x, y, z can be used in expressions
```

### 2. Use Assumptions for Better Simplification

```python
x = symbols('x', positive=True, real=True)
sqrt(x**2)  # Returns x (not Abs(x)) due to positive assumption
```

Common assumptions: `real`, `positive`, `negative`, `integer`, `rational`, `complex`, `even`, `odd`

### 3. Use Exact Arithmetic

```python
from sympy import Rational, S
# Correct (exact):
expr = Rational(1, 2) * x
expr = S(1)/2 * x

# Incorrect (floating-point):
expr = 0.5 * x  # Creates approximate value
```

### 4. Numerical Evaluation When Needed

```python
from sympy import pi, sqrt
result = sqrt(8) + pi
result.evalf()    # 5.96371554103586
result.evalf(50)  # 50 digits of precision
```

### 5. Convert to NumPy for Performance

```python
# Slow for many evaluations:
for x_val in range(1000):
    result = expr.subs(x, x_val).evalf()

# Fast:
f = lambdify(x, expr, 'numpy')
results = f(np.arange(1000))
```

### 6. Use Appropriate Solvers

- `solveset`: Algebraic equations (primary)
- `linsolve`: Linear systems
- `nonlinsolve`: Nonlinear systems
- `dsolve`: Differential equations
- `solve`: General purpose (legacy, but flexible)

## Reference Files Structure

This skill uses modular reference files for different capabilities:

1. **`core-capabilities.md`**: Symbols, algebra, calculus, simplification, equation solving
   - Load when: Basic symbolic computation, calculus, or solving equations

2. **`matrices-linear-algebra.md`**: Matrix operations, eigenvalues, linear systems
   - Load when: Working with matrices or linear algebra problems

3. **`physics-mechanics.md`**: Classical mechanics, quantum mechanics, vectors, units
   - Load when: Physics calculations or mechanics problems

4. **`advanced-topics.md`**: Geometry, number theory, combinatorics, logic, statistics
   - Load when: Advanced mathematical topics beyond basic algebra and calculus

5. **`code-generation-printing.md`**: Lambdify, codegen, LaTeX output, printing
   - Load when: Converting expressions to code or generating formatted output

## Common Use Case Patterns

### Pattern 1: Solve and Verify

```python
from sympy import symbols, solve, simplify
x = symbols('x')

# Solve equation
equation = x**2 - 5*x + 6
solutions = solve(equation, x)  # [2, 3]

# Verify solutions
for sol in solutions:
    result = simplify(equation.subs(x, sol))
    assert result == 0
```

### Pattern 2: Symbolic to Numeric Pipeline

```python
# 1. Define symbolic problem
x, y = symbols('x y')
expr = sin(x) + cos(y)

# 2. Manipulate symbolically
simplified = simplify(expr)
derivative = diff(simplified, x)

# 3. Convert to numerical function
f = lambdify((x, y), derivative, 'numpy')

# 4. Evaluate numerically
results = f(x_data, y_data)
```

### Pattern 3: Document Mathematical Results

```python
# Compute result symbolically
integral_expr = Integral(x**2, (x, 0, 1))
result = integral_expr.doit()

# Generate documentation
print(f"LaTeX: {latex(integral_expr)} = {latex(result)}")
print(f"Pretty: {pretty(integral_expr)} = {pretty(result)}")
print(f"Numerical: {result.evalf()}")
```

## Integration with Scientific Workflows

### With NumPy

```python
import numpy as np
from sympy import symbols, lambdify

x = symbols('x')
expr = x**2 + 2*x + 1

f = lambdify(x, expr, 'numpy')
x_array = np.linspace(-5, 5, 100)
y_array = f(x_array)
```

### With Matplotlib

```python
import matplotlib.pyplot as plt
import numpy as np
from sympy import symbols, lambdify, sin

x = symbols('x')
expr = sin(x) / x

f = lambdify(x, expr, 'numpy')
x_vals = np.linspace(-10, 10, 1000)
y_vals = f(x_vals)

plt.plot(x_vals, y_vals)
plt.show()
```

### With SciPy

```python
from scipy.optimize import fsolve
from sympy import symbols, lambdify

# Define equation symbolically
x = symbols('x')
equation = x**3 - 2*x - 5

# Convert to numerical function
f = lambdify(x, equation, 'numpy')

# Solve numerically with initial guess
solution = fsolve(f, 2)
```

## Quick Reference: Most Common Functions

```python
# Symbols
from sympy import symbols, Symbol
x, y = symbols('x y')

# Basic operations
from sympy import simplify, expand, factor, collect, cancel
from sympy import sqrt, exp, log, sin, cos, tan, pi, E, I, oo

# Calculus
from sympy import diff, integrate, limit, series, Derivative, Integral

# Solving
from sympy import solve, solveset, linsolve, nonlinsolve, dsolve

# Matrices
from sympy import Matrix, eye, zeros, ones, diag

# Logic and sets
from sympy import And, Or, Not, Implies, FiniteSet, Interval, Union

# Output
from sympy import latex, pprint, lambdify, init_printing

# Utilities
from sympy import evalf, N, nsimplify
```

## Getting Started Examples

### Example 1: Solve Quadratic Equation
```python
from sympy import symbols, solve, sqrt
x = symbols('x')
solution = solve(x**2 - 5*x + 6, x)
# [2, 3]
```

### Example 2: Calculate Derivative
```python
from sympy import symbols, diff, sin
x = symbols('x')
f = sin(x**2)
df_dx = diff(f, x)
# 2*x*cos(x**2)
```

### Example 3: Evaluate Integral
```python
from sympy import symbols, integrate, exp
x = symbols('x')
integral = integrate(x * exp(-x**2), (x, 0, oo))
# 1/2
```

### Example 4: Matrix Eigenvalues
```python
from sympy import Matrix
M = Matrix([[1, 2], [2, 1]])
eigenvals = M.eigenvals()
# {3: 1, -1: 1}
```

### Example 5: Generate Python Function
```python
from sympy import symbols, lambdify
import numpy as np
x = symbols('x')
expr = x**2 + 2*x + 1
f = lambdify(x, expr, 'numpy')
f(np.array([1, 2, 3]))
# array([ 4,  9, 16])
```

## Troubleshooting Common Issues

1. **"NameError: name 'x' is not defined"**
   - Solution: Always define symbols using `symbols()` before use

2. **Unexpected numerical results**
   - Issue: Using floating-point numbers like `0.5` instead of `Rational(1, 2)`
   - Solution: Use `Rational()` or `S()` for exact arithmetic

3. **Slow performance in loops**
   - Issue: Using `subs()` and `evalf()` repeatedly
   - Solution: Use `lambdify()` to create a fast numerical function

4. **"Can't solve this equation"**
   - Try different solvers: `solve`, `solveset`, `nsolve` (numerical)
   - Check if the equation is solvable algebraically
   - Use numerical methods if no closed-form solution exists

5. **Simplification not working as expected**
   - Try different simplification functions: `simplify`, `factor`, `expand`, `trigsimp`
   - Add assumptions to symbols (e.g., `positive=True`)
   - Use `simplify(expr, force=True)` for aggressive simplification

## Additional Resources

- Official Documentation: https://docs.sympy.org/
- Tutorial: https://docs.sympy.org/latest/tutorials/intro-tutorial/index.html
- API Reference: https://docs.sympy.org/latest/reference/index.html
- Examples: https://github.com/sympy/sympy/tree/master/examples

用户提示词模板

填充变量后发送,即可运行该技能: {{variables}}

user-template.txt

变量

名称 必填 说明 示例

完整技能配置

标准 .aiskill 文件,提供 JSON 与 YAML 两种格式。

sympy.aiskill (JSON)
{
  "format": "aiskill/v1",
  "skill": {
    "name": "sympy",
    "slug": "sympy",
    "version": "1.0.0",
    "description": "Use this skill when working with symbolic mathematics in Python. This skill should be used for symbolic computation tasks including solving equations algebraically, performing calculus operations (derivatives, integrals, limits), manipulating algebraic expressions, working with matrices symbolically, physics calculations, number theory problems, geometry computations, and generating executable code from mathematical expressions. Apply this skill when the user needs exact symbolic results rather than numerical approximations, or when working with mathematical formulas that contain variables and parameters.",
    "category": "Research",
    "tags": [
      "research-science",
      "python"
    ],
    "platforms": [
      "chatgpt",
      "claude-code",
      "cursor"
    ],
    "tested_environment": "Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and compatible agents",
    "license": "HTTPS://GITHUB.COM/SYMPY/SYMPY/BLOB/MASTER/LICENSE"
  },
  "prompts": {
    "system": "# SymPy - Symbolic Mathematics in Python\r\n\r\n## Overview\r\n\r\nSymPy is a Python library for symbolic mathematics that enables exact computation using mathematical symbols rather than numerical approximations. This skill provides comprehensive guidance for performing symbolic algebra, calculus, linear algebra, equation solving, physics calculations, and code generation using SymPy.\r\n\r\n## When to Use This Skill\r\n\r\nUse this skill when:\r\n- Solving equations symbolically (algebraic, differential, systems of equations)\r\n- Performing calculus operations (derivatives, integrals, limits, series)\r\n- Manipulating and simplifying algebraic expressions\r\n- Working with matrices and linear algebra symbolically\r\n- Doing physics calculations (mechanics, quantum mechanics, vector analysis)\r\n- Number theory computations (primes, factorization, modular arithmetic)\r\n- Geometric calculations (2D/3D geometry, analytic geometry)\r\n- Converting mathematical expressions to executable code (Python, C, Fortran)\r\n- Generating LaTeX or other formatted mathematical output\r\n- Needing exact mathematical results (e.g., `sqrt(2)` not `1.414...`)\r\n\r\n## Core Capabilities\r\n\r\n### 1. Symbolic Computation Basics\r\n\r\n**Creating symbols and expressions:**\r\n```python\r\nfrom sympy import symbols, Symbol\r\nx, y, z = symbols('x y z')\r\nexpr = x**2 + 2*x + 1\r\n\r\n# With assumptions\r\nx = symbols('x', real=True, positive=True)\r\nn = symbols('n', integer=True)\r\n```\r\n\r\n**Simplification and manipulation:**\r\n```python\r\nfrom sympy import simplify, expand, factor, cancel\r\nsimplify(sin(x)**2 + cos(x)**2)  # Returns 1\r\nexpand((x + 1)**3)  # x**3 + 3*x**2 + 3*x + 1\r\nfactor(x**2 - 1)    # (x - 1)*(x + 1)\r\n```\r\n\r\n**For detailed basics:** See `references/core-capabilities.md`\r\n\r\n### 2. Calculus\r\n\r\n**Derivatives:**\r\n```python\r\nfrom sympy import diff\r\ndiff(x**2, x)        # 2*x\r\ndiff(x**4, x, 3)     # 24*x (third derivative)\r\ndiff(x**2*y**3, x, y)  # 6*x*y**2 (partial derivatives)\r\n```\r\n\r\n**Integrals:**\r\n```python\r\nfrom sympy import integrate, oo\r\nintegrate(x**2, x)              # x**3/3 (indefinite)\r\nintegrate(x**2, (x, 0, 1))      # 1/3 (definite)\r\nintegrate(exp(-x), (x, 0, oo))  # 1 (improper)\r\n```\r\n\r\n**Limits and Series:**\r\n```python\r\nfrom sympy import limit, series\r\nlimit(sin(x)/x, x, 0)  # 1\r\nseries(exp(x), x, 0, 6)  # 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)\r\n```\r\n\r\n**For detailed calculus operations:** See `references/core-capabilities.md`\r\n\r\n### 3. Equation Solving\r\n\r\n**Algebraic equations:**\r\n```python\r\nfrom sympy import solveset, solve, Eq\r\nsolveset(x**2 - 4, x)  # {-2, 2}\r\nsolve(Eq(x**2, 4), x)  # [-2, 2]\r\n```\r\n\r\n**Systems of equations:**\r\n```python\r\nfrom sympy import linsolve, nonlinsolve\r\nlinsolve([x + y - 2, x - y], x, y)  # {(1, 1)} (linear)\r\nnonlinsolve([x**2 + y - 2, x + y**2 - 3], x, y)  # (nonlinear)\r\n```\r\n\r\n**Differential equations:**\r\n```python\r\nfrom sympy import Function, dsolve, Derivative\r\nf = symbols('f', cls=Function)\r\ndsolve(Derivative(f(x), x) - f(x), f(x))  # Eq(f(x), C1*exp(x))\r\n```\r\n\r\n**For detailed solving methods:** See `references/core-capabilities.md`\r\n\r\n### 4. Matrices and Linear Algebra\r\n\r\n**Matrix creation and operations:**\r\n```python\r\nfrom sympy import Matrix, eye, zeros\r\nM = Matrix([[1, 2], [3, 4]])\r\nM_inv = M**-1  # Inverse\r\nM.det()        # Determinant\r\nM.T            # Transpose\r\n```\r\n\r\n**Eigenvalues and eigenvectors:**\r\n```python\r\neigenvals = M.eigenvals()  # {eigenvalue: multiplicity}\r\neigenvects = M.eigenvects()  # [(eigenval, mult, [eigenvectors])]\r\nP, D = M.diagonalize()  # M = P*D*P^-1\r\n```\r\n\r\n**Solving linear systems:**\r\n```python\r\nA = Matrix([[1, 2], [3, 4]])\r\nb = Matrix([5, 6])\r\nx = A.solve(b)  # Solve Ax = b\r\n```\r\n\r\n**For comprehensive linear algebra:** See `references/matrices-linear-algebra.md`\r\n\r\n### 5. Physics and Mechanics\r\n\r\n**Classical mechanics:**\r\n```python\r\nfrom sympy.physics.mechanics import dynamicsymbols, LagrangesMethod\r\nfrom sympy import symbols\r\n\r\n# Define system\r\nq = dynamicsymbols('q')\r\nm, g, l = symbols('m g l')\r\n\r\n# Lagrangian (T - V)\r\nL = m*(l*q.diff())**2/2 - m*g*l*(1 - cos(q))\r\n\r\n# Apply Lagrange's method\r\nLM = LagrangesMethod(L, [q])\r\n```\r\n\r\n**Vector analysis:**\r\n```python\r\nfrom sympy.physics.vector import ReferenceFrame, dot, cross\r\nN = ReferenceFrame('N')\r\nv1 = 3*N.x + 4*N.y\r\nv2 = 1*N.x + 2*N.z\r\ndot(v1, v2)  # Dot product\r\ncross(v1, v2)  # Cross product\r\n```\r\n\r\n**Quantum mechanics:**\r\n```python\r\nfrom sympy.physics.quantum import Ket, Bra, Commutator\r\npsi = Ket('psi')\r\nA = Operator('A')\r\ncomm = Commutator(A, B).doit()\r\n```\r\n\r\n**For detailed physics capabilities:** See `references/physics-mechanics.md`\r\n\r\n### 6. Advanced Mathematics\r\n\r\nThe skill includes comprehensive support for:\r\n\r\n- **Geometry:** 2D/3D analytic geometry, points, lines, circles, polygons, transformations\r\n- **Number Theory:** Primes, factorization, GCD/LCM, modular arithmetic, Diophantine equations\r\n- **Combinatorics:** Permutations, combinations, partitions, group theory\r\n- **Logic and Sets:** Boolean logic, set theory, finite and infinite sets\r\n- **Statistics:** Probability distributions, random variables, expectation, variance\r\n- **Special Functions:** Gamma, Bessel, orthogonal polynomials, hypergeometric functions\r\n- **Polynomials:** Polynomial algebra, roots, factorization, Groebner bases\r\n\r\n**For detailed advanced topics:** See `references/advanced-topics.md`\r\n\r\n### 7. Code Generation and Output\r\n\r\n**Convert to executable functions:**\r\n```python\r\nfrom sympy import lambdify\r\nimport numpy as np\r\n\r\nexpr = x**2 + 2*x + 1\r\nf = lambdify(x, expr, 'numpy')  # Create NumPy function\r\nx_vals = np.linspace(0, 10, 100)\r\ny_vals = f(x_vals)  # Fast numerical evaluation\r\n```\r\n\r\n**Generate C/Fortran code:**\r\n```python\r\nfrom sympy.utilities.codegen import codegen\r\n[(c_name, c_code), (h_name, h_header)] = codegen(\r\n    ('my_func', expr), 'C'\r\n)\r\n```\r\n\r\n**LaTeX output:**\r\n```python\r\nfrom sympy import latex\r\nlatex_str = latex(expr)  # Convert to LaTeX for documents\r\n```\r\n\r\n**For comprehensive code generation:** See `references/code-generation-printing.md`\r\n\r\n## Working with SymPy: Best Practices\r\n\r\n### 1. Always Define Symbols First\r\n\r\n```python\r\nfrom sympy import symbols\r\nx, y, z = symbols('x y z')\r\n# Now x, y, z can be used in expressions\r\n```\r\n\r\n### 2. Use Assumptions for Better Simplification\r\n\r\n```python\r\nx = symbols('x', positive=True, real=True)\r\nsqrt(x**2)  # Returns x (not Abs(x)) due to positive assumption\r\n```\r\n\r\nCommon assumptions: `real`, `positive`, `negative`, `integer`, `rational`, `complex`, `even`, `odd`\r\n\r\n### 3. Use Exact Arithmetic\r\n\r\n```python\r\nfrom sympy import Rational, S\r\n# Correct (exact):\r\nexpr = Rational(1, 2) * x\r\nexpr = S(1)/2 * x\r\n\r\n# Incorrect (floating-point):\r\nexpr = 0.5 * x  # Creates approximate value\r\n```\r\n\r\n### 4. Numerical Evaluation When Needed\r\n\r\n```python\r\nfrom sympy import pi, sqrt\r\nresult = sqrt(8) + pi\r\nresult.evalf()    # 5.96371554103586\r\nresult.evalf(50)  # 50 digits of precision\r\n```\r\n\r\n### 5. Convert to NumPy for Performance\r\n\r\n```python\r\n# Slow for many evaluations:\r\nfor x_val in range(1000):\r\n    result = expr.subs(x, x_val).evalf()\r\n\r\n# Fast:\r\nf = lambdify(x, expr, 'numpy')\r\nresults = f(np.arange(1000))\r\n```\r\n\r\n### 6. Use Appropriate Solvers\r\n\r\n- `solveset`: Algebraic equations (primary)\r\n- `linsolve`: Linear systems\r\n- `nonlinsolve`: Nonlinear systems\r\n- `dsolve`: Differential equations\r\n- `solve`: General purpose (legacy, but flexible)\r\n\r\n## Reference Files Structure\r\n\r\nThis skill uses modular reference files for different capabilities:\r\n\r\n1. **`core-capabilities.md`**: Symbols, algebra, calculus, simplification, equation solving\r\n   - Load when: Basic symbolic computation, calculus, or solving equations\r\n\r\n2. **`matrices-linear-algebra.md`**: Matrix operations, eigenvalues, linear systems\r\n   - Load when: Working with matrices or linear algebra problems\r\n\r\n3. **`physics-mechanics.md`**: Classical mechanics, quantum mechanics, vectors, units\r\n   - Load when: Physics calculations or mechanics problems\r\n\r\n4. **`advanced-topics.md`**: Geometry, number theory, combinatorics, logic, statistics\r\n   - Load when: Advanced mathematical topics beyond basic algebra and calculus\r\n\r\n5. **`code-generation-printing.md`**: Lambdify, codegen, LaTeX output, printing\r\n   - Load when: Converting expressions to code or generating formatted output\r\n\r\n## Common Use Case Patterns\r\n\r\n### Pattern 1: Solve and Verify\r\n\r\n```python\r\nfrom sympy import symbols, solve, simplify\r\nx = symbols('x')\r\n\r\n# Solve equation\r\nequation = x**2 - 5*x + 6\r\nsolutions = solve(equation, x)  # [2, 3]\r\n\r\n# Verify solutions\r\nfor sol in solutions:\r\n    result = simplify(equation.subs(x, sol))\r\n    assert result == 0\r\n```\r\n\r\n### Pattern 2: Symbolic to Numeric Pipeline\r\n\r\n```python\r\n# 1. Define symbolic problem\r\nx, y = symbols('x y')\r\nexpr = sin(x) + cos(y)\r\n\r\n# 2. Manipulate symbolically\r\nsimplified = simplify(expr)\r\nderivative = diff(simplified, x)\r\n\r\n# 3. Convert to numerical function\r\nf = lambdify((x, y), derivative, 'numpy')\r\n\r\n# 4. Evaluate numerically\r\nresults = f(x_data, y_data)\r\n```\r\n\r\n### Pattern 3: Document Mathematical Results\r\n\r\n```python\r\n# Compute result symbolically\r\nintegral_expr = Integral(x**2, (x, 0, 1))\r\nresult = integral_expr.doit()\r\n\r\n# Generate documentation\r\nprint(f\"LaTeX: {latex(integral_expr)} = {latex(result)}\")\r\nprint(f\"Pretty: {pretty(integral_expr)} = {pretty(result)}\")\r\nprint(f\"Numerical: {result.evalf()}\")\r\n```\r\n\r\n## Integration with Scientific Workflows\r\n\r\n### With NumPy\r\n\r\n```python\r\nimport numpy as np\r\nfrom sympy import symbols, lambdify\r\n\r\nx = symbols('x')\r\nexpr = x**2 + 2*x + 1\r\n\r\nf = lambdify(x, expr, 'numpy')\r\nx_array = np.linspace(-5, 5, 100)\r\ny_array = f(x_array)\r\n```\r\n\r\n### With Matplotlib\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom sympy import symbols, lambdify, sin\r\n\r\nx = symbols('x')\r\nexpr = sin(x) / x\r\n\r\nf = lambdify(x, expr, 'numpy')\r\nx_vals = np.linspace(-10, 10, 1000)\r\ny_vals = f(x_vals)\r\n\r\nplt.plot(x_vals, y_vals)\r\nplt.show()\r\n```\r\n\r\n### With SciPy\r\n\r\n```python\r\nfrom scipy.optimize import fsolve\r\nfrom sympy import symbols, lambdify\r\n\r\n# Define equation symbolically\r\nx = symbols('x')\r\nequation = x**3 - 2*x - 5\r\n\r\n# Convert to numerical function\r\nf = lambdify(x, equation, 'numpy')\r\n\r\n# Solve numerically with initial guess\r\nsolution = fsolve(f, 2)\r\n```\r\n\r\n## Quick Reference: Most Common Functions\r\n\r\n```python\r\n# Symbols\r\nfrom sympy import symbols, Symbol\r\nx, y = symbols('x y')\r\n\r\n# Basic operations\r\nfrom sympy import simplify, expand, factor, collect, cancel\r\nfrom sympy import sqrt, exp, log, sin, cos, tan, pi, E, I, oo\r\n\r\n# Calculus\r\nfrom sympy import diff, integrate, limit, series, Derivative, Integral\r\n\r\n# Solving\r\nfrom sympy import solve, solveset, linsolve, nonlinsolve, dsolve\r\n\r\n# Matrices\r\nfrom sympy import Matrix, eye, zeros, ones, diag\r\n\r\n# Logic and sets\r\nfrom sympy import And, Or, Not, Implies, FiniteSet, Interval, Union\r\n\r\n# Output\r\nfrom sympy import latex, pprint, lambdify, init_printing\r\n\r\n# Utilities\r\nfrom sympy import evalf, N, nsimplify\r\n```\r\n\r\n## Getting Started Examples\r\n\r\n### Example 1: Solve Quadratic Equation\r\n```python\r\nfrom sympy import symbols, solve, sqrt\r\nx = symbols('x')\r\nsolution = solve(x**2 - 5*x + 6, x)\r\n# [2, 3]\r\n```\r\n\r\n### Example 2: Calculate Derivative\r\n```python\r\nfrom sympy import symbols, diff, sin\r\nx = symbols('x')\r\nf = sin(x**2)\r\ndf_dx = diff(f, x)\r\n# 2*x*cos(x**2)\r\n```\r\n\r\n### Example 3: Evaluate Integral\r\n```python\r\nfrom sympy import symbols, integrate, exp\r\nx = symbols('x')\r\nintegral = integrate(x * exp(-x**2), (x, 0, oo))\r\n# 1/2\r\n```\r\n\r\n### Example 4: Matrix Eigenvalues\r\n```python\r\nfrom sympy import Matrix\r\nM = Matrix([[1, 2], [2, 1]])\r\neigenvals = M.eigenvals()\r\n# {3: 1, -1: 1}\r\n```\r\n\r\n### Example 5: Generate Python Function\r\n```python\r\nfrom sympy import symbols, lambdify\r\nimport numpy as np\r\nx = symbols('x')\r\nexpr = x**2 + 2*x + 1\r\nf = lambdify(x, expr, 'numpy')\r\nf(np.array([1, 2, 3]))\r\n# array([ 4,  9, 16])\r\n```\r\n\r\n## Troubleshooting Common Issues\r\n\r\n1. **\"NameError: name 'x' is not defined\"**\r\n   - Solution: Always define symbols using `symbols()` before use\r\n\r\n2. **Unexpected numerical results**\r\n   - Issue: Using floating-point numbers like `0.5` instead of `Rational(1, 2)`\r\n   - Solution: Use `Rational()` or `S()` for exact arithmetic\r\n\r\n3. **Slow performance in loops**\r\n   - Issue: Using `subs()` and `evalf()` repeatedly\r\n   - Solution: Use `lambdify()` to create a fast numerical function\r\n\r\n4. **\"Can't solve this equation\"**\r\n   - Try different solvers: `solve`, `solveset`, `nsolve` (numerical)\r\n   - Check if the equation is solvable algebraically\r\n   - Use numerical methods if no closed-form solution exists\r\n\r\n5. **Simplification not working as expected**\r\n   - Try different simplification functions: `simplify`, `factor`, `expand`, `trigsimp`\r\n   - Add assumptions to symbols (e.g., `positive=True`)\r\n   - Use `simplify(expr, force=True)` for aggressive simplification\r\n\r\n## Additional Resources\r\n\r\n- Official Documentation: https://docs.sympy.org/\r\n- Tutorial: https://docs.sympy.org/latest/tutorials/intro-tutorial/index.html\r\n- API Reference: https://docs.sympy.org/latest/reference/index.html\r\n- Examples: https://github.com/sympy/sympy/tree/master/examples",
    "user_template": ""
  },
  "variables": [],
  "install": {
    "steps": [
      {
        "title": "Download & unzip",
        "detail": "Download the .zip package from SkillVault and unzip it. The sympy/ folder contains SKILL.md plus any companion scripts, references and assets."
      },
      {
        "title": "Copy into your agent skills directory",
        "detail": "Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session."
      },
      {
        "title": "Use it",
        "detail": "Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description."
      }
    ]
  },
  "usage": {
    "steps": []
  },
  "metadata": {
    "author": "SkillVault",
    "source": "https://skillvault.top/skills/sympy",
    "exported_at": "2026-11-03T07:44:27.228Z"
  }
}
sympy.aiskill (YAML)
format: aiskill/v1
skill:
  name: sympy
  slug: sympy
  version: 1.0.0
  description: >-
    Use this skill when working with symbolic mathematics in Python. This skill should be used for
    symbolic computation tasks including solving equations algebraically, performing calculus
    operations (derivatives, integrals, limits), manipulating algebraic expressions, working with
    matrices symbolically, physics calculations, number theory problems, geometry computations, and
    generating executable code from mathematical expressions. Apply this skill when the user needs
    exact symbolic results rather than numerical approximations, or when working with mathematical
    formulas that contain variables and parameters.
  category: Research
  tags:
    - research-science
    - python
  platforms:
    - chatgpt
    - claude-code
    - cursor
  tested_environment: >-
    Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and
    compatible agents
  license: HTTPS://GITHUB.COM/SYMPY/SYMPY/BLOB/MASTER/LICENSE
prompts:
  system: "# SymPy - Symbolic Mathematics in Python\r\n\r\n## Overview\r\n\r\nSymPy is a Python library for symbolic mathematics that enables exact computation using mathematical symbols rather than numerical approximations. This skill provides comprehensive guidance for performing symbolic algebra, calculus, linear algebra, equation solving, physics calculations, and code generation using SymPy.\r\n\r\n## When to Use This Skill\r\n\r\nUse this skill when:\r\n- Solving equations symbolically (algebraic, differential, systems of equations)\r\n- Performing calculus operations (derivatives, integrals, limits, series)\r\n- Manipulating and simplifying algebraic expressions\r\n- Working with matrices and linear algebra symbolically\r\n- Doing physics calculations (mechanics, quantum mechanics, vector analysis)\r\n- Number theory computations (primes, factorization, modular arithmetic)\r\n- Geometric calculations (2D/3D geometry, analytic geometry)\r\n- Converting mathematical expressions to executable code (Python, C, Fortran)\r\n- Generating LaTeX or other formatted mathematical output\r\n- Needing exact mathematical results (e.g., `sqrt(2)` not `1.414...`)\r\n\r\n## Core Capabilities\r\n\r\n### 1. Symbolic Computation Basics\r\n\r\n**Creating symbols and expressions:**\r\n```python\r\nfrom sympy import symbols, Symbol\r\nx, y, z = symbols('x y z')\r\nexpr = x**2 + 2*x + 1\r\n\r\n# With assumptions\r\nx = symbols('x', real=True, positive=True)\r\nn = symbols('n', integer=True)\r\n```\r\n\r\n**Simplification and manipulation:**\r\n```python\r\nfrom sympy import simplify, expand, factor, cancel\r\nsimplify(sin(x)**2 + cos(x)**2)  # Returns 1\r\nexpand((x + 1)**3)  # x**3 + 3*x**2 + 3*x + 1\r\nfactor(x**2 - 1)    # (x - 1)*(x + 1)\r\n```\r\n\r\n**For detailed basics:** See `references/core-capabilities.md`\r\n\r\n### 2. Calculus\r\n\r\n**Derivatives:**\r\n```python\r\nfrom sympy import diff\r\ndiff(x**2, x)        # 2*x\r\ndiff(x**4, x, 3)     # 24*x (third derivative)\r\ndiff(x**2*y**3, x, y)  # 6*x*y**2 (partial derivatives)\r\n```\r\n\r\n**Integrals:**\r\n```python\r\nfrom sympy import integrate, oo\r\nintegrate(x**2, x)              # x**3/3 (indefinite)\r\nintegrate(x**2, (x, 0, 1))      # 1/3 (definite)\r\nintegrate(exp(-x), (x, 0, oo))  # 1 (improper)\r\n```\r\n\r\n**Limits and Series:**\r\n```python\r\nfrom sympy import limit, series\r\nlimit(sin(x)/x, x, 0)  # 1\r\nseries(exp(x), x, 0, 6)  # 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)\r\n```\r\n\r\n**For detailed calculus operations:** See `references/core-capabilities.md`\r\n\r\n### 3. Equation Solving\r\n\r\n**Algebraic equations:**\r\n```python\r\nfrom sympy import solveset, solve, Eq\r\nsolveset(x**2 - 4, x)  # {-2, 2}\r\nsolve(Eq(x**2, 4), x)  # [-2, 2]\r\n```\r\n\r\n**Systems of equations:**\r\n```python\r\nfrom sympy import linsolve, nonlinsolve\r\nlinsolve([x + y - 2, x - y], x, y)  # {(1, 1)} (linear)\r\nnonlinsolve([x**2 + y - 2, x + y**2 - 3], x, y)  # (nonlinear)\r\n```\r\n\r\n**Differential equations:**\r\n```python\r\nfrom sympy import Function, dsolve, Derivative\r\nf = symbols('f', cls=Function)\r\ndsolve(Derivative(f(x), x) - f(x), f(x))  # Eq(f(x), C1*exp(x))\r\n```\r\n\r\n**For detailed solving methods:** See `references/core-capabilities.md`\r\n\r\n### 4. Matrices and Linear Algebra\r\n\r\n**Matrix creation and operations:**\r\n```python\r\nfrom sympy import Matrix, eye, zeros\r\nM = Matrix([[1, 2], [3, 4]])\r\nM_inv = M**-1  # Inverse\r\nM.det()        # Determinant\r\nM.T            # Transpose\r\n```\r\n\r\n**Eigenvalues and eigenvectors:**\r\n```python\r\neigenvals = M.eigenvals()  # {eigenvalue: multiplicity}\r\neigenvects = M.eigenvects()  # [(eigenval, mult, [eigenvectors])]\r\nP, D = M.diagonalize()  # M = P*D*P^-1\r\n```\r\n\r\n**Solving linear systems:**\r\n```python\r\nA = Matrix([[1, 2], [3, 4]])\r\nb = Matrix([5, 6])\r\nx = A.solve(b)  # Solve Ax = b\r\n```\r\n\r\n**For comprehensive linear algebra:** See `references/matrices-linear-algebra.md`\r\n\r\n### 5. Physics and Mechanics\r\n\r\n**Classical mechanics:**\r\n```python\r\nfrom sympy.physics.mechanics import dynamicsymbols, LagrangesMethod\r\nfrom sympy import symbols\r\n\r\n# Define system\r\nq = dynamicsymbols('q')\r\nm, g, l = symbols('m g l')\r\n\r\n# Lagrangian (T - V)\r\nL = m*(l*q.diff())**2/2 - m*g*l*(1 - cos(q))\r\n\r\n# Apply Lagrange's method\r\nLM = LagrangesMethod(L, [q])\r\n```\r\n\r\n**Vector analysis:**\r\n```python\r\nfrom sympy.physics.vector import ReferenceFrame, dot, cross\r\nN = ReferenceFrame('N')\r\nv1 = 3*N.x + 4*N.y\r\nv2 = 1*N.x + 2*N.z\r\ndot(v1, v2)  # Dot product\r\ncross(v1, v2)  # Cross product\r\n```\r\n\r\n**Quantum mechanics:**\r\n```python\r\nfrom sympy.physics.quantum import Ket, Bra, Commutator\r\npsi = Ket('psi')\r\nA = Operator('A')\r\ncomm = Commutator(A, B).doit()\r\n```\r\n\r\n**For detailed physics capabilities:** See `references/physics-mechanics.md`\r\n\r\n### 6. Advanced Mathematics\r\n\r\nThe skill includes comprehensive support for:\r\n\r\n- **Geometry:** 2D/3D analytic geometry, points, lines, circles, polygons, transformations\r\n- **Number Theory:** Primes, factorization, GCD/LCM, modular arithmetic, Diophantine equations\r\n- **Combinatorics:** Permutations, combinations, partitions, group theory\r\n- **Logic and Sets:** Boolean logic, set theory, finite and infinite sets\r\n- **Statistics:** Probability distributions, random variables, expectation, variance\r\n- **Special Functions:** Gamma, Bessel, orthogonal polynomials, hypergeometric functions\r\n- **Polynomials:** Polynomial algebra, roots, factorization, Groebner bases\r\n\r\n**For detailed advanced topics:** See `references/advanced-topics.md`\r\n\r\n### 7. Code Generation and Output\r\n\r\n**Convert to executable functions:**\r\n```python\r\nfrom sympy import lambdify\r\nimport numpy as np\r\n\r\nexpr = x**2 + 2*x + 1\r\nf = lambdify(x, expr, 'numpy')  # Create NumPy function\r\nx_vals = np.linspace(0, 10, 100)\r\ny_vals = f(x_vals)  # Fast numerical evaluation\r\n```\r\n\r\n**Generate C/Fortran code:**\r\n```python\r\nfrom sympy.utilities.codegen import codegen\r\n[(c_name, c_code), (h_name, h_header)] = codegen(\r\n    ('my_func', expr), 'C'\r\n)\r\n```\r\n\r\n**LaTeX output:**\r\n```python\r\nfrom sympy import latex\r\nlatex_str = latex(expr)  # Convert to LaTeX for documents\r\n```\r\n\r\n**For comprehensive code generation:** See `references/code-generation-printing.md`\r\n\r\n## Working with SymPy: Best Practices\r\n\r\n### 1. Always Define Symbols First\r\n\r\n```python\r\nfrom sympy import symbols\r\nx, y, z = symbols('x y z')\r\n# Now x, y, z can be used in expressions\r\n```\r\n\r\n### 2. Use Assumptions for Better Simplification\r\n\r\n```python\r\nx = symbols('x', positive=True, real=True)\r\nsqrt(x**2)  # Returns x (not Abs(x)) due to positive assumption\r\n```\r\n\r\nCommon assumptions: `real`, `positive`, `negative`, `integer`, `rational`, `complex`, `even`, `odd`\r\n\r\n### 3. Use Exact Arithmetic\r\n\r\n```python\r\nfrom sympy import Rational, S\r\n# Correct (exact):\r\nexpr = Rational(1, 2) * x\r\nexpr = S(1)/2 * x\r\n\r\n# Incorrect (floating-point):\r\nexpr = 0.5 * x  # Creates approximate value\r\n```\r\n\r\n### 4. Numerical Evaluation When Needed\r\n\r\n```python\r\nfrom sympy import pi, sqrt\r\nresult = sqrt(8) + pi\r\nresult.evalf()    # 5.96371554103586\r\nresult.evalf(50)  # 50 digits of precision\r\n```\r\n\r\n### 5. Convert to NumPy for Performance\r\n\r\n```python\r\n# Slow for many evaluations:\r\nfor x_val in range(1000):\r\n    result = expr.subs(x, x_val).evalf()\r\n\r\n# Fast:\r\nf = lambdify(x, expr, 'numpy')\r\nresults = f(np.arange(1000))\r\n```\r\n\r\n### 6. Use Appropriate Solvers\r\n\r\n- `solveset`: Algebraic equations (primary)\r\n- `linsolve`: Linear systems\r\n- `nonlinsolve`: Nonlinear systems\r\n- `dsolve`: Differential equations\r\n- `solve`: General purpose (legacy, but flexible)\r\n\r\n## Reference Files Structure\r\n\r\nThis skill uses modular reference files for different capabilities:\r\n\r\n1. **`core-capabilities.md`**: Symbols, algebra, calculus, simplification, equation solving\r\n   - Load when: Basic symbolic computation, calculus, or solving equations\r\n\r\n2. **`matrices-linear-algebra.md`**: Matrix operations, eigenvalues, linear systems\r\n   - Load when: Working with matrices or linear algebra problems\r\n\r\n3. **`physics-mechanics.md`**: Classical mechanics, quantum mechanics, vectors, units\r\n   - Load when: Physics calculations or mechanics problems\r\n\r\n4. **`advanced-topics.md`**: Geometry, number theory, combinatorics, logic, statistics\r\n   - Load when: Advanced mathematical topics beyond basic algebra and calculus\r\n\r\n5. **`code-generation-printing.md`**: Lambdify, codegen, LaTeX output, printing\r\n   - Load when: Converting expressions to code or generating formatted output\r\n\r\n## Common Use Case Patterns\r\n\r\n### Pattern 1: Solve and Verify\r\n\r\n```python\r\nfrom sympy import symbols, solve, simplify\r\nx = symbols('x')\r\n\r\n# Solve equation\r\nequation = x**2 - 5*x + 6\r\nsolutions = solve(equation, x)  # [2, 3]\r\n\r\n# Verify solutions\r\nfor sol in solutions:\r\n    result = simplify(equation.subs(x, sol))\r\n    assert result == 0\r\n```\r\n\r\n### Pattern 2: Symbolic to Numeric Pipeline\r\n\r\n```python\r\n# 1. Define symbolic problem\r\nx, y = symbols('x y')\r\nexpr = sin(x) + cos(y)\r\n\r\n# 2. Manipulate symbolically\r\nsimplified = simplify(expr)\r\nderivative = diff(simplified, x)\r\n\r\n# 3. Convert to numerical function\r\nf = lambdify((x, y), derivative, 'numpy')\r\n\r\n# 4. Evaluate numerically\r\nresults = f(x_data, y_data)\r\n```\r\n\r\n### Pattern 3: Document Mathematical Results\r\n\r\n```python\r\n# Compute result symbolically\r\nintegral_expr = Integral(x**2, (x, 0, 1))\r\nresult = integral_expr.doit()\r\n\r\n# Generate documentation\r\nprint(f\"LaTeX: {latex(integral_expr)} = {latex(result)}\")\r\nprint(f\"Pretty: {pretty(integral_expr)} = {pretty(result)}\")\r\nprint(f\"Numerical: {result.evalf()}\")\r\n```\r\n\r\n## Integration with Scientific Workflows\r\n\r\n### With NumPy\r\n\r\n```python\r\nimport numpy as np\r\nfrom sympy import symbols, lambdify\r\n\r\nx = symbols('x')\r\nexpr = x**2 + 2*x + 1\r\n\r\nf = lambdify(x, expr, 'numpy')\r\nx_array = np.linspace(-5, 5, 100)\r\ny_array = f(x_array)\r\n```\r\n\r\n### With Matplotlib\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom sympy import symbols, lambdify, sin\r\n\r\nx = symbols('x')\r\nexpr = sin(x) / x\r\n\r\nf = lambdify(x, expr, 'numpy')\r\nx_vals = np.linspace(-10, 10, 1000)\r\ny_vals = f(x_vals)\r\n\r\nplt.plot(x_vals, y_vals)\r\nplt.show()\r\n```\r\n\r\n### With SciPy\r\n\r\n```python\r\nfrom scipy.optimize import fsolve\r\nfrom sympy import symbols, lambdify\r\n\r\n# Define equation symbolically\r\nx = symbols('x')\r\nequation = x**3 - 2*x - 5\r\n\r\n# Convert to numerical function\r\nf = lambdify(x, equation, 'numpy')\r\n\r\n# Solve numerically with initial guess\r\nsolution = fsolve(f, 2)\r\n```\r\n\r\n## Quick Reference: Most Common Functions\r\n\r\n```python\r\n# Symbols\r\nfrom sympy import symbols, Symbol\r\nx, y = symbols('x y')\r\n\r\n# Basic operations\r\nfrom sympy import simplify, expand, factor, collect, cancel\r\nfrom sympy import sqrt, exp, log, sin, cos, tan, pi, E, I, oo\r\n\r\n# Calculus\r\nfrom sympy import diff, integrate, limit, series, Derivative, Integral\r\n\r\n# Solving\r\nfrom sympy import solve, solveset, linsolve, nonlinsolve, dsolve\r\n\r\n# Matrices\r\nfrom sympy import Matrix, eye, zeros, ones, diag\r\n\r\n# Logic and sets\r\nfrom sympy import And, Or, Not, Implies, FiniteSet, Interval, Union\r\n\r\n# Output\r\nfrom sympy import latex, pprint, lambdify, init_printing\r\n\r\n# Utilities\r\nfrom sympy import evalf, N, nsimplify\r\n```\r\n\r\n## Getting Started Examples\r\n\r\n### Example 1: Solve Quadratic Equation\r\n```python\r\nfrom sympy import symbols, solve, sqrt\r\nx = symbols('x')\r\nsolution = solve(x**2 - 5*x + 6, x)\r\n# [2, 3]\r\n```\r\n\r\n### Example 2: Calculate Derivative\r\n```python\r\nfrom sympy import symbols, diff, sin\r\nx = symbols('x')\r\nf = sin(x**2)\r\ndf_dx = diff(f, x)\r\n# 2*x*cos(x**2)\r\n```\r\n\r\n### Example 3: Evaluate Integral\r\n```python\r\nfrom sympy import symbols, integrate, exp\r\nx = symbols('x')\r\nintegral = integrate(x * exp(-x**2), (x, 0, oo))\r\n# 1/2\r\n```\r\n\r\n### Example 4: Matrix Eigenvalues\r\n```python\r\nfrom sympy import Matrix\r\nM = Matrix([[1, 2], [2, 1]])\r\neigenvals = M.eigenvals()\r\n# {3: 1, -1: 1}\r\n```\r\n\r\n### Example 5: Generate Python Function\r\n```python\r\nfrom sympy import symbols, lambdify\r\nimport numpy as np\r\nx = symbols('x')\r\nexpr = x**2 + 2*x + 1\r\nf = lambdify(x, expr, 'numpy')\r\nf(np.array([1, 2, 3]))\r\n# array([ 4,  9, 16])\r\n```\r\n\r\n## Troubleshooting Common Issues\r\n\r\n1. **\"NameError: name 'x' is not defined\"**\r\n   - Solution: Always define symbols using `symbols()` before use\r\n\r\n2. **Unexpected numerical results**\r\n   - Issue: Using floating-point numbers like `0.5` instead of `Rational(1, 2)`\r\n   - Solution: Use `Rational()` or `S()` for exact arithmetic\r\n\r\n3. **Slow performance in loops**\r\n   - Issue: Using `subs()` and `evalf()` repeatedly\r\n   - Solution: Use `lambdify()` to create a fast numerical function\r\n\r\n4. **\"Can't solve this equation\"**\r\n   - Try different solvers: `solve`, `solveset`, `nsolve` (numerical)\r\n   - Check if the equation is solvable algebraically\r\n   - Use numerical methods if no closed-form solution exists\r\n\r\n5. **Simplification not working as expected**\r\n   - Try different simplification functions: `simplify`, `factor`, `expand`, `trigsimp`\r\n   - Add assumptions to symbols (e.g., `positive=True`)\r\n   - Use `simplify(expr, force=True)` for aggressive simplification\r\n\r\n## Additional Resources\r\n\r\n- Official Documentation: https://docs.sympy.org/\r\n- Tutorial: https://docs.sympy.org/latest/tutorials/intro-tutorial/index.html\r\n- API Reference: https://docs.sympy.org/latest/reference/index.html\r\n- Examples: https://github.com/sympy/sympy/tree/master/examples"
  user_template: ""
variables: []
install:
  steps:
    - title: Download & unzip
      detail: >-
        Download the .zip package from SkillVault and unzip it. The sympy/ folder contains SKILL.md
        plus any companion scripts, references and assets.
    - title: Copy into your agent skills directory
      detail: >-
        Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code),
        .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or
        reload the session.
    - title: Use it
      detail: >-
        Describe the task in natural language; the agent loads the skill automatically when the
        request matches the skill description.
usage:
  steps: []
metadata:
  author: SkillVault
  source: https://skillvault.top/skills/sympy
  exported_at: "2026-11-03T07:44:27.228Z"

安装指南

  1. 1

    Download & unzip

    Download the .zip package from SkillVault and unzip it. The sympy/ folder contains SKILL.md plus any companion scripts, references and assets.

  2. 2

    Copy into your agent skills directory

    Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session.

  3. 3

    Use it

    Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description.

使用方法

平台兼容性

ChatGPT GPTs

OpenAI

将系统提示词粘贴到 GPT 的「Instructions」字段,并把用户模板作为起始消息使用。

官方文档

Claude Code

Anthropic

将导出的 .aiskill JSON 保存为项目中的技能文件,或将系统提示词粘贴进 CLAUDE.md / 斜杠命令 Markdown 文件。

官方文档

Cursor

Anysphere

将系统提示词复制到 .cursor/rules/*.mdc(或设置中的 Project Rules),并在智能体提示词中引用用户模板。

官方文档

相关技能

astropy AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

astropy

Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.

#research-science#python
0 0 v1.0.0
fluidsim AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

fluidsim

Framework for computational fluid dynamics simulations using Python. Use when running fluid dynamics simulations including Navier-Stokes equations (2D/3D), shallow water equations, stratified flows, or when analyzing turbulence, vortex dynamics, or geophysical flows. Provides pseudospectral methods with FFT, HPC support, and comprehensive output analysis.

#research-science#python
0 0 v1.0.0
geomaster AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

geomaster

Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains. Supports satellite imagery processing (Sentinel, Landsat, MODIS, SAR, hyperspectral), vector and raster data operations, spatial statistics, point cloud processing, network analysis, cloud-native workflows (STAC, COG, Planetary Computer), and 8 programming languages (Python, R, Julia, JavaScript, C++, Java, Go, Rust) with 500+ code examples. Use for remote sensing workflows, GIS analysis, spatial ML, Earth observation data processing, terrain analysis, hydrological modeling, marine spatial analysis, atmospheric science, and any geospatial computation task.

#research-science#infrastructure#python
0 0 v1.0.0