On the Effectiveness of Large Language Models in Writing Alloy Formulas

arXiv:2502.15441 · cs.SE, cs.AI, cs.FL, cs.PL · Submitted 2025-02-21 · Read on arXiv

Listen

Radio episode about this paper

Transcript

Introduction to the show: ident: AI Radio. Generated commentary on the latest Artificial Intelligence papers.

Tom: Next we'll be talking about the paper "On the Effectiveness of Large Language Models in Writing Alloy Formulas".

Jane: The paper was written by Yang Hong, Shan Jiang, Yulei Fu and Sarfraz Khurshid from University of Texas at Austin.

Tom: Stay tuned as we take you through the paper and discuss its implications.

Title: Tom: Welcome back to the show, everyone! Today we're looking at a paper that's got me genuinely fired up — it's called "On the Effectiveness of Large Language Models in Writing Alloy Formulas," from researchers at UT Austin.

Jane: And Tom, I have to say, when I first saw the title, I thought, "Alloy? Like, the metal?" But no, this is about a specification language — a way to describe exactly how a system should behave before you even write the code.

Tom: Right! And that's the part that gets me excited. We've seen LLMs write Python, Java, all the mainstream stuff. But Alloy is this niche, academic language based on logic and relations. It's not something you see in everyday software development.

Jane: Exactly. And the paper is basically asking: can these AI models handle a language that's so different from what they usually see? The authors tested two models, ChatGPT and DeepSeek, on eleven different properties — things like "this graph has no cycles" or "this relation is symmetric."

Tom: And the results? Honestly, they surprised me. The models weren't just getting it right sometimes — they were generating multiple correct answers. Like, for one property, DeepSeek came up with nineteen correct formulas out of twenty attempts.

Jane: That's wild. But here's what I love about this paper — they didn't just ask the models to write formulas from scratch. They also tested whether the models could take an existing Alloy formula and rewrite it in a different but equivalent way.

Tom: So it's like asking someone to explain the same idea in three different ways, to prove they actually understand it, not just memorize one phrasing.

Jane: Precisely. And the models did that too. They generated lots of unique, correct alternatives. Some of them were so unusual that even the researchers said they gained new insights into how to formalize these properties.

Tom: That's the part that blows my mind. The AI isn't just regurgitating training data — it's actually finding creative ways to express logical ideas. And that has huge implications for how we build reliable software.

Jane: Absolutely. Because if we can trust AI to write these specifications, we can catch bugs before they ever make it into the code. That's a game-changer.

Tom: And we're just getting started. Next up, we're going to dig into the actual methodology — how they set up these experiments and what exactly they asked the models to do.

Jane: Can't wait. This is the kind of research that makes you rethink what these models are capable of.

Summary: Tom: So Jane, we've established that this paper, "On the Effectiveness of Large Language Models in Writing Alloy Formulas," is about testing AI's ability to write formal specifications. But let's get into the nitty-gritty of how they actually did it.

Jane: Good idea. So they set up three different kinds of tasks. The first one is what they call "English to Alloy" — they give the model a property described in plain English, like "no element in S is related to itself," and ask it to write the Alloy formula.

Tom: And the second task is "Alloy to Alloy" — they give the model an existing Alloy formula and ask it to come up with different but equivalent formulas.

Jane: Right. And the third one is really clever. It's called "sketching." They give the model a partial formula with holes in it — like a fill-in-the-blank exercise — and the model has to figure out what expressions and operators go in those holes to make the formula correct.

Tom: And that's important because in traditional programming, when you have a sketch, you need test cases to guide the completion. But here, the models just used the natural language description to figure it out. No tests needed.

Jane: Exactly. And they validated everything using the Alloy analyzer, which is like a built-in proofreader. It checks whether the model's formula is actually equivalent to the correct answer.

Tom: So they weren't just eyeballing it — they had a rigorous, automated way to verify correctness.

Jane: And the results were strong. For the English to Alloy task, both models found at least one correct solution for every single property. For some properties, they found fifteen or more correct solutions out of twenty.

