Skip to content

SymPy

Simplify, factor, differentiate, integrate and solve symbolic math expressions

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/sympy/index.md to help me query SymPy with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Factor polynomials and find their roots

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT poly,
       sympy.main.factor(poly) AS factored,
       sympy.main.solve(poly, 'x') AS roots
FROM (VALUES ('x**3 - 6*x**2 + 11*x - 6'), ('x**2 - 2')) AS t(poly)
ORDER BY poly
Result
poly factored roots
x**2 - 2 x**2 - 2 ["-sqrt(2)", "sqrt(2)"]
x**3 - 6*x**2 + 11*x - 6 (x - 3)*(x - 2)*(x - 1) ["1", "2", "3"]

Quick start

Choose where to run SymPy, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'sympy' AS sympy (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-sympy-worker'
);

3. Run a query

query.sql
SELECT poly,
       sympy.main.factor(poly) AS factored,
       sympy.main.solve(poly, 'x') AS roots
FROM (VALUES ('x**3 - 6*x**2 + 11*x - 6'), ('x**2 - 2')) AS t(poly)
ORDER BY poly
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'sympy' AS sympy (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-sympy-worker'
);

Overview

Symbolic math (CAS): simplify/solve/differentiate/integrate/factor for SQL via SymPy.

Catalog

Everything sympy exposes once attached — read straight from the worker's released build.

sympy 1 schema
main 10 functions

Symbolic math (CAS): simplify/solve/differentiate/integrate/factor for SQL

Schema examples (12)
Examples (12)

Simplify a Pythagorean trig identity to 1.

SELECT sympy.main.simplify('sin(x)**2 + cos(x)**2');

Expand a squared binomial into a flat polynomial.

SELECT sympy.main.expand('(x + 1)**2');

Factor a difference of squares into a product.

SELECT sympy.main.factor('x**2 - 1');

Differentiate x**3 with respect to x.

SELECT sympy.main.differentiate('x**3', 'x');
8 more examples

Integrate 2*x with respect to x (no constant of integration).

SELECT sympy.main.integrate('2*x', 'x');

Solve a quadratic equation for x, returning a VARCHAR[] of roots.

SELECT sympy.main.solve('x**2 - 4', 'x');

Substitute x=3, y=1 into an expression and evaluate to a DOUBLE.

SELECT sympy.main.evaluate('x**2 + y', '{"x":3,"y":1}');

Test that two different-looking expressions are symbolically equal.

SELECT sympy.main.symbolic_equal('2*(x+1)', '2*x+2');

Find the stationary points of x**3 - 3*x by solving its derivative for zero, then evaluate the function at each one: a local maximum of 2.0 at x = -1 and a local minimum of -2.0 at x = 1.

WITH crit AS (
  SELECT UNNEST(sympy.main.solve(sympy.main.differentiate('x**3 - 3*x', 'x'), 'x')) AS root
), pts AS (
  SELECT root, sympy.main.evaluate(root, '{}') AS x_value FROM crit
)
SELECT root, x_value,
       sympy.main.evaluate('x**3 - 3*x', '{"x": ' || x_value || '}') AS f_value
FROM pts
ORDER BY x_value;

Integrate each integrand, then verify the antiderivative by differentiating it back and testing symbolic equality with the original (all four rows are verified TRUE, even where the round-tripped string looks different).

SELECT integrand,
       sympy.main.integrate(integrand, 'x') AS antiderivative,
       sympy.main.symbolic_equal(
         sympy.main.differentiate(sympy.main.integrate(integrand, 'x'), 'x'), integrand) AS verified
FROM (VALUES ('x*exp(x)'), ('1/(1 + x**2)'), ('sin(x)**2'), ('log(x)')) AS t(integrand)
ORDER BY integrand;

Grade free-form answers against the key (x + 1)**2: render each answer as LaTeX for display and mark it correct when it is symbolically equal to the key (only x**2 + 1 is wrong).

SELECT answer,
       sympy.main.to_latex(answer) AS latex,
       sympy.main.symbolic_equal(answer, '(x + 1)**2') AS correct
FROM (VALUES ('x**2 + 2*x + 1'), ('(1 + x)*(x + 1)'), ('x**2 + 1'), ('x*(x + 2) + 1')) AS t(answer)
ORDER BY answer;

Show each polynomial's factorization over the rationals beside its roots: x**3 - 6*x**2 + 11*x - 6 factors into (x - 3)*(x - 2)*(x - 1) with roots 1, 2, 3, while x**2 - 2 comes back unfactored because its roots -sqrt(2) and sqrt(2) are irrational.

SELECT poly,
       sympy.main.factor(poly) AS factored,
       sympy.main.solve(poly, 'x') AS roots
