The SymPy skill: exact symbolic math for AI agents

Most numbers an AI agent touches are approximations. Ask for the square root of two and you usually get 1.4142… — close enough, until it isn’t. The SymPy skill exists for the moments when “close enough” is the bug, not the answer: it computes with mathematical symbols, so you get exact results like sqrt(2), 1/3, or a closed-form derivative instead of a rounded decimal.

SymPy is a mature Python library for symbolic mathematics — this skill is packaged by K-Dense Inc. on top of the open-source SymPy project. This spotlight covers what the skill lets an agent do, when it earns its place in a workflow, and the practical habits that keep it from tripping.

What the skill covers

It spans the working surface of computer algebra:

  • Algebra and simplification — expand, factor, cancel and simplify expressions (simplify(sin(x)**2 + cos(x)**2) returns 1).
  • Calculus — derivatives, indefinite and definite integrals, limits and series expansions.
  • Equation solving — algebraic equations, linear and nonlinear systems, and differential equations via solveset, linsolve, nonlinsolve and dsolve.
  • Matrices and linear algebra — inverses, determinants, eigenvalues and eigenvectors, diagonalization, and solving Ax = b symbolically.
  • Physics — classical mechanics (including Lagrange’s method), vector analysis, and quantum-mechanics primitives like kets, bras and commutators.
  • Advanced topics — geometry, number theory, combinatorics, logic and set theory, statistics, special functions, and polynomials up to Gröbner bases.
  • Code generation and output — turn an expression into a fast NumPy function, emit C or Fortran, or render LaTeX for documents.

A few things it does in one line

solve(x**2 - 5*x + 6, x)             # [2, 3]
diff(sin(x**2), x)                   # 2*x*cos(x**2)
integrate(x*exp(-x**2), (x, 0, oo))  # 1/2
Matrix([[1, 2], [2, 1]]).eigenvals() # {3: 1, -1: 1}
latex(Integral(x**2, (x, 0, 1)))     # ready-to-paste LaTeX

When to reach for it

Symbolic math is the right tool when exactness matters more than raw speed: deriving a formula, verifying an algebraic step, producing a closed-form result, or generating LaTeX and runnable code from the same expression. For heavy numerical crunching, the skill’s own advice is to convert the symbolic result into a compiled NumPy function with lambdify and let NumPy do the loops — symbolic to set up, numeric to run.

Habits that keep it honest

  • Define symbols first. Every variable comes from symbols('x y z') before it appears in an expression.
  • Use assumptions. Declaring x = symbols('x', positive=True) lets sqrt(x**2) simplify to x instead of Abs(x).
  • Stay exact. Write Rational(1, 2) or S(1)/2, not 0.5 — a stray float quietly turns exact math into approximate math.
  • Lambdify for loops. Repeated subs() plus evalf() is slow; one lambdify call is the fast path.
  • Match the solver to the problemsolveset for algebra, linsolve/nonlinsolve for systems, dsolve for differential equations.

Where it fits

In the AOF skill library, SymPy is the “give me the exact answer, plus the code and the LaTeX to go with it” tool. It pairs naturally with numerical and plotting skills such as NumPy, Matplotlib and SciPy: reason symbolically, then hand the compiled function to the numerical stack. When an agent needs to be right to the last term rather than the third decimal, this is the one to load.

Built on the open-source SymPy project; skill packaged by K-Dense Inc. Full library: the AI Skill Library.