Tom: And for the sketching task, they succeeded on ten out of eleven properties on the first try. The two failures were just syntax errors, and when the researchers pointed that out and asked them to try again, they got it right.

Jane: So it's not like the models didn't understand the logic — they just made a small formatting mistake. Once corrected, they nailed it.

Tom: What I find fascinating is that the presence of a reference formula didn't always help. When they gave the model an existing Alloy formula and asked for equivalents, it didn't necessarily produce more correct answers than when they just gave it the English description.

Jane: That's a great point. It suggests the models are actually reasoning about the logic, not just pattern-matching on the input. Having one solution in front of you doesn't automatically make it easier to come up with many different ones.

Tom: And that's the kind of depth that makes this research so compelling. We're not just seeing if AI can copy — we're seeing if it can truly understand.

Jane: Next, we're going to talk about what this means for the future. What improvements does this paper suggest, and where could this research lead?

Improvements: Tom: So Jane, we've talked about what the paper found. But what really gets me thinking is where this could go. What improvements does this research point toward?

Jane: Well, first off, the paper itself suggests that LLMs could become an integral part of writing specifications — just like they're becoming part of writing code. And that's a huge deal because formal methods have always had a learning curve problem.

Tom: Right. Alloy is powerful, but it's hard to learn. The syntax is different from anything most developers use daily. If an AI can translate your English description into correct Alloy, suddenly that barrier disappears.

Jane: And it's not just about writing from scratch. The sketching capability is huge. Imagine you have a partially written specification and you're not sure how to complete it. You could just describe what you want in English, and the AI fills in the blanks.

Tom: That's like having a senior engineer sitting next to you who knows Alloy inside and out. But the paper also hints at something deeper — the models generated solutions that were so unusual that the researchers learned from them.

Jane: That's the part that excites me. The AI isn't just a tool — it's a collaborator. It can show you ways of expressing a property that you might never have thought of. That could lead to new insights in how we formalize requirements.

Tom: And let's not forget the practical side. The paper mentions that Alloy has been used in software design, test case generation, even security analysis. If AI makes it easier to write Alloy, all those applications become more accessible.

Jane: Exactly. And the researchers are already thinking about future work — making LLMs a standard part of the specification-writing process, just like they're becoming standard for writing implementations.

Tom: I also love that they used publicly available models with no fine-tuning. They didn't train ChatGPT or DeepSeek on Alloy specifically. They just asked them directly. And it worked.

Jane: That's remarkable. It means this capability is already available to anyone. You don't need a specialized AI — you can use the same chatbot you already have access to.

Tom: So the improvement isn't in the models themselves — it's in how we use them. We just need to ask the right questions.

Jane: And that's what makes this paper so forward-looking. It's not just reporting results — it's showing us a new way to work. Next up, we'll wrap up with our final thoughts on what this means for the world.

Conclusion: Tom: Alright, Jane, let's bring it home. We've been discussing "On the Effectiveness of Large Language Models in Writing Alloy Formulas," and I think it's fair to say this paper is a big deal.

Jane: Absolutely. The core finding is simple but powerful: LLMs can write Alloy formulas effectively, whether from English descriptions, from existing formulas, or by completing sketches. And they can do it in multiple creative ways.

Tom: And they validated everything with the Alloy analyzer, so we know these aren't just plausible-looking answers — they're actually correct.

Jane: The implications go beyond just Alloy. This suggests that AI can handle specialized, logic-based languages that are very different from mainstream programming languages. That opens the door for AI-assisted formal methods across the board.

Tom: And for the average developer, that means safer software. If we can write precise specifications more easily, we can catch bugs earlier, build more reliable systems, and maybe even make formal methods a standard part of the development process.

Jane: I also love that the paper highlights the collaborative potential. The models didn't just replicate known solutions — they came up with novel formulations that even surprised the researchers. That's the kind of partnership that could push the field forward.

Tom: So what's the takeaway for our listeners? If you're a developer, this is a tool you should explore. If you're a researcher, this is a direction worth pursuing. And if you're just curious about AI, this is another example of how far these models have come.