FROM (VALUES ('x**3 - 6*x**2 + 11*x - 6'), ('x**2 - 2')) AS t(poly)
ORDER BY poly;
Result
poly factored roots
x**2 - 2 x**2 - 2 ["-sqrt(2)", "sqrt(2)"]
x**3 - 6*x**2 + 11*x - 6 (x - 3)*(x - 2)*(x - 1) ["1", "2", "3"]
Scalar functions
differentiate (expr VARCHAR, var VARCHAR) 3 examples

Derivative of an expression with respect to a variable, or NULL if invalid

Arguments
expr VARCHAR
Expression to differentiate.
var VARCHAR
Variable name to differentiate by.
ReturnsVARCHAR
Examples (3)

Differentiate x**3 with respect to x.

SELECT sympy.main.differentiate('x**3', 'x');

Differentiate sin(x) with respect to x.

SELECT sympy.main.differentiate('sin(x)', 'x');

Find the stationary points of x**3 - 3*x by solving its derivative for zero, then evaluate the function at each one: a local maximum of 2.0 at x = -1 and a local minimum of -2.0 at x = 1.

WITH crit AS (
  SELECT UNNEST(sympy.main.solve(sympy.main.differentiate('x**3 - 3*x', 'x'), 'x')) AS root
), pts AS (
  SELECT root, sympy.main.evaluate(root, '{}') AS x_value FROM crit
)
SELECT root, x_value,
       sympy.main.evaluate('x**3 - 3*x', '{"x": ' || x_value || '}') AS f_value
FROM pts
ORDER BY x_value;
Link
evaluate (expr VARCHAR, vars_json VARCHAR) 2 examples

Substitute numeric values from a JSON object like '{"x":2,"y":3}' and evaluate to a DOUBLE. NULL if invalid, non-numeric, or free symbols remain.

Arguments
expr VARCHAR
Expression to evaluate.
vars_json VARCHAR
JSON object of variable values, e.g. {"x":2}.
ReturnsDOUBLE
Examples (2)

Substitute x=3, y=1 into an expression and evaluate to a DOUBLE.

SELECT sympy.main.evaluate('x**2 + y', '{"x":3,"y":1}');

Evaluate a constant expression (2*pi) with no variables.

SELECT sympy.main.evaluate('2*pi', '{}');
Link
expand (expr VARCHAR) 2 examples

Algebraically expanded form of an expression, or NULL if invalid/unsafe

Arguments
expr VARCHAR
Expression to expand.
ReturnsVARCHAR
Examples (2)

Expand a squared binomial into a flat polynomial.

SELECT sympy.main.expand('(x + 1)**2');

Expand a product of conjugates to a difference of squares.

SELECT sympy.main.expand('(x + y)*(x - y)');
Link
factor (expr VARCHAR) 3 examples

Factored form of an expression, e.g. '(x - 1)*(x + 1)', or NULL if invalid

Arguments
expr VARCHAR
Expression to factor.
ReturnsVARCHAR
Examples (3)

Factor a difference of squares into a product.

SELECT sympy.main.factor('x**2 - 1');

Factor a perfect-square trinomial.

SELECT sympy.main.factor('x**2 + 2*x + 1');

Show each polynomial's factorization over the rationals beside its roots: x**3 - 6*x**2 + 11*x - 6 factors into (x - 3)*(x - 2)*(x - 1) with roots 1, 2, 3, while x**2 - 2 comes back unfactored because its roots -sqrt(2) and sqrt(2) are irrational.

SELECT poly,
       sympy.main.factor(poly) AS factored,
       sympy.main.solve(poly, 'x') AS roots
FROM (VALUES ('x**3 - 6*x**2 + 11*x - 6'), ('x**2 - 2')) AS t(poly)
ORDER BY poly;
Result
poly factored roots
x**2 - 2 x**2 - 2 ["-sqrt(2)", "sqrt(2)"]
x**3 - 6*x**2 + 11*x - 6 (x - 3)*(x - 2)*(x - 1) ["1", "2", "3"]
Link
integrate (expr VARCHAR, var VARCHAR) 3 examples

Indefinite integral of an expression w.r.t. a variable (no +C), or NULL if invalid or no closed form is found

Arguments
expr VARCHAR
Expression to integrate.
var VARCHAR
Variable name to integrate by.
ReturnsVARCHAR
Examples (3)

Integrate 2*x with respect to x (no constant of integration).

SELECT sympy.main.integrate('2*x', 'x');

Integrate cos(x) with respect to x.

SELECT sympy.main.integrate('cos(x)', 'x');

Integrate each integrand, then verify the antiderivative by differentiating it back and testing symbolic equality with the original (all four rows are verified TRUE, even where the round-tripped string looks different).

