arXiv:2610.30059cs.SEOct 2026

Manuscript Offprint

arXiv:2610.30059

Validating Autoformalized Specifications via Contrapuntal Languages

Yihan Dai, Xuanlin Liu, Haoxiang Jia, Tianchi Li, Xin Zhang, Sergey Mechtaev

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

YIHAN DAI, Peking University, China

XUANLIN LIU, Nankai University, China

HAOXIANG JIA, Peking University, China

TIANCHI LI, Peking University, China

XIN ZHANG, Peking University, China

SERGEY MECHTAEV*, Peking University, China

Formal specifications can make AI-generated code mechanically checkable. Because user intent is typically expressed in natural language rather than formal logic, specifications must first be derived from it, e.g., via LLM-based autoformalization. Yet autoformalized specifications are themselves untrusted, so a key challenge is validating whether they capture user intent without relying on a costly oracle such as human review. In this oracle-free setting, a natural strategy is to vote among model outputs, but because model errors are often correlated, agreement among outputs may reflect shared mistakes rather than correctness. Our key insight is that these errors can be decorrelated through representational diversity. We achieve this diversity with contrapuntal languages: pairs of task-specific formal languages, each designed to express the intended specification, yet admitting no structure-preserving translation between them. An LLM formalizes the intent independently in each language, and we accept a specification only if a solver proves the two formalizations equivalent. Because the model must discover separately how to express the intent in each language's constructs, agreement is less likely to reflect a correlated error than agreement within a single language. To construct such languages, we present a synthesis algorithm that reuses fragments of sampled seed specifications as syntactic sugar over a base specification language. We implement the approach for first-order logic specifications and evaluate it on HumanEval+ and LiveCodeBench using GPT-5.4 mini and Qwen3.6-Flash with and without thinking. Over the strongest baseline among direct generation, plurality voting, and round-trip verification, our method increases the proportion of accepted specifications that are correct, i.e., complete and sound, by 12.0% on HumanEval+ and 42.9% on LiveCodeBench. The accepted specifications judged complete are more effective at detecting bugs: they reject 98.6% of buggy program variants on HumanEval+ and 96.2% on LiveCodeBench, compared with 92.8% and 78.3% for the strongest baseline. A case study shows how disagreement between contrapuntal languages can surface ambiguity in a natural-language task.

CCS Concepts: • Software and its engineering → Automatic programming; Formal software verification; • Computing methodologies → Natural language processing.

Additional Key Words and Phrases: Intent Autoformalization, Specification Validation, Large Language Models

1 Introduction

As large language models (LLMs) generate code faster than humans can review it [7, 27], the central challenge is shifting from generating code to determining whether that code faithfully captures the user's intent. A promising answer is intent autoformalization: automatically translating natural-language intent into formal specifications against which generated code can be mechanically verified. Yet this only relocates the trust problem: if the specification is itself produced by a fallible autoformalization process, does it capture the user's intent expressed in natural language? Prior studies on HumanEval tasks show that generating behaviorally correct postconditions and contracts

∗^{*}Corresponding author.

Authors' Contact Information: Yihan Dai, Peking University, Beijing, China, yhdai25@stu.pku.edu.cn; Xuanlin Liu, Nankai University, Tianjin, China, 2312289@mail.nankai.edu.cn; Haoxiang Jia, Peking University, Beijing, China, haoxiangjia@stu.pku.edu.cn; Tianchi Li, Peking University, Beijing, China, litianchi@pku.edu.cn; Xin Zhang, Peking University, Beijing, China, xin@pku.edu.cn; Sergey Mechtaev, Peking University, Beijing, China, mechtaev@pku.edu.cn.

Dai et al.

from natural-language intent remains challenging for LLMs [8, 29, 30]. For example, even for Python contracts on HumanEval, the setting most familiar to LLMs, only 39.5% of GPT-5-generated contracts that raised no false alarms on the reference implementation rejected every evaluated mutant [30]. However, validating generated specifications typically requires costly human review, making oracle-free validation a central bottleneck for reliable AI-assisted software development [17].

How can we validate whether autoformalized specifications accurately capture the user's intent without an external oracle? A straightforward approach is voting. Plurality voting [10, 19] partitions the specifications into equivalence classes and selects the largest, i.e., the most frequently occurring semantics. However, LLM-generated artifacts often exhibit correlated errors [15]; when multiple candidates share the same mistake, plurality voting can reinforce the dominant error rather than identify the correct answer [31]. Also, plurality voting treats each candidate as an indivisible vote, ignoring its internal structure: a candidate need not be correct as a whole for some of its components to be useful. Clause2Inv [3], for example, shows that clauses extracted from invalid invariant candidates can contribute to a valid invariant. Yet reusing such fragments naively would steer the model back toward the same formalizations, and thus the same errors. The challenge is therefore to reuse useful fragments while inducing sufficiently different formalization paths.

