Mutant-Contrast Scoring: Catching Unfaithful Lean Formalizations Without Proof Search

When a language model translates a mathematics problem into Lean, a theorem-proving language, the output can compile perfectly and still state the wrong theorem. A ≤ becomes <, a hypothesis is dropped, a constant changes, or the statement becomes true only over the empty set. The Lean checker cannot see any of this, because it only verifies that a proof proves the stated proposition. It has no way to check that the proposition is the one a human meant. This proposal borrows one idea from machine-generated text detection: judge a text by how its likelihood compares with the likelihood of its small edits, not by its likelihood alone. We turn that idea into a faithfulness test for formal statements. Given an informal problem and a candidate Lean statement, we generate the candidate's one-step semantic mutants (operator flips, dropped or added hypotheses, changed constants, swapped quantifiers). We then ask a Lean-specialized language model whether the candidate is more plausible than all of its neighbors. A faithful translation should be a clear local optimum. An unfaithful one should have a neighbor, often the correct statement, that the model prefers.

The test needs no training, no reference formalization, and no call to the proof search that equivalence checking requires. Its best-scoring mutant also doubles as a proposed repair. The central empirical question is whether the contrast signal only appears when the scoring model was trained on formal mathematics. This is the part where domain-specific pre-training is not a side detail but the variable under test.

Core Claim

Raw token likelihood is a weak faithfulness signal in formal languages. Lean statements are short and heavily constrained by the grammar, so their likelihood mostly reflects length, notation, and library naming. The detection literature met a milder version of this problem in prose and solved it by normalizing against perturbations. DetectLLM introduced two scores: a log-likelihood to log-rank ratio, and a normalized perturbed log-rank (NPR) that compares a text's token ranks before and after random rewrites. The finding behind NPR is that machine text sits at a sharp likelihood peak that perturbations fall off.

Our claim has three parts. First, the right perturbations for formal statements are not random paraphrases. They are type-correct, meaning-changing edits drawn from the known taxonomy of autoformalization errors. Second, the relative score of a candidate against these mutants, conditioned on the informal text and averaged over meaning-preserving rewrites such as variable renaming, separates faithful from unfaithful statements better than absolute confidence does. Third, it does so only under a model that has absorbed formal-mathematics structure through domain pre-training.

Concretely, let $x$ be the informal statement, $y$ the candidate, $M(y)$ its set of well-typed one-step mutants, and $s(\cdot \mid x)$ the per-token conditional log-probability averaged over a small set of renamings and hypothesis reorderings. The score is

$$D(y) = \frac{s(y \mid x) - \max_{m \in M(y)} s(m \mid x)}{\sigma_{M}(x)},$$

where $\sigma_M(x)$ is the standard deviation of $s$ over the mutants. Dividing by it makes scores comparable across problems. $D(y) > 0$ means the candidate beats every neighbor. We also report a mean-based variant closer to NPR.

Relation to Prior Work

Three works motivate the gap by showing that compile-clean but unfaithful formal code is common and costly. Faults in Our Formal Benchmarking audits roughly 10,000 benchmark problems and certifies 398 real issues, including counterexamples and vacuous theorems, in statements that compiled. A benchmark for vericoding finds about 9% of specifications weak enough to admit trivial solutions. From Agents to Axioms reports agent-written Lean that proved statements holding only vacuously. That pipeline filters such code with external gates (build, sorry grep, axiom audit) and has no model-level signal for semantic faults. Our score is meant to sit in exactly that gap.

Two works are the direct competitors, and each supplies part of our method. Rethinking and Improving Autoformalization defines BEq, which certifies equivalence to a reference statement by generating bidirectional Lean proofs. It is highly precise, but it needs a reference formalization and bounded proof search. We need neither. FormalAlign fine-tunes Mistral-7B with a contrastive loss that pushes rule-perturbed statements away from their informal source, then scores alignment with certainty plus cosine similarity. We reuse its perturbation categories as our mutation operators. The difference is that we use them at test time, as a local neighborhood to compare against, rather than at training time as negatives. We also evaluate on the natural errors models make, where FormalAlign's rule-generated negatives may not match the real distribution.

CertJudge constrains the design. It shows that frontier LLM judges change their verdicts under alpha-renaming, meaning a consistent change of variable names that leaves the logic untouched. Averaging $s$ over renamings is our direct answer to that failure. The averaging is inspired by the identifier-stripping normalization in MonoCoder, which made a domain-pretrained model robust to renaming.

Finally, Intrinsic Dimension Estimation for Robust Detection of AI-Generated Texts offers a geometric alternative. It finds that human prose embeddings span about 9 dimensions against about 7.5 for machine text. We deliberately do not build on it. Its signal is estimated over long passages, and MGTBench documents that detectors degrade sharply on short inputs. A single theorem statement is the shortest input there is.

Research Program

The system has three parts. The first is a Lean-aware mutation engine that parses a statement into its hypotheses and goal and applies typed edits. These edits are relation flips (≤/</=/≠), deletion of one hypothesis, insertion of a common side condition (positivity, nonemptiness, measurability), perturbation of numeric constants, quantifier swaps, and domain changes (ℕ/ℤ/ℝ). Every mutant is elaborated by Lean, and only type-correct mutants are kept. This makes compilation a free filter rather than the decision-maker.

