Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Searching for the formula itself
Ordinary regression fixes the shape of the answer, say a straight line, and only adjusts numbers. Symbolic regression also searches for the shape: it tries combinations like a·b, a/b², sin(a) and so on, and keeps the ones that match the data best while staying short. When it works, the result is a formula a scientist can read, test and use far outside the range of the data, as Kepler’s laws are used for planets nobody had measured.
| complexity | best expression | RMS error |
|---|---|---|
| 1 | -0.003 | 2.395 |
| 2 | 1.271·x | 0.850 |
| 4 | 1.001·x²·sin x | 0.096 |
Symbolic regression has rediscovered physical laws, found new empirical formulas in materials science and astrophysics, and extracted equations from trained neural networks.
- 1. Symbolic regression searches for…
- 2. Its results are…
- 3. A good formula should be…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Search space: trees whose leaves are variables or constants and whose nodes are operators (+, −, ×, ÷, sin, exp, √ …). The number of trees grows exponentially with size.
- Genetic programming (Koza, 1992): populations of trees evolve by mutation and crossover, selected for accuracy and simplicity; used by Eureqa (Schmidt and Lipson, 2009) and PySR (Cranmer, 2023).
- Brute force with pruning: enumerate small expressions, drop those equivalent on the data, fit constants by least squares; AI Feynman (Udrescu and Tegmark, 2020) adds dimensional analysis, symmetry and separability tests.
- Pareto front: for each complexity, the most accurate expression; the true law often shows as a sharp drop in error at its complexity.
- Neural approaches: sparse networks with symbolic activations, transformers that output equations, and distillation of a trained network into formulas.
- Risks: many formulas fit finite noisy data; extrapolation, units and physical checks separate laws from coincidences.
- 1. The number of candidate expressions grows…
- 2. A Pareto front lists…
- 3. AI Feynman uses…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Enumeration with duplicate removal
Exercise 1.
- Bottom-up enumeration of expressions by size over variables, unary operators (sin, cos, √) and binary operators (+, −, ×, ÷).
- Duplicates removed when an expression equals an earlier one up to a constant factor on the data, since the constant is fitted anyway.
- The eight planets: semi-major axis a in AU and period T in years; the Pareto front over expressions in a.
Practice.
- Restrict the grammar to operators that make physical sense, and give units to the variables when possible.
- Fit constants by least squares or local optimisation rather than searching over them.
- Read the Pareto front, not only the most accurate model; look for a sharp drop in error.
- Test extrapolation and units before believing a formula.
- Tools: PySR (fast genetic programming in Julia with a Python interface), gplearn, AI Feynman, Operon, and SymbolicRegression.jl.
from pysr import PySRRegressor
model = PySRRegressor(
binary_operators=["+", "-", "*", "/"],
unary_operators=["sin", "cos", "sqrt"],
maxsize=12, niterations=40,
)
model.fit(X, y, variable_names=["m1", "m2", "r"])
print(model.equations_[["complexity", "loss", "equation"]]) # the Pareto front- 1. A fast symbolic regression package:
- 2. Constants in expressions are best…
- 3. Before believing a formula, test…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why duplicates matter. With 3 variables, 3 unary and 4 binary operators there are 215427 trees of up to 7 nodes. Many compute the same function on the data, for example x + x and x, or a × b and b × a. Removing expressions that equal an earlier one up to a constant factor left 70884, a third, and the search took seconds.
Results in the exercise. From the planets, the front was 4.96·a (error 10.9 years), 0.19·a² (7.4 years) and then 0.999·a·√a (0.008 years): Kepler’s third law appears as a sharp drop. For F = G m1 m2 / r² with G = 6.674, clean data gave the exact law at 7 nodes. With 5% noise the same expression was found at 7 nodes, with error 4.2 against 21 for the best 6-node expression, and G was fitted as 6.58. On masses twice as large and distances half as small as in the data, the formula’s relative error was 0.01, while a cubic polynomial fitted to the same data, with error 0.1 inside the range, had error 0.7.
- 1. Removing duplicates left about…
- 2. Kepler's law showed on the Pareto front as…
- 3. Outside the data range, the cubic polynomial…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Can exhaustive expression search recover physical laws from noisy data, and how do the results extrapolate compared with a polynomial?
History.
- J. Koza (1992) established genetic programming.
- J. Bongard and H. Lipson (2007) and M. Schmidt and H. Lipson (2009) recovered conservation laws and equations of motion from motion data (Eureqa).
- S.-M. Udrescu and M. Tegmark (2020) introduced AI Feynman and rediscovered 100 equations from the Feynman Lectures.
- M. Cranmer et al. (2020) distilled formulas from graph networks; M. Cranmer (2023) released PySR.
Exercise 2. F = 6.674·m1·m2/r² at 60 random points with m in [1, 10] and r in [1, 5]; expressions up to 7 nodes; y ≈ c·expression. Pareto front with 5% multiplicative noise (RMSE):
| size | best expression | RMSE |
|---|---|---|
| 1 | m1 | 70 |
| 3 | m1 ÷ r | 44 |
| 5 | m1 ÷ (r × r) | 22 |
| 6 | m1 ÷ (r − sin r) | 21 |
| 7 | m1 × (m2 ÷ (r × r)) | 4.2 |
- The law stands out as a fivefold drop in error; the 6-node expression is a meaningless near-fit.
- Extrapolation (m in [10, 20], r in [0.5, 1]): formula 0.01, cubic polynomial 0.7.
- Seeds 1 and 2: the same law at 7 nodes, with G fitted as 6.53 and 6.78 and extrapolation errors 0.02 and 0.02 against 0.7 for the polynomial.
Symbolic regression in practice
- Astrophysics: formulas for dark-matter halo properties distilled from graph networks; empirical scaling relations.
- Materials science: descriptors and formulas for properties such as band gaps (SISSO).
- Fluids and climate: closed-form subgrid closures and parameterisations discovered from simulation data.
- Interpretability: replacing parts of trained neural networks with equations.
References
- J. R. Koza (1992). Genetic Programming: On the Programming of Computers by Means of Natural Selection. MIT Press.
- M. Schmidt and H. Lipson (2009). “Distilling free-form natural laws from experimental data.” Science.
- S.-M. Udrescu and M. Tegmark (2020). “AI Feynman: a physics-inspired method for symbolic regression.” Science Advances.
- M. Cranmer et al. (2020). “Discovering symbolic models from deep learning with inductive biases.” NeurIPS.
- M. Cranmer (2023). “Interpretable machine learning for science with PySR and SymbolicRegression.jl.” arXiv:2305.01582.