Mathematics on Tap: Agents, Lean, and the Research Loop
A research harness for RL and sampling
What changes when mathematical reasoning becomes easier to access?
A small change to an LLM training rule can disappear in one setting and matter in another: add the same constant to every response’s training weight. With samples drawn from the policy being trained, the extra raw update averages to zero. With samples from another distribution, it generally does not.
The distinction is straightforward to derive. What interests me is making that reasoning available while we are choosing a training rule or deciding what an experiment means.
The rapid improvement in models’ mathematical abilities, including their ability to solve open mathematical problems, made me rethink my research workflow. If this kind of reasoning is becoming easier to access, how could it change applied research, especially when we work outside our own specialty?
Over the past few years, I have worked on sampling and LLM reinforcement learning. Those experiences left me with different frustrations: in sampling, algorithms could be shaped by what made a proof manageable; in LLM RL, a theory could explain a simplified update while leaving the training run unexplained. I wanted mathematical reasoning to be easier to consult in both situations.
I call the working environment connecting questions, models, checked arguments, and experiments a research harness. Its purpose is to help us find the smallest theory that still explains the phenomenon we care about, and keep testing where it stops working.
The loop I want to make routine is simple:
flowchart TB
Q["Ask a question"] --> M["State a model"]
M --> D["Explore and derive"]
D --> L["Formalize and check in Lean"]
L --> T["Run a focused test"]
T -->|"Refine the question or assumptions"| Q
Each pass should leave us with a concrete next action: a prediction to test, an assumption to establish, or a more precise question. People and agents can contribute at every stage. I concentrate my own review on the question’s scientific value, whether the formal statement captures the intended problem, and whether the experiment can distinguish the explanations we care about. After a test, I judge what the evidence supports and what to revisit.
Formalization makes the assumptions, definitions and claimed conclusion explicit. In these projects we use Lean, a proof assistant whose kernel checks formal proofs against their statements and declared assumptions. The researcher still needs to check that those definitions and assumptions describe the actual algorithm or scientific system. Agents can help inspect that correspondence through examples and counterexamples; Lean supplies checked deductions that the next iteration can reuse.
RL: turning a change of weights into a test
In our work on RL, we describe a training rule through the coefficients it assigns to sampled responses. This lets us ask two concrete questions: which prompts does it emphasize, and how does the source of the responses affect the update?
Fix a prompt and draw \(K\) responses independently from a sampler \(\mu\). The reward \(R\) is binary. Write \(q\) for the sampler’s success probability and \(s_\theta(y)=\nabla_\theta\log\pi_\theta(y)\) for the trained policy’s score. Consider the raw ascent update \(U=K^{-1}\sum_i a_i s_\theta(y_i)\), with coefficients computed only from the group’s rewards and held fixed during differentiation.
After averaging over the other responses and group positions, let \(c_1\) and \(c_0\) be the coefficients received by correct and incorrect responses. Define \(\omega(q)=c_1-c_0\) and \(\beta(q)=q c_1+(1-q)c_0\). One decomposition then gives
\[\boxed{ \mathbb E[U] =\underbrace{\omega(q)\mathrm{Cov}_{\mu}(R,s_\theta)}_{\text{reward contrast}} -\underbrace{\beta(q)\nabla_\theta\mathrm{KL}(\mu\Vert\pi_\theta)}_{\text{sampler drift}}. }\]The derivation is short: the effective coefficient is \(c(R)=\beta+\omega(R-q)\). Multiply by the score and take expectations, using \(\mathbb E_\mu[s_\theta]=-\nabla_\theta\mathrm{KL}(\mu\Vert\pi_\theta)\) with the sampler held fixed. Here \(\beta\) is a population mean over sampled groups; it is not the mean of one realized group. The self-contained derivation gives the assumptions and endpoint cases.
On policy, this becomes a statement about prompt weighting. When the actual sampling law is \(\pi_\theta\), the score has mean zero and the drift vanishes. For success probability \(p_x\) on prompt \(x\), a fixed prompt distribution and a common coefficient rule give
\[\boxed{ \mathbb E[U] =\mathbb E_x\!\left[\omega(p_x)\nabla_\theta p_x\right] =\nabla_\theta\mathbb E_x\!\left[f(p_x)\right], \qquad f'=\omega. }\]The rule determines the marginal weight assigned to improving each prompt. The objective \(f(p)=p\) weights those improvements equally; an increasing, strictly concave \(f\) places more marginal weight on prompts with lower success probabilities. We developed the nonlinear-objective perspective in our work on Reinforce-Ada. The decomposition connects it to the coefficients of a sampled update.
Off policy, the sampler’s distribution remains in the formula. A positive \(\beta\) contributes a gradient toward that distribution; a negative \(\beta\) contributes a gradient away from it. Neither direction is automatically beneficial for reward. The contrast term is also evaluated under \(\mu\), so it generally cannot be replaced by the trained policy’s reward gradient.
This gives a direct answer to the opening example. Add a fixed constant \(\lambda\) to every response coefficient, leaving the sampler unchanged:
\[\Delta\mathbb E[U] =\lambda\mathbb E_\mu[s_\theta] =-\lambda\nabla_\theta\mathrm{KL}(\mu\Vert\pi_\theta).\]The change vanishes on policy. Off policy, it changes the tendency to fit the sampler. A baseline can therefore change more than the variance of an uncorrected off-policy update.
For a concrete comparison, take two responses per prompt:
| Coefficient rule | Reward contrast \(\omega\) | Sampler drift \(\beta\) |
|---|---|---|
| GRPO | 1 | 0 |
| Top-one RAFT | 1 | 1 |
Here updates average over the two responses. GRPO uses \((1,-1)\) on a mixed pair and zero on ties; top-one RAFT gives coefficient 2 to a highest-reward response, breaking ties uniformly. Under these conventions, their expected raw updates have the same reward contrast and differ by the sampler-score mean. Their sampling noise and optimizer trajectories can still differ.
Our Minimal-RL work supplied a practical question for the next pass through this loop: which response groups should contribute to training? Reinforce-Rej zeros the policy coefficients of multiresponse groups whose rewards are all equal. We wanted to separate what the all-correct and all-wrong groups contribute.
For the two-response model, use signed rewards \(2R-1\) and keep the original response denominator when zeroing coefficients. The on-policy identity gives:
| Filtering rule | Prompt weight \(\omega(p)\) |
|---|---|
| Keep all pairs | \(2\) |
| Zero all-wrong pairs | \(1+p\) |
| Zero all-correct pairs | \(2-p\) |
| Zero both homogeneous cases | \(1\) |
This immediately suggests useful controls. We can keep every pair and reweight prompts to match the filtered rule’s expected update. We can also filter pairs and compensate their coefficients to recover the original expected update. Matching the means makes it possible to investigate what changes through the randomness of the updates.
That brought gradient norm into the model. Let \(U\) be a random batch update and \(G=\nabla_\theta J\) the gradient of expected task reward at the initial policy. A small gradient step makes progress to first order through \(\langle U,G\rangle\). With norm clipping, the length of each realized update also enters the comparison. We used the measurable diagnostic
\[\boxed{ \mathcal S(U;G) =\frac{\mathbb E\langle U,G\rangle} {\sqrt{\mathbb E\|U\|^2}}. }\]The numerator measures the update’s component along the reward gradient. The denominator is its RMS norm, including sampling noise: \(\mathbb E\|U\|^2=\|\mathbb E U\|^2+\mathbb E\|U-\mathbb E U\|^2\). Two rules with the same mean update can therefore receive different scores. This gives us a reason to measure both direction and second moments before choosing a training comparison.
We formalized in Lean a bound connecting this score to the expected projection of a norm-clipped step when all possible updates reach the clipping threshold. The approximation error is controlled by how much the norms vary; constant norms make the relation exact. The derivation makes that connection explicit. We used the resulting diagnostic to generate a training ranking and then test it.
Before training, we fixed model-based estimates of this score from initial-model samples for six updates: the four filtering rules above and two controls with matched expected updates. We then tested the prediction in training. Across three separately analyzed sets of repeated runs, the Spearman correlations between the six scores and the six mean final sampled accuracies on MATH-500 (temperature 1, 16 samples per problem) were 0.64, 0.99 and 0.99. Each exceeded the predeclared threshold of 0.6. With greedy decoding of the same checkpoints, recorded outside the test, the six updates differed far less and the ranking held in only one of the three sets. The study summary and reported data give all six scores.
This is the loop I wanted: a filtering question produces an exact decomposition; the decomposition suggests controls; gradient geometry supplies a quantity to measure; the measurement makes a prediction that training can test. Lean checks the mathematical bound. The researcher must still judge whether a one-step model captures enough of the training process to motivate that experiment; the measured ranking then tests its usefulness. The next pass can change a filter into a continuous weight, recompute its mean and second moment, and use calibration data to choose the next comparison.
Sampling: returning to a field with a reusable foundation
I had spent some time working on sampling theory, then no longer had the bandwidth to keep pursuing it in depth. Returning to the literature, I wanted to connect analyses I had previously encountered as separate papers. A shared proof foundation could help distinguish the conditions an algorithm needs from the choices made to analyze it.
FormalizeSampling brings Langevin dynamics, proximal sampling, diffusion models, and related methods into a shared Lean framework. It includes versions of published convergence theorems, their supporting inequalities and evolution equations, and formal counterexamples. The literature map records how the analyses connect; the theorem registry records each result’s hypotheses and scope.
A practical query starts with an algorithm change: I replaced the exact drift with an estimate from an approximate inner sampler. Which guarantees survive?
The existing framework propagates conditional bias and variance through the outer chain. This makes the remaining work explicit: bound the new estimator’s errors under the required distribution, establish the moment conditions, and check the independence assumptions. Increasing the number of samples controls one part of that error; it does not automatically remove bias from the inner distribution. The outer argument can be reused once the new obligations are met. The public library provides the interface and proof.
This is where formalization matters to the workflow. A bound under the target distribution cannot silently become a bound under the algorithm’s current distribution. Samples from a correlated inner chain cannot silently become independent samples. Lean makes the needed premises part of the proof interface. The researcher still has to establish that they describe the proposed algorithm.
For a worked example, suppose the reference sampler already has a total-variation error bound of 0.01, and we allow another 0.05 for the approximate drift. In a normalized case with common initialization, total outer time 1 and drift coefficient 1, assume the estimator’s bias norm is bounded by 0.02 and its single-sample trace variance by 4, uniformly along the outer chain. With \(N\) conditionally independent inner samples, the library’s bound reduces the extra budget to the condition \((0.02^2+4/N)/8\leq 0.05^2\).
Choosing \(N=256\) satisfies that condition. An executable calculation checks the arithmetic, giving a total TV guarantee of at most 0.06 when the stated estimator and kernel assumptions hold. The proof supplies the error-propagation rule; the calculation turns it into a concrete requirement for the proposed estimator.
The next pass starts with those requirements. Can the chosen inner sampler establish the required bias and variance bounds under the outer chain’s distribution? If its samples are correlated, what replaces the \(1/N\) variance term? We can ask the agent to analyze that changed component, reuse the outer argument, and test the estimator quantities that the proof identifies. Each answer sharpens the next modeling or experimental task.
The reusable result is more than a collection of finished theorems. It is a foundation on which the next change of assumption, estimator or algorithm can be analyzed without rebuilding every argument.
Mathematics as a research harness
Mathematics is one perspective on a scientific problem. Experiments reveal behavior, computation explores specified systems, statistics assesses patterns, and mathematics asks what follows from a model and its assumptions. How easily we can access each perspective influences which questions we pursue.
Working with an agent makes it practical to weaken an assumption, request a counterexample, or follow a connection into unfamiliar literature while a design is still changing. The conversation can start in ordinary language and become precise as the question develops. That helps both a researcher returning to an old field with limited time and one entering a new field.
Formalization gives this exploration something durable to build on. Which distribution averages an error? Does a constant depend on the time horizon? In a Lean library, these details are inputs to the statements. Changing a model means checking which theorems still apply and establishing the new premises. This keeps the mathematical foundation available for the next question, while making the assumptions that need scientific scrutiny visible.
The useful result may be a better experiment. If two mechanisms fit the same observations, mathematical exploration can identify conditions under which their predictions differ, or show that a proposed measurement cannot distinguish them. Experiments then decide whether the model captures what matters. Mathematics helps choose the abstractions within that loop as well as derive their consequences.
The longer-term value of formalization automation may be to make this perspective routinely available across science. Conversation makes exploration easier to start; reusable proofs let the next investigation build on it. The working habit I want to carry into other fields is simple: ask what a model predicts, test the consequences, and build the smallest theory that continues to earn its place.