LLMs with in-context learning for Algorithmic Theoretical Physics

Anamaria Hell, Leander ThieleAI4Physics @ ICML 2026 · DOI · OpenReview

TL;DR

Large Language Models (LLMs) can be surprisingly effective at tackling complex, algorithmic tasks in theoretical physics when equipped with a Computer Algebra System (CAS) and provided with relevant examples. This work demonstrates that a frontier LLM, when given worked examples, can solve a significant portion of problems related to cosmological perturbations in modified gravity theories, performing on par with a first-year graduate student.

What Problem Does This Paper Address?

Theoretical physics research involves a spectrum of tasks, from highly creative theory building to more routine, yet time-consuming, "algorithmic computations." These algorithmic tasks, while conceptually straightforward, can be intricate and prone to subtle errors, making them ideal candidates for automation. The authors investigate whether modern LLMs, when augmented with a CAS and provided with appropriate context, can reliably handle these tasks, freeing up physicists' time and potentially uncovering new insights into their capabilities and limitations. Specifically, they focus on identifying the degrees of freedom for cosmological perturbations in various modified theories of gravity, a crucial step for understanding the stability and observational consequences of these theories.

Methods

The core of the methodology involves interfacing a frontier LLM (Claude Opus 4-6) with a CAS (Maple). The LLM is prompted with a problem description and a context, which can include worked examples and algorithmic instructions. The LLM then generates Maple code, which is executed by the CAS. The results are fed back to the LLM, creating an iterative loop until a solution is found or the process times out. The authors explore different "context" strategies, ranging from a large set of solved examples to a concise algorithmic description. They also investigate the impact of enabling "thinking mode" in the LLM.

Datasets

The paper does not describe training datasets for the LLM. For evaluation, the authors created a set of nine novel problems related to cosmological perturbations in modified theories of gravity. These problems were designed to be challenging and to avoid being present in the LLM's training data. The problems are presented in plain text and formatted in LaTeX for readability.

Key Insights and Ideas

  • LLMs as Algorithmic Assistants: LLMs, when properly equipped and guided, can serve as capable assistants for performing complex, routine calculations in theoretical physics, akin to a first-year graduate student.
  • The Power of Worked Examples: Providing the LLM with worked examples is crucial for its success. Abstract algorithmic descriptions alone are insufficient.
  • Context is King (and Queen): The quality and relevance of the provided context significantly impact the LLM's performance. Tailoring examples to address common failure modes can dramatically improve success rates.
  • Perseverance and Abstract Reasoning: The LLM exhibits remarkable perseverance, often restarting computations when stuck and demonstrating an ability to handle abstract mathematical objects when concrete solutions are elusive.
  • Subtleties are Not Overlooked: Contrary to potential expectations, the LLM was adept at identifying and handling subtle aspects of the problems, such as branching solutions, which are often overlooked even by human students.

Key Results

  • High Success Rate with Good Context: With a well-chosen set of worked examples ("3tailored" context), the LLM achieved a high success rate, solving most of the nine test problems.
  • Context Matters: Performance varied significantly with the type of context provided. A large set of general examples ("10ex") yielded a moderate success rate, while a purely instructional context ("instruction") resulted in the lowest success rate.
  • Failure Modes Identified: Common failure modes included misinterpreting the problem (e.g., mistaking a flat background for a cosmological one), incorrect reduction of higher-order derivatives, and issues with solving background equations of motion.
  • "Thinking Mode" Ineffectiveness: Enabling the LLM's "thinking mode" did not significantly improve performance, suggesting that for these specific algorithmic tasks, the core challenge lies in the reasoning and context utilization rather than the generation of intermediate reasoning steps.

Limitations and Future Work

  • Limited Scope: The study focused on a single frontier LLM, one CAS, and a specific class of algorithmic physics problems.
  • Novelty of Problems: While the problems were designed to be novel, there's always a possibility of overlap with LLM training data.
  • Human-in-the-Loop: The authors acknowledge that human oversight would be crucial for catching subtle errors or misinterpretations.
  • Future Work: The authors suggest expanding the evaluation to other LLMs, CAS, and problem domains. They also propose exploring Retrieval-Augmented Generation (RAG) setups where the LLM can dynamically pull relevant information from a larger knowledge base. The potential for LLMs to assist in other areas of theoretical physics, such as string theory and quantum field theory, is highlighted.

Summary updated

BibTeX
@inproceedings{hell2026llms,
  author = {Anamaria Hell and Leander Thiele},
  title = {{LLMs with in-context learning for Algorithmic Theoretical Physics}},
  booktitle = {AI4Physics @ ICML},
  year = {2026},
  doi = {10.48550/arxiv.2605.08212},
}
Figure