To address these challenges, we build on the insight that representational diversity can break the correlation between errors. Inspired by linguistic determinism—the hypothesis that language shapes thought [33]—we introduce contrapuntal languages: pairs of task-specific formal languages, each designed to express the intended specification, yet admitting no structure-preserving translation between them. An LLM formalizes the intent independently in each language, and we accept a specification only if a solver proves the two formalizations equivalent. Because the model must discover separately how to express the intent in each language's constructs, cross-language agreement is less likely to reflect a correlated error than agreement within a single language.

To construct such languages, we present a synthesis algorithm that builds both languages as syntactic sugar over a base specification language. We first sample seed specifications for the task from the LLM; the algorithm then cuts each seed into fragments and turns them into language constructs, using a solver to choose cuts that carve every seed into differently shaped trees in the two languages. Since the intended specification is unknown, the seeds stand in for it: we call a language pair effectively contrapuntal for a seed set when every seed can be represented in both languages, but no AST-level structure-preserving translation relates its representations across them. This design also addresses the challenge of reusing fragments: seed fragments let the model reuse useful components, even from incorrect seeds, while the structural incompatibility of the two languages still forces separate formalization paths and thus decorrelates errors.

We implement the approach for first-order logic specifications in SMT-LIB and evaluate it on HumanEval+ [21] and LiveCodeBench [12] using GPT-5.4 mini and Qwen3.6-Flash with and without thinking. We compare it against direct generation, plurality voting, and round-trip verification, judging a specification complete if it accepts reference input–output pairs and sound if it rejects the outputs of buggy program variants. Over the strongest baseline, our method increases the proportion of accepted specifications that are both complete and sound by 12.0% on HumanEval+ and 42.9% on LiveCodeBench, and the accepted specifications judged complete reject 98.6% and 96.2% of buggy program variants, respectively, compared with 92.8% and 78.3% for the strongest baseline. An ablation shows that these gains depend on enforcing contrapuntality rather than merely using two languages, and a case study shows that disagreement between contrapuntal languages can surface ambiguity in a task description.

In summary, the paper makes the following contributions:

def can_arrange(arr): """Create a function that returns the largest index r of an element that is not greater than or equal to the element immediately preceding it. If no such element exists, then return -1. The given array will not contain duplicate values. Examples: can_arrange([1,2,4,3,5]) = 3 can_arrange([1,2,3]) = -1 """ HumanEval/135

Write an SMT-lib specification for the task below: {task description}

e.g., assume that a = [1,4,3,6,7,5,8]

LLM

n = 30

equivalence

partitioning

I. (

r=−1r = -1

①

V(descend_at(r,a)∧largest(r,a))V(\text{descend\_at}(r, a) \land \text{largest}(r, a))

②

③

cardinality correlated error!

Plurality incorrectly regards the largest equivalence class as exact.

incorrectly accept r = -1

II. (r=−1∧¬∃i.descend_at(i,a))①∨((1≤r)∧(r≤n)⑤∧largest(r,a))③\frac{(r = -1 \land \neg \exists i. descend\_at(i, a))}{①} \lor \frac{((1 \leq r) \land (r \leq n)}{⑤} \land \frac{\text{largest}(r, a))}{③}

incorrectly accept r = 6

III. (r=−1∧¬∃i.descend_at(i,a))①∨(descend_at(r,a)∧largest(r,a))②\frac{(r = -1 \land \neg \exists i. descend\_at(i, a))}{①} \lor \frac{(descend\_at(r, a) \land \text{largest}(r, a))}{②}

③

correct specification,

correctly accepts r = 5, rejects r = -1 and 6

The key components of the exact specification

①④②③ already appear in the inexact ones.

language

synthesizer

split whole samples

into small pieces

language L

Write an SMT-lib specification using the given language for the task below:

{task description}

{language}

LLM

descend_at(r, a)

r = -1

Fig. 1. Plurality voting on HumanEval/135 with n=30n = 30 samples. A correlated error (I, 8/30) outnumbers the correct specification (III, 5/30), so Plurality accepts it. Yet the key components of III already appear in the incorrect I and II, motivating language synthesis from such fragments. descend_at(i,a)≜(1≤i<∣a∣)∧(a[i]<a[i−1])descend\_at(i, a) \triangleq (1 \leq i < |a|) \land (a[i] < a[i-1]); largest(r,a)≜∀ilargest(r, a) \triangleq \forall i. (descend_at(i,a)⇒i≤rdescend\_at(i, a) \Rightarrow i \leq r).

  • A new approach that automatically validates autoformalized specifications without an oracle through contrapuntal languages.

• An algorithm to automatically synthesize contrapuntal languages with an SMT solver.

  • An evaluation on HumanEval+ and LiveCodeBench showing that contrapuntal languages accept a higher proportion of complete and sound specifications than three baselines, and that the accepted specifications judged complete detect more bugs.

All code and data are available at https://figshare.com/s/be97e0291c8ce608bcd4.

References (20)