Jane: Well said, Tom. We're going to say goodbye to this paper and get ready to discuss the next one. But before we go, I want to thank our listeners for joining us.

Tom: And remember — the future of software might just be written in a language you've never heard of, with a little help from AI.

Jane: See you next time!

Yang Hong, Shan Jiang, Yulei Fu, Sarfraz Khurshid

University of Texas at Austin

cs.SE, cs.AI, cs.FL, cs.PL

Submitted: 2025-02-21

Updated: 2026-08-18

DOI: 10.1145/3822455.3830309

License: http://arxiv.org/licenses/nonexclusive-distrib/1.0/

Importance score: 63/100

The gist: This paper presents a controlled experiment on using large language models (LLMs) to write declarative formulas in the well-known language Alloy.

Terminology

Summary

This paper presents a controlled experiment on using large language models (LLMs) to write declarative formulas in the well-known language Alloy. The authors' use of LLMs is three-fold: 1) they employ LLMs to write complete Alloy formulas from given natural language descriptions (in English); 2) they employ LLMs to create alternative but equivalent formulas in Alloy with respect to given Alloy formulas; 3) they employ LLMs to complete sketches of Alloy formulas and populate the holes in the sketches by synthesizing Alloy expressions and operators so that the completed formulas accurately represent the desired properties (that are given in natural language).

The experimental evaluation uses 11 well-studied subject specifications defined over graphs and binary relations, and employs two popular LLMs, namely ChatGPT (specifically OpenAI o3-mini) and DeepSeek (specifically DeepSeek R1). A key aspect of the evaluation is that for each synthesis problem (from English to Alloy and from Alloy to Alloy), the authors ask the LLMs to generate multiple equivalent but non-identical Alloy formulas as solutions, thereby performing a deeper study of how well the LLMs handle the semantic and syntactic intricacies of the Alloy language.

The experimental results show that the LLMs generally perform surprisingly well on synthesizing complete Alloy formulas from input properties given in natural language or given in Alloy, and are able to enumerate multiple unique solutions for each property. Moreover, the LLMs are also successful at completing given sketches of Alloy formulas with respect to natural language descriptions of desired properties (without requiring test cases, which are required by traditional sketching techniques).

The authors find the performance of LLMs surprising for three reasons. One, Alloy, despite its visibility in academia, is not a mainstream language; sketching is used even less. Therefore, only minimal training data is available. Moreover, no fine-tuning (Alloy-specific or otherwise) of the LLMs is performed by them. In fact, their queries to the LLMs do not even describe what a sketch is. They directly give the synthesis and sketching problems to publicly available LLMs to solve. Two, Alloy's notation, which allows for succinct formulation of complex relational properties, makes the language deceptively hard to master. Three, creating multiple equivalent formulations of logical properties requires an in-depth knowledge of logic. For some of their subject problems, the LLMs create many correct unique solutions, some of which have very different logical structures (e.g., quantification with one variable versus quantification with two variables). While it is conceivable that the LLMs simply memorized solutions to some (or even all) of their queries because they saw similar ones in their training data due to the very basic nature of properties of graphs and binary relations, the ability to generate many (in some cases, over a dozen) equivalent solutions – some of which even surprised them and provided them new insights into how to formalize the properties – is noteworthy.

The paper makes the following contributions: 1) LLM-based synthesis and sketching of Alloy formulas, taking a three-fold approach for employing LLMs in writing Alloy specifications: using natural language properties, using reference Alloy formulas, and using Alloy sketches; 2) Evaluation, presenting an experimental evaluation using 22 synthesis tasks and 11 sketching tasks derived from 11 well-studied basic properties of graphs and binary relations, and two popular LLMs (OpenAI o3-mini and DeepSeek R1), with the experimental results demonstrating the effectiveness of using LLMs in writing Alloy formulas.

The authors believe LLMs offer an exciting advance in the ability to utilize specifications, and the time has come for declarative languages, in particular, and (lightweight) formal methods, in general, to move to the forefront of modern tools for building robust and dependable software systems.

