sympy – skill Lập trình cho agent AI
Thực hiện toán ký hiệu chính xác với SymPy cho đại số, giải tích, giải phương trình, đại số tuyến tính ký hiệu, vật lý, và sinh code lambdify hoặc LaTeX. Dùng khi tác vụ cần kết quả ký hiệu, giả định rõ ràng hoặc số học chính xác; dùng NumPy hoặc SciPy cho khối lượng công việc thuần số.
Cài skill sympy bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/sympy-08489.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /sympy – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/sympy-08489.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $sympy – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/sympy-08489.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /sympy – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/sympy-08489.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /sympy – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
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.
Installation
Reviewed against current official documentation and executed with SymPy 1.14.0
on Python 3.13.3 (2026-10-01). Core SymPy requires Python 3.9+; the tested
NumPy 2.5.3 / SciPy 1.18.1 stack needs Python 3.12+. SymPy 1.14.0 requires
mpmath>=1.1,<1.4; use the compatible 1.3.0, not the newer 1.4.x release.
See [verification and official sources](references/review.md) for coverage.
# Install SymPy using uv
uv pip install "sympy==1.14.0"
# Optional: for lambdify and plotting examples
uv pip install numpy scipy matplotlibCheck your version:
import sympy
print(sympy.__version__)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)not1.414...)
Core Capabilities
Seven capability areas are documented in
[references/core_capabilities.md](references/core_capabilities.md):
1. Symbolic computation basics — symbols, expressions, simplification, substitution.
2. Calculus — differentiation, integration, limits, series.
3. Equation solving — solve, solveset, linear and nonlinear systems, ODEs.
4. Matrices and linear algebra — see
[references/matrices-linear-algebra.md](references/matrices-linear-algebra.md).
5. Physics and mechanics — see
[references/physics-mechanics.md](references/physics-mechanics.md).
6. Advanced mathematics — see
[references/advanced-topics.md](references/advanced-topics.md).
7. Code generation and output — see
[references/code-generation-printing.md](references/code-generation-printing.md).
Deeper treatment of the first three is in
[references/core-capabilities.md](references/core-capabilities.md).
Working with SymPy: Best Practices
1. Always Define Symbols First
from sympy import symbols
x, y, z = symbols('x y z')
# Now x, y, z can be used in expressions2. Use Assumptions for Better Simplification
from sympy import symbols, sqrt
x = symbols('x', positive=True, real=True)
sqrt(x**2) # Returns x (not Abs(x)) due to positive assumptionCommon assumptions: real, positive, negative, integer, rational, complex, even, odd
3. Use Exact Arithmetic
from sympy import Rational, S
# Correct (exact):
expr = Rational(1, 2) * x
expr = S(1)/2 * x
# Approximate (appropriate for measured/numerical inputs):
expr = 0.5 * x # Creates approximate value4. Numerical Evaluation When Needed
from sympy import pi, sqrt
result = sqrt(8) + pi
result.evalf() # 5.96371554103586
result.evalf(50) # Request 50 decimal digits; cannot recover precision lost in inputs5. Convert to NumPy for Performance
from sympy import symbols, lambdify
import numpy as np
x = symbols("x")
expr = x**2 + 1
# 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 systemsnonlinsolve: Nonlinear systemsdsolve: Differential equationssolve: General purpose; supports some problemssolvesetdoes not
Declare the solution domain: solveset defaults to complex numbers, so use domain=S.Reals for real-only questions. A returned ConditionSet means an unresolved solution condition, not that no solutions exist; distinguish it from EmptySet. A numerical nsolve result is a local root found from a starting point, not proof that every root was found.
7. Preserve mathematical meaning and input trust
Use assumptions only when justified by the problem. An unconstrained symbol is
complex; sqrt(x**2) need not equal x, and logarithm/power identities depend on
branches. Assumption predicates can return None (unknown). Keep excluded
denominator zeros when cancelling factors, and verify candidate solutions in the
original expression and requested domain. == compares symbolic structure; use
Eq to build an equation and targeted simplification to verify an identity.
parse_expr, string sympify, and lambdify can execute code. Accept only trusted
expressions there. A regex, local_dict, or evaluate=False is not a security
boundary; untrusted input needs a separate allowlisted grammar that constructs
SymPy objects, plus resource limits. See the code-generation reference.
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
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 == 0Pattern 2: Symbolic to Numeric Pipeline
from sympy import symbols, sin, cos, simplify, diff, lambdify
import numpy as np
x_data = np.linspace(0, 1, 5)
y_data = np.linspace(1, 2, 5)
# 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
from sympy import symbols, Integral, latex, pretty
x = symbols("x")
# 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
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
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
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, info, status, message = fsolve(f, 2, full_output=True)
assert status == 1, message
assert abs(f(solution[0])) < 1e-10
# A converged local root is not a complete root set.Quick Reference: Most Common Functions
# 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… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- docs-guard – Rà soát tài liệu được tạo hoặc thay đổi trước khi phát hành, bao gồm README, tham chiếu…
- documentation – Quy trình tạo tài liệu gồm tài liệu API, tài liệu kiến trúc, file README, chú thích code…
- documentation-generation-doc-generate – Bạn là chuyên gia tài liệu, chuyên tạo tài liệu toàn diện, dễ bảo trì từ code. Tạo tài…
- songsee – Phổ tần số và đặc trưng âm thanh (mel, chroma, MFCC) qua CLI.
- documentation-templates – Mẫu tài liệu và hướng dẫn cấu trúc. README, tài liệu API, chú thích code và tài liệu…
- product-discovery – Dùng khi xác thực cơ hội sản phẩm, lập bản đồ giả định, lên kế hoạch sprint khám phá…
- dotnet-architect – Kiến trúc sư backend .NET chuyên về C#, ASP.NET Core, Entity Framework, Dapper và các…
- dotnet-backend – Xây dựng dịch vụ backend ASP.NET Core 8+ với EF Core, xác thực, tác vụ nền và các mẫu…