MCP server for symbolic regression — discover formulas from data, simplify expressions, check equivalence.
Give any AI assistant (Claude, Copilot, Cursor) the ability to find exact mathematical formulas from numerical data.
Install straight from this repository (not published to PyPI yet):
pip install git+https://github.com/HippocampusEvolve/formula-mcp.git
Or clone and install in editable mode for development:
git clone https://github.com/HippocampusEvolve/formula-mcp.git cd formula-mcp pip install -e ".[dev]" python -m pytest
Either way you get the formula-mcp executable used in the MCP configs below.
Add to claude_desktop_config.json:
{
"mcpServers": {
"formula-mcp": {
"command": "formula-mcp"
}
}
}Add to .vscode/mcp.json:
{
"servers": {
"formula-mcp": {
"command": "formula-mcp"
}
}
}Now ask your AI assistant: "Here's my data: x=[1,2,3,4,5], y=[2.7, 7.4, 20.1, 54.6, 148.4]. What's the formula?"
Input: x_values=[[1],[2],[3],[4],[5]], y_values=[2.71, 7.39, 20.09, 54.6, 148.41]
Output: exp(x) [R2=0.9999, complexity=2]
Runs symbolic regression (PySR if installed, polynomial fallback otherwise). Returns: formula string, LaTeX, Python code, R2, complexity, alternatives.
Input: "(x**2 - 1) / (x - 1)"
Output: "x + 1"
Input: "sin(x)**2 + cos(x)**2"
Output: "1"
Uses SymPy with multiple simplification strategies (trig, cancel, factor).
Input: formula1="exp(log(x))", formula2="x"
Output: equivalent=true, method="algebraic"
Input: formula1="x**2 + 0.001*x**3", formula2="x**2", tolerance=0.01
Output: equivalent=true (within tolerance on [-5,5])
Algebraic proof first, numerical test (10K points) as fallback.
For proper formula discovery beyond polynomial fitting, install PySR:
pip install "formula-mcp[sr] @ git+https://github.com/HippocampusEvolve/formula-mcp.git"This adds PySR (genetic programming SR) which can discover trigonometric, exponential, logarithmic formulas. First run takes ~2-5 min to set up Julia dependencies.
Use directly without MCP:
from formula_mcp.sr import discover_formula from formula_mcp.simplify import simplify_expression, check_equivalence # Discover formula from data results = discover_formula( x_values=[[1],[2],[3],[4],[5]], y_values=[2.71, 7.39, 20.09, 54.6, 148.41], variable_names=["x"], timeout=30, ) print(results[0].expression) # exp(x) print(results[0].latex) # e^{x} print(results[0].python_code) # def f(x): return math.exp(x) # Simplify result = simplify_expression("(x**2 - 1)/(x - 1)") print(result.simplified) # x + 1 # Check equivalence result = check_equivalence("sin(x)**2 + cos(x)**2", "1") print(result.equivalent) # True
User → AI Assistant → MCP protocol → formula-mcp server
│
┌─────┴──────┐
│ │
PySR SymPy
(optional) (always)
│ │
└─────┬──────┘
│
Formula result
(str, LaTeX, code)
- discover: Samples data → PySR genetic programming (or polynomial fallback) → Pareto front of formulas
- simplify: SymPy
simplify,trigsimp,cancel,factor→ picks simplest - equivalent: SymPy algebraic proof → if inconclusive, numerical test on 10K random points
- Python 3.10+
- SymPy, NumPy (auto-installed)
- PySR (optional, for full SR beyond polynomials)
MIT