The second part is the scorer. It computes the conditional likelihood of each statement given the informal text under a chosen base model, averaged over five meaning-preserving rewrites.

The third part is a controlled comparison of scoring models, since this is where domain pre-training enters as the independent variable. We compare three models. The first is a Lean-specialized model, the 8B model from Goedel-Prover-V2, which was trained on scaffolded synthetic Lean data. The second is a general code-and-text model of similar size. The third is that same general model LoRA-adapted on the same volume of Lean text, which separates "saw Lean during pre-training" from "was lightly adapted to Lean." This third condition tests the claim from A Comparative Study of PEFT Methods for Python Code Generation, that domain pre-training predicts downstream success better than any parameter-efficient adaptation.

Baselines

The naive reference point is the per-token conditional log-likelihood of the candidate under the same Lean-specialized model, with no mutants. This baseline is also the key ablation. If mutant contrast does not beat raw likelihood from the identical model on the identical inputs, the core claim is false. We will also run a mean-over-random-token-perturbation score in the style of DetectLLM's NPR, with an equal number of forward passes. This isolates whether the semantic structure of the mutants matters, or whether any perturbation budget would do.

The strongest learned competitor is FormalAlign. It is the only existing system trained specifically to catch compile-clean misalignment, and on FormL4-Basic it reports 93.65% detection precision against GPT-4's 42.68% FormalAlign. It also reports an Alignment-Selection score of 66.39% on MiniF2F-Valid versus 64.34% for GPT-4. We will run the released FormalAlign scorer as-is, and also retrain it on our base models with the same Lean data used for our LoRA condition, so that model capacity and data exposure are matched.

Beating FormalAlign on FormL4-Basic is not our bar, because its training perturbations come from the same family as that test set. The bar is higher AUROC and higher precision at 80% recall on the natural-error set described below, while staying within a few points of it on FormL4. We also require that its precision exceed 42.68% while remaining close to 93.65% on FormL4-Basic.

The strongest reference-based method is BEq, which reports 100% precision and 90.50% accuracy on a 200-pair expert-labeled set Rethinking and Improving Autoformalization. We do not expect to beat it where a reference exists. We compare accuracy against wall-clock cost on that set, and we treat matching its accuracy within ten points at a small fraction of its compute as a success.

The LLM-as-judge baseline is a frontier model prompted with chain-of-thought to check faithfulness, given the same informal text, and run under CertJudge's alpha-renaming stability test.

Why not just…?

Why not just use the model's raw confidence, as FormalAlign's certainty term already does? This is the most serious threat, because our score is built from the same likelihoods. Our argument is that raw confidence confounds faithfulness with statement length and notation, and a same-length mutant cancels that confound. But the argument is only a hypothesis until the ablation in the Baselines section is run. If raw likelihood matches mutant contrast on natural errors, we will report that the mechanism adds nothing and the domain-model comparison becomes the main result.

Why not just run BEq or a prover? BEq needs a trusted reference formalization, which does not exist in the setting that matters most: formalizing new mathematics or auditing an agent's library. Its proof search also has a finite budget. On ProofNet it reached 18.18% BEq@8 as a success rate for its retrieval-augmented autoformalizer, which shows how often search-based equivalence stays inconclusive. We keep BEq as the label source and the upper bound, not as a competitor in the reference-free setting.

Why not just add a cheap symbolic vacuity check, trying to derive False from the hypotheses with automation? For vacuous statements specifically, this may well work as well as or better than our score, and we will not claim otherwise. We run it as a separate baseline and report results per error type. We also report the union of the two methods, so the contribution is stated only for relation flips, dropped hypotheses, and wrong constants, which the vacuity check cannot see.

Why not just ask a frontier LLM? CertJudge shows these judges fail alpha-renaming stability, FormalAlign reports 42.68% precision for GPT-4, and BEq's authors report 48–82% accuracy for judge baselines. We rerun such a judge on our data rather than rely on these numbers alone.

Proposed Experiments

The main test set consists of natural errors. We run several autoformalizers, including our base models and a frontier model, on the informal statements of miniF2F, ProofNet, and the out-of-distribution Con-NF benchmark from Rethinking and Improving Autoformalization. We keep only outputs that compile. Each output is labeled faithful or unfaithful by BEq against the reference, which is reliable in the "equivalent" direction given BEq's reported precision. Outputs BEq cannot resolve are labeled by a human on a stratified subset. Secondary sets are FormL4-Basic and FormL4-Random, the 200-pair human equivalence set, and the 398 certified defects from the benchmark audit, which are human-written errors and so test transfer beyond model-generated mistakes. Metrics are AUROC, precision at fixed recall, true-positive rate at 1% false-positive rate (mirroring the detection literature's operating point), verdict flip rate under alpha-renaming, and seconds per statement. We also measure repair accuracy: how often the top-scoring mutant of an unfaithful candidate is BEq-equivalent to the reference.

Three checks decide the proposal. The first is a coverage check run before anything else: what fraction of natural unfaithful outputs lie within one mutation of a reference-equivalent statement? If coverage is low, local contrast cannot work, and we extend to two-step mutants or stop. The second is the raw-likelihood ablation described above. The third is the domain-model contrast. If the gap between specialized and general models is large for mutant contrast but small for raw likelihood, domain pre-training is what supplies the signal. If LoRA adaptation closes that gap, the result instead undercuts the pre-training claim in the PEFT study for this detection task, and we will report it that way.