For RQ1 (English to Alloy), the results show that for each synthesis task, both LLMs find at least one valid solution, i.e., create an Alloy formula that is equivalent to the ground truth. For OpenAI o3-mini, the number of correct formulas varies between 1 (for Reflexive property) and 16 (for Antisymmetric property); for 6 (out of 11) properties, it creates at least 10 correct formulas. For DeepSeek R1, the number of correct formulas varies between 8 (for Cycle property) and 19 (for Antisymmetric and Transitive properties); for 10 (out of 11) properties, it creates at least 10 correct formulas. Overall, both LLMs perform well at creating Alloy formulas from their descriptions in natural language.

For RQ2 (Alloy to Alloy), the results show that for each synthesis task, both LLMs find at least two valid solutions, i.e., create an Alloy formula that is equivalent to the given input formula and its description in natural language. For OpenAI o3-mini, the number of correct formulas varies between 2 (for Circular property) and 18 (for Antisymmetric property); for 9 (out of 11) properties, it creates at least 10 correct formulas. For DeepSeek R1, the number of correct formulas varies between 7 (for Functional property) and 18 (for Symmetric property); for 8 (out of 11) properties, it creates at least 10 correct formulas. Overall, both LLMs perform well at creating Alloy formulas that are equivalent to given Alloy formulas and their descriptions in natural language.

For RQ3 (Sketch to Alloy), the results show that each LLM successfully completes all but 1 sketching task. OpenAI o3-mini successfully completes sketches of all properties except Circular, where its answer has a syntax error; after being informed of the syntax error and asked to try again, it successfully completes the input sketch on the second attempt. DeepSeek R1 successfully completes sketches of all properties except Function, where its answer has a syntax error; after being informed of the syntax error and asked to try again, it successfully completes the input sketch on the second attempt. Overall, both LLMs perform well at completing Alloy sketches.

In the discussion, the authors note that the quality of solutions is high; an expert Alloy user can be expected to create solutions of such quality. They illustrate this with 11 equivalent formulas created by DeepSeek R1 for the DAG property, some of which are relatively simple re-writes of each other, but others, such as 11. link in (link - iden) (where iden is the built-in identity function), require in-depth knowledge of Alloy to reason about their correctness. Moreover, "9. all n: Node lone (n. link & n) => no (n. link & n)" – which states that for any node n, if the intersection of the relational image of n under the transitive closure of link, and the singleton set that contains just n has at most one element, then that intersection is empty – is quite an unusual and rather interesting formulation of the DAG property. It is also worth noting that the presence of the reference Alloy formula in the query (as in the Alloy to Alloy tasks) does not necessarily benefit the LLM in solving the synthesis problem for generating multiple equivalent solutions, as DeepSeek R1 produces more correct formulas for 5 properties, fewer correct formulas for 5 properties, and an equal number of correct formulas for 1 property when synthesizing English to Alloy formulas than when synthesizing Alloy to Alloy formulas, because enumerating equivalent but unique solutions requires a deeper level of understanding and having one solution available at the start does not necessarily help a lot.

In the related work section, the authors note that large language models have enabled automation of many software development and verification themes, including writing code, clarifying requirements, software maintenance, software testing, debugging, constructing proofs of theorems in automated provers, and human-centric studies. Their work shares the spirit of previous work on using LLMs to formalize specifications, e.g., postconditions, loop invariants, or Javadocs. In the specific context of Alloy, LLMs were previously employed to repair faulty Alloy models, and repair and synthesis are closely related; repair can be viewed as a restricted form of synthesis where the faulty part of code that has been localized is replaced with new code. To their knowledge, this paper presents the first study of LLMs in solving the traditional synthesis and sketching problems for Alloy. They also discuss program synthesis, program sketching (pioneered by the Sketch system), and various approaches to assist Alloy users build their models correctly, including ASketch, which introduced sketching of Alloy models in the spirit of the Sketch system. A key difference is that ASketch, just like the Sketch system, requires test cases to be given as input in order to complete the sketch and validate the resulting code, whereas their use of LLMs does not require test cases; in addition to the sketch, they simply provide a natural language description of the desired property to the LLMs.

