with one click
sympy
// Use when you need exact symbolic math in Python — algebra, calculus, equation solving, symbolic linear algebra, or code generation via lambdify/LaTeX. Prefer NumPy or SciPy when floating-point approximations are sufficient.
// Use when you need exact symbolic math in Python — algebra, calculus, equation solving, symbolic linear algebra, or code generation via lambdify/LaTeX. Prefer NumPy or SciPy when floating-point approximations are sufficient.
Deep generative models for single-cell omics. Use when you need probabilistic batch correction (scVI), transfer learning, differential expression with uncertainty, or multi-modal integration (TOTALVI, MultiVI). Best for advanced modeling, batch effects, multimodal data. For standard analysis pipelines use scanpy.
Biological data toolkit. Sequence analysis, alignments, phylogenetic trees, diversity metrics (alpha/beta, UniFrac), ordination (PCoA), PERMANOVA, FASTA/Newick I/O, for microbiome analysis.
Modal is a serverless cloud platform for running Python on demand, including on-demand GPUs. Use when deploying or serving AI/ML models, running GPU-accelerated workloads (training, fine-tuning, inference), serving web endpoints, scheduling batch jobs, or scaling Python code to cloud containers with the Modal SDK.
End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g. "analyze my RNA-seq", "FASTQ to DESeq2", "run nf-core/rnaseq", "STAR/Salmon quantification", "build a counts matrix for DESeq2", or "go from reads to differentially expressed genes and enriched pathways". Routes between an nf-core/rnaseq (Nextflow) path and a standalone STAR/Salmon path, and covers experimental design, strandedness, and QC gates. For single-cell RNA-seq use the scanpy skill instead.
Run pathway and gene-set enrichment analysis on gene lists or ranked gene data, then interpret the results. Use whenever the user has a set of genes (differentially expressed genes from PyDESeq2/Scanpy, CRISPR-screen hits, cluster marker genes, proteomics hits) and wants to know which biological pathways, GO terms, or gene sets are over-represented or enriched. Covers over-representation analysis (ORA / Enrichr / Fisher / hypergeometric), ranked Gene Set Enrichment Analysis (GSEA / preranked), single-sample scoring (ssGSEA/GSVA), and functional profiling via gseapy, g:Profiler, Enrichr libraries, MSigDB, GO, KEGG, Reactome, and WikiPathways — plus gene-ID mapping, choosing the right background universe, multiple-testing correction, redundancy reduction, dotplots/enrichment maps, and publication-ready tables. Use this for "pathway analysis", "enrichment analysis", "GO enrichment", "KEGG/Reactome pathways", "GSEA", "over-representation", "functional annotation", or "what pathways are my genes in".
Build, run, and debug Nextflow data pipelines and nf-core workflows end to end. Use whenever the user mentions Nextflow, nf-core, .nf files, nextflow.config, DSL2, processes/channels/operators, samplesheets, or wants to run a community pipeline (e.g. nf-core/rnaseq, nf-core/sarek), write or test a module/subworkflow with nf-test, configure executors/containers (Docker, Singularity/Apptainer, Conda, Wave), scale a workflow to HPC/SLURM or cloud (AWS Batch, Google Batch, Azure, Kubernetes), or debug a failed/-resume run. Make sure to use this skill for any reproducible scientific/bioinformatics workflow work even if the user does not say the word "Nextflow", and for authoring nf-core-compliant pipelines, modules, configs, and linting.
| name | sympy |
| description | Use when you need exact symbolic math in Python — algebra, calculus, equation solving, symbolic linear algebra, or code generation via lambdify/LaTeX. Prefer NumPy or SciPy when floating-point approximations are sufficient. |
| license | https://github.com/sympy/sympy/blob/master/LICENSE |
| allowed-tools | Read Write Edit Bash |
| compatibility | Requires Python 3.9+ and SymPy 1.14+. Optional NumPy/SciPy/Matplotlib for lambdify examples; C/Fortran compiler for autowrap/codegen. |
| metadata | {"version":"1.1","skill-author":"K-Dense Inc."} |
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.
Tested against SymPy 1.14.0 (stable; April 2025). Requires Python 3.9+.
# Install SymPy using uv
uv pip install "sympy>=1.14"
# Optional: for lambdify and plotting examples
uv pip install numpy scipy matplotlib
Check your version:
import sympy
print(sympy.__version__)
Use this skill when:
sqrt(2) not 1.414...)Creating symbols and expressions:
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:
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
Derivatives:
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:
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:
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
Algebraic equations:
from sympy import solveset, solve, Eq
solveset(x**2 - 4, x) # {-2, 2}
solve(Eq(x**2, 4), x) # [-2, 2]
Systems of equations:
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:
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
Matrix creation and operations:
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:
eigenvals = M.eigenvals() # {eigenvalue: multiplicity}
eigenvects = M.eigenvects() # [(eigenval, mult, [eigenvectors])]
P, D = M.diagonalize() # M = P*D*P^-1
Solving linear systems:
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
Classical mechanics:
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:
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:
from sympy.physics.quantum import Ket, Bra, Operator, Commutator
A, B = Operator('A'), Operator('B')
psi = Ket('psi')
comm = Commutator(A, B).doit()
For detailed physics capabilities: See references/physics-mechanics.md
The skill includes comprehensive support for:
For detailed advanced topics: See references/advanced-topics.md
Convert to executable functions:
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:
from sympy.utilities.codegen import codegen
[(c_name, c_code), (h_name, h_header)] = codegen(
('my_func', expr), 'C'
)
LaTeX output:
from sympy import latex
latex_str = latex(expr) # Convert to LaTeX for documents
For comprehensive code generation: See references/code-generation-printing.md
from sympy import symbols
x, y, z = symbols('x y z')
# Now x, y, z can be used in expressions
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
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
from sympy import pi, sqrt
result = sqrt(8) + pi
result.evalf() # 5.96371554103586
result.evalf(50) # 50 digits of precision
# 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))
solveset: Algebraic equations (primary)linsolve: Linear systemsnonlinsolve: Nonlinear systemsdsolve: Differential equationssolve: General purpose (legacy, but flexible)This skill uses modular reference files for different capabilities:
core-capabilities.md: Symbols, algebra, calculus, simplification, equation solving
matrices-linear-algebra.md: Matrix operations, eigenvalues, linear systems
physics-mechanics.md: Classical mechanics, quantum mechanics, vectors, units
advanced-topics.md: Geometry, number theory, combinatorics, logic, statistics
code-generation-printing.md: Lambdify, codegen, LaTeX output, printing
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
# 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)
# 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()}")
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)
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()
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)
# 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
from sympy import symbols, solve, sqrt
x = symbols('x')
solution = solve(x**2 - 5*x + 6, x)
# [2, 3]
from sympy import symbols, diff, sin
x = symbols('x')
f = sin(x**2)
df_dx = diff(f, x)
# 2*x*cos(x**2)
from sympy import symbols, integrate, exp
x = symbols('x')
integral = integrate(x * exp(-x**2), (x, 0, oo))
# 1/2
from sympy import Matrix
M = Matrix([[1, 2], [2, 1]])
eigenvals = M.eigenvals()
# {3: 1, -1: 1}
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])
"NameError: name 'x' is not defined"
symbols() before useUnexpected numerical results
0.5 instead of Rational(1, 2)Rational() or S() for exact arithmeticSlow performance in loops
subs() and evalf() repeatedlylambdify() to create a fast numerical function"Can't solve this equation"
solve, solveset, nsolve (numerical)Simplification not working as expected
simplify, factor, expand, trigsimppositive=True)simplify(expr, force=True) for aggressive simplification