Abstract
Coding conventions for naming, spacing, and other essentially stylistic properties are necessary for developers to effectively understand, review, and modify source code in large software projects. Consistent conventions in verification projects based on proof assistants, such as Coq, increase in importance as projects grow in size and scope. While conventions can be documented and enforced manually at high cost, emerging approaches automatically learn and suggest idiomatic names in Java-like languages by applying statistical language models on large code corpora. However, due to its powerful language extension facilities and fusion of type checking and computation, Coq is a challenging target for automated learning techniques. We present novel generation models for learning and suggesting lemma names for Coq projects. Our models, based on multi-input neural networks, are the first to leverage syntactic and semantic information from Coq's lexer (tokens in lemma statements), parser (syntax trees), and kernel (elaborated terms) for naming; the key insight is that learning from elaborated terms can substantially boost model performance. We implemented our models in a toolchain, dubbed Roosterize, and applied it on a large corpus of code derived from the Mathematical Components family of projects, known for its stringent coding conventions. Our results show that Roosterize substantially outperforms baselines for suggesting lemma names, highlighting the importance of using multi-input models and elaborated terms.
Introduction
In large-scale formal verification projects, naming conventions are more than just "style"—they are essential for navigating complex mathematical proofs. However, naming lemmas in Coq is notoriously difficult for both humans and machines. Unlike Java, where method names are often descriptive English phrases, Coq lemma names are frequently short, highly abbreviated, and packed with logical meaning (e.g., extprod_mulgA). Furthermore, Coq allows for user-defined notations and complex type-checking that hide the true structure of a statement from simple text-based models. Existing tools for "big code" struggle with Coq because the surface-level syntax is often too sparse or inconsistent to learn from effectively.
Methodology
The researchers developed Roosterize, a tool that uses deep learning to automatically suggest idiomatic names for lemmas. The core of Roosterize is a multi-input encoder-decoder neural network (specifically using LSTMs) that processes three distinct representations of a lemma:
- Lemma Statement: Raw tokens written by the user.
- Syntax Tree: The structure produced by Coq’s parser.
- Kernel Tree (Elaborated Terms): The version of the code after Coq has resolved all notations, implicit arguments, and types.
The key insight is that the elaborated terms provide much richer semantic information than raw source code. To manage the complexity of these trees, the team implemented "Tree Chopping"—heuristics that prune irrelevant information—and flattened the trees into sequences. They also utilized a Copy Mechanism to allow the model to reuse specific tokens from the input and sub-tokenization to handle dense abbreviations.
Experimental Setup
The models were trained and evaluated on two primary datasets:
- Core Corpus: 164,000 lines of code (LOC) from the Mathematical Components (MathComp) family, known for its strict naming conventions.
- Expanded Corpus: 21 Coq projects totaling over 297,000 LOC to test generalization across libraries following MathComp-style conventions.
Results and Discussion
Quantitative results indicate that the best model, which combines the lemma statement and the chopped kernel tree, achieved a BLEU score of 47.2. This significantly outperforms retrieval-based baselines (28.3) and models that omit elaborated terms.
Qualitatively, a manual study by a maintainer of the PCM library (external to the training set) found that 20% of the suggestions were of high quality, often suggesting more descriptive or consistent names than the originals (e.g., suggesting kfilter instead of kfilt). The findings reinforce the "naturalness" of proofs—the idea that formal proofs exhibit statistical regularities that can be captured by language models. However, the study also found that manually "chopping" trees to remove noise was more effective than relying solely on neural attention mechanisms, as the raw trees were often too large for the attention mechanism to process efficiently.
Conclusion
Roosterize demonstrates that leveraging the internal representations of a proof assistant's kernel can substantially improve the performance of automated naming tools. While currently tuned to the MathComp style and dependent on Coq-specific serialization (SerAPI), this approach paves the way for more sophisticated developer tools in formal verification. Future work includes extending these techniques to other proof assistants like Lean or Isabelle and exploring broader applications in library restructuring and discoverability.
Summary updated