Can Large Language Models Model Programs Formally?
This paper introduces Model-Bench, a benchmark and pipeline comprising 400 Python programs designed to evaluate and improve Large Language Models' ability to automatically generate verification-ready model checking specifications, revealing significant current limitations in this capability.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a very talented, super-fast translator who speaks every human language and can write code in Python. You ask this translator to take a complex Python program and rewrite it into a completely different language called TLA+.
But here's the catch: TLA+ isn't just another programming language for building apps. It's a mathematical language for proving truth. It's like asking a translator to turn a novel into a rigorous mathematical proof that guarantees the story cannot have a plot hole.
This paper, titled "Can Large Language Models Model Programs Formally?", asks a simple but tough question: Can AI (like the translator) actually do this job?
Here is the breakdown of their journey, using some everyday analogies.
1. The Problem: The "Blueprint" Gap
In the world of software, there are two ways to check if a program is safe:
- Testing: Driving a car on a few different roads to see if it breaks. (Good, but you might miss a hidden cliff).
- Formal Verification: Building a perfect mathematical blueprint of the car and proving, with math, that it cannot fall off a cliff, no matter what.
The "blueprint" part is called Model Checking. It's incredibly hard to do automatically because turning messy, flexible code (like Python) into a rigid, mathematical blueprint (TLA+) is like trying to turn a free-flowing jazz improvisation into a strict military marching order.
Until now, AI has been great at helping with the "math proof" part (Theorem Proving), but it has struggled with the "blueprint" part (Model Checking) because the AI gets confused by the messy details of real-world code.
2. The Solution: Model-Bench (The Training Gym)
The authors built a new gym called Model-Bench.
- The Workout: They took 400 Python programs (from popular coding challenges) and asked various AI models to turn them into TLA+ blueprints.
- The Goal: To see if the AI can create a blueprint that a "Model Checker" (a strict referee) can verify without errors.
- The Twist: They didn't just throw the code at the AI. They tried two different coaching methods:
- Direct Translation: "Here is the Python code, turn it into TLA+."
- The "Pre-Processing" Trick: Before asking the AI, they ran the code through a robot that simplified it. They stripped away complex features (like fancy loops or weird libraries) and turned the code into a simple "state machine" (like a flowchart). This made the code look more like the TLA+ language the AI needed to speak.
3. The Results: The AI is Trying, But It's Stumbling
The results were a mix of "Not bad!" and "Oh no."
- The Good News: The best AI models (like DeepSeek-V3) could successfully create a working blueprint about 50% of the time when given a few examples to learn from. That's a start!
- The Bad News: When the AI had to do it alone (without examples), it failed almost 100% of the time.
- The "State Similarity" Issue: Even when the AI got the blueprint to run, it often didn't match the original program perfectly. It was like the AI built a car that looks like the original and drives, but the engine parts are slightly different. It passed the "runnable" test but failed the "exact match" test.
4. The "Pre-Processing" Trick: A Double-Edged Sword
The authors tried that "Pre-Processing" trick (simplifying the code first).
- What happened? The blueprints became much more accurate (better similarity). The AI understood the logic better.
- The Catch: The blueprints were slightly less likely to run without crashing. Why? Because the simplified code was longer and more complex to type out, causing the AI to get "lost in the middle" of its own sentence.
- The Takeaway: Using both the original code and the simplified code together gave the best results. It's like having a human translator check the AI's work; they complement each other.
5. Why Did It Fail? (The "Bad Cases")
The authors looked at the errors and found three main reasons the AI got stuck:
- The "Dictionary" Problem: Python has built-in tools (like
sort()) that TLA+ doesn't have. The AI tried to use them anyway, causing a crash. It's like asking a chef to "use a blender" in a kitchen that only has a mortar and pestle. - The "Counting" Problem: Python counts starting at 0 (0, 1, 2...), but TLA+ counts starting at 1 (1, 2, 3...). The AI kept forgetting this rule, leading to "off-by-one" errors.
- The "Too Faithful" Problem: Sometimes the AI was too loyal to the original code. It tried to copy every single detail, including things that shouldn't be in a mathematical proof, causing the logic to break.
The Big Picture
This paper is a reality check. It tells us that while AI is amazing at writing code, it is not yet a master of formal mathematical modeling.
- Analogy: Think of AI as a brilliant apprentice carpenter. It can build a beautiful chair (write code) very fast. But asking it to draw the engineering schematics that prove the chair will never collapse under any weight (Formal Modeling) is still too hard for it. It needs more training, better tools, and perhaps a human supervisor to double-check the math.
The Future: The authors hope this "Model-Bench" will help train the next generation of AIs to become not just code writers, but code verifiers, ensuring our critical software (like self-driving cars or medical devices) is mathematically proven to be safe.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.