SELECT integrand,
       sympy.main.integrate(integrand, 'x') AS antiderivative,
       sympy.main.symbolic_equal(
         sympy.main.differentiate(sympy.main.integrate(integrand, 'x'), 'x'), integrand) AS verified
FROM (VALUES ('x*exp(x)'), ('1/(1 + x**2)'), ('sin(x)**2'), ('log(x)')) AS t(integrand)
ORDER BY integrand;
Link
simplify (expr VARCHAR) 2 examples

Algebraically simplified form of an expression, or NULL if invalid/unsafe

Arguments
expr VARCHAR
Expression to simplify.
ReturnsVARCHAR
Examples (2)

Simplify a Pythagorean trig identity to 1.

SELECT sympy.main.simplify('sin(x)**2 + cos(x)**2');

Cancel a common factor from a rational expression.

SELECT sympy.main.simplify('(x**2 - 1)/(x - 1)');
Link
solve (equation VARCHAR, var VARCHAR) 2 examples

Solve an equation for a variable, returning solutions as VARCHAR[]. Accepts 'lhs = rhs' or a bare expression assumed equal to zero. NULL if invalid; empty list if no solutions.

Arguments
equation VARCHAR
Equation or expression to solve.
var VARCHAR
Variable name to solve for.
ReturnsVARCHAR[]
Examples (2)

Solve a quadratic for x, returning a VARCHAR[] of roots.

SELECT sympy.main.solve('x**2 - 4', 'x');

Solve a linear 'lhs = rhs' equation and unnest the solution rows.

SELECT UNNEST(sympy.main.solve('2*x = 10', 'x'));
Link
symbolic_equal (a VARCHAR, b VARCHAR) 3 examples

True if two expressions are symbolically equivalent (simplify(a-b)==0), or NULL if either is invalid

Arguments
a VARCHAR
First expression.
b VARCHAR
Second expression.
ReturnsBOOLEAN
Examples (3)

Prove two different-looking forms are equal (TRUE).

SELECT sympy.main.symbolic_equal('2*(x+1)', '2*x+2');

Show two distinct functions are not equal (FALSE).

SELECT sympy.main.symbolic_equal('sin(x)', 'cos(x)');

Grade free-form answers against the key (x + 1)**2: render each answer as LaTeX for display and mark it correct when it is symbolically equal to the key (only x**2 + 1 is wrong).

SELECT answer,
       sympy.main.to_latex(answer) AS latex,
       sympy.main.symbolic_equal(answer, '(x + 1)**2') AS correct
FROM (VALUES ('x**2 + 2*x + 1'), ('(1 + x)*(x + 1)'), ('x**2 + 1'), ('x*(x + 2) + 1')) AS t(answer)
ORDER BY answer;
Link
sympy_version (n BIGINT) 2 examples

The SymPy version string backing this worker

Arguments
n BIGINT
Row driver (value ignored).
ReturnsVARCHAR
Examples (2)

Report the backing SymPy version string.

SELECT sympy.main.sympy_version(1);

Check that the backing SymPy version is present (non-empty).

SELECT length(sympy.main.sympy_version(1)) > 0;
Link
to_latex (expr VARCHAR) 2 examples

LaTeX rendering of an expression, or NULL if invalid/unsafe

Arguments
expr VARCHAR
Expression to render.
ReturnsVARCHAR
Examples (2)

Render x squared as LaTeX markup.

SELECT sympy.main.to_latex('x**2');

Render a square root as LaTeX markup.

SELECT sympy.main.to_latex('sqrt(x)');
Link

Try these queries

Simplify a Pythagorean trig identity to 1.

SELECT sympy.main.simplify('sin(x)**2 + cos(x)**2')

Uses simplify

Expand a squared binomial into a flat polynomial.

SELECT sympy.main.expand('(x + 1)**2')

Uses expand

Factor a difference of squares into a product.

SELECT sympy.main.factor('x**2 - 1')

Uses factor

Differentiate x**3 with respect to x.

SELECT sympy.main.differentiate('x**3', 'x')

Uses differentiate

Integrate 2*x with respect to x (no constant of integration).

SELECT sympy.main.integrate('2*x', 'x')

Uses integrate

Solve a quadratic equation for x, returning a VARCHAR[] of roots.

SELECT sympy.main.solve('x**2 - 4', 'x')

Uses solve

17 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Algebraically simplify the expression sin(x)**2 + cos(x)**2 to its simplest canonical form.
  • Expand the expression (x + 1)**2 by multiplying it out into a flat polynomial.
  • Factor the polynomial x**2 - 1 into a product of irreducible factors.
  • Render the expression x**2 as a LaTeX markup string.
  • Compute the symbolic derivative of x**3 with respect to x.
  • Compute the indefinite integral (antiderivative, with no constant of integration) of 2*x with respect to x.

SymPy is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.