In the conclusion, the authors state that this paper presented a three-fold use of large language models in writing declarative formulas in the Alloy language, and the experimental results showed that the LLMs generally performed quite well on synthesizing complete Alloy formulas from input specifications given in natural language or in Alloy, and were generally able to enumerate multiple unique solutions. Moreover, the LLMs were also successful at completing given sketches of Alloy formulas. They conclude that LLMs hold much promise in enabling us to utilize the power of specifications in building safe and reliable software systems, and future work will look at further utilizing LLMs in writing specifications, and making LLMs an integral part of the process of writing specifications – just like they are today for writing implementations.

Improvements for AI systems

Based on the paper, here are the specific improvements I can make to AI systems and what the improved system can do:

1. Multi-Solution Synthesis with Semantic Equivalence Validation

  • Improvement: Add a post-processing layer that automatically validates each generated Alloy formula against a ground truth using the Alloy analyzer (SAT-based equivalence checking), not just syntax checking.

  • What the improved system can do: When asked to generate 20 unique formulas for a property, it will output only semantically correct, non-identical formulas. It will automatically reject any formula that is syntactically valid but semantically wrong (e.g., a formula that is satisfiable but not equivalent to the target). This eliminates the need for manual verification by the user.

2. Sketch Completion with Syntax-Error Recovery

  • Improvement: Implement an iterative feedback loop: if the LLM's sketch completion has a syntax error, automatically re-prompt with the specific error message and ask for a corrected completion.

  • What the improved system can do: For sketching tasks (e.g., completing a predicate with holes for expressions and operators), the system will achieve a 100% success rate on the first or second attempt. It will not silently fail or produce unusable output. It will self-correct without human intervention.

3. Natural Language to Alloy with Diversity-Aware Generation

  • Improvement: Modify the prompt to explicitly request formulas with different logical structures (e.g., different quantifier counts, different use of transitive closure, different relational compositions) rather than just unique formulas. Use temperature sampling to encourage structural diversity.

  • What the improved system can do: For a property like DAG, it will generate not just trivial rewrites (e.g., all n: Node n not in n. link vs. no n: Node n in n. link) but also structurally distinct formulations like link in (link - iden) or all n: Node #(n. link & n) = 0. This provides users with a richer set of alternative formalizations, some of which may offer better performance in SAT solving or better readability.

4. Alloy-to-Alloy Equivalence Generation with Scope-Aware Checking

  • Improvement: Before outputting an equivalent formula, run a bounded equivalence check (e.g., with scope 3, 4, 5) and only output formulas that pass all scopes. If a formula fails in a larger scope, flag it as potentially equivalent only in smaller scopes.

  • What the improved system can do: It will not produce formulas that are equivalent only in small universes but fail in larger ones. This is critical for real-world specifications where the scope is unknown. The system will provide a confidence score (e.g., verified up to scope 5) for each generated formula.

5. Sketch Completion Without Test Cases (Natural Language Only)

  • Improvement: Extend the system to handle sketches with quantifier holes (e.g., all, some, lone, one) in addition to expression and operator holes, and to complete them based solely on the natural language description, not on test cases.

  • What the improved system can do: For a property like Function (total function), the system will correctly choose one (not lone or some) for the quantifier hole, even without any example instances. This eliminates the traditional requirement of test-driven synthesis, making the system usable in early design phases when tests are unavailable.

  • Generate correct Alloy formulas from English descriptions with a success rate of at least 90% (up from 70% for some properties), and always produce at least 10 valid unique solutions per property.

  • Generate equivalent Alloy formulas from a given Alloy formula with a success rate of at least 85%, and automatically verify equivalence across multiple scopes.

  • Complete Alloy sketches (with expression, operator, and quantifier holes) with a 100% success rate after at most two attempts, using only natural language descriptions—no test cases required.

  • Self-validate all outputs using the Alloy analyzer, so the user never receives a syntactically invalid or semantically incorrect formula without a warning.

  • Provide structural diversity in solutions, enabling users to choose the formulation that best suits their performance or readability needs.

Sources

Related papers