LLM-SR: Scientific Equation Discovery via Programming with Large Language Models

Parshin Shojaee, Kazem Meidani, Shashank Gupta, Amir Barati Farimani, Chandan K. Reddy

TL;DR

LLM-SR is a novel framework that transforms Large Language Models (LLMs) into scientific "co-pilots" for discovering mathematical equations from raw data. By treating equations as Python programs and combining an LLM’s vast scientific knowledge with evolutionary search, LLM-SR finds accurate, physically meaningful formulas far more efficiently than traditional symbolic regression methods.

What Problem Does This Paper Address?

In fields like physics and biology, scientists often seek the "hidden" mathematical laws that explain observed data—a task known as Symbolic Regression (SR). Traditional SR methods typically represent equations as "expression trees" and use genetic algorithms to randomly mutate them until they fit the data.

However, these traditional methods face two major hurdles:

  1. Combinatorial Explosion: The space of possible mathematical combinations is infinitely large, making blind searches incredibly slow and computationally expensive.
  2. Lack of Context: Traditional algorithms lack domain-specific physical intuition. They might find a formula that perfectly fits the data points but makes no physical sense (e.g., a formula for bacterial growth that predicts a negative population).

While LLMs have shown promise in coding, they often "recite" famous equations (like $F=ma$) from memory rather than genuinely discovering them from data. This paper aims to bridge the gap by creating a system that uses LLM "priors"—the scientific intuition baked into the model—to guide a rigorous, data-driven discovery process.

Methods

The authors introduce LLM-SR, which treats equation discovery as a programming task.

LLM-SR Framework Overview

The framework operates in an iterative loop consisting of three main stages:

  • Hypothesis Generation: Instead of guessing a full equation, the LLM generates an equation skeleton as a Python program. It uses a natural language description of the problem (e.g., "this is a damped oscillator") to propose structures with placeholder parameters (e.g., params[0] * sin(params[1] * x)).
  • Data-driven Evaluation: These skeletons are passed to off-the-shelf numerical optimizers (like BFGS or Adam). The optimizer finds the best values for the parameters to fit the actual experimental data. This decouples the structure of the math (handled by the LLM) from the tuning of the constants (handled by math libraries).
  • Experience Management: The system maintains an "Experience Buffer" using an islands model. It keeps several diverse "populations" of high-scoring equations. The LLM then reviews these successful past attempts to "cross-over" or "mutate" them into even better hypotheses in the next round.

Datasets

The researchers evaluated LLM-SR on four distinct benchmarks:

  1. Feynman Benchmark: A standard set of 120 physics equations, used primarily to prove that LLMs have memorized these and require harder tests.
  2. Nonlinear Oscillators (New): Custom-designed physics systems (Oscillation 1 & 2) complex enough to prevent simple LLM recitation.
  3. Bacterial Growth (New): A biological model of E. coli growth involving population density, substrate, temperature, and pH.
  4. Material Stress Behavior (New): Real-world experimental data measuring how Aluminum 6061-T651 reacts to stress at different temperatures.

Key Insights and Ideas

  • The "Recitation" Trap: The authors found that LLMs have extremely low "perplexity" on the Feynman equations, meaning they have essentially memorized them. This highlights a major flaw in current AI-for-science benchmarks and justifies the need for their new, custom datasets.
  • Equations as Programs: Representing math as code is a powerful paradigm shift. It allows the model to use conditional logic (if-else) and complex structures that are difficult to represent in traditional expression trees.
  • Priors are the Secret Sauce: Providing a short text description of the variables (e.g., "x is position, v is velocity") allows the LLM to prune the search space. It avoids suggesting formulas that are dimensionally inconsistent or physically absurd.
  • OOD Generalization: Because LLM-SR is guided by physical principles, the equations it finds tend to generalize well on Out-of-Domain (OOD) data. While traditional models might "overfit" to noise, LLM-SR zeroes in on the underlying truth.

Key Results

Performance Comparison on Benchmarks
  • Superior Accuracy: LLM-SR (using GPT-3.5 or Mixtral) consistently outperformed state-of-the-art baselines like PySR and uDSR across all new benchmarks.
  • Massive Efficiency: LLM-SR typically found the correct equation in about 2,500 iterations, whereas traditional baselines often failed to reach the same accuracy even after 2 million iterations.
  • Robustness to Noise: In tests with "messy" data, LLM-SR maintained its performance better than other models because its scientific priors acted as a "sanity check" against the noise.

Limitations and Future Work

  • LLM Dependency: The system is only as good as the underlying LLM. If a model has a "blind spot" in a specific scientific domain, the discovery process will struggle.
  • Computational Cost: Calling an LLM thousands of times can be expensive and slower per iteration than running a local genetic algorithm.
  • Future Directions: The authors suggest integrating Human-in-the-Loop systems where scientists can provide feedback mid-search, and using Retrieval-Augmented Generation (RAG) to pull in specific formulas from scientific literature to further sharpen the model's hypotheses.

Summary updated

BibTeX
@inproceedings{shojaee2025llm,
  author = {Parshin Shojaee and Kazem Meidani and Shashank Gupta and Amir Barati Farimani and Chandan K. Reddy},
  title = {{LLM-SR: Scientific Equation Discovery via Programming with Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=m2nmp8P5in},
}
Figure