← Latest papers
💻 computer science

Assessing Coherency and Consistency of Code Execution Reasoning by Large Language Models

This paper introduces CES, a novel evaluation framework that assesses Large Language Models' ability to simulate program execution with both correctness and coherence, revealing that despite high simulation accuracy, frontier models often rely on natural language shortcuts rather than genuine reasoning, leading to inconsistent performance and limited generalizability in complex programming tasks.

Original authors: Changshu Liu, Yang Chen, Reyhaneh Jabbarvand

Published 2026-04-08
📖 5 min read🧠 Deep dive

Original authors: Changshu Liu, Yang Chen, Reyhaneh Jabbarvand

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 smart, well-read robot assistant (a Large Language Model, or LLM) that claims it can write and understand computer code. You ask it, "If I run this program with these numbers, what will happen?"

The robot gives you an answer. But here's the problem: Is the robot actually "thinking" through the steps like a human programmer, or is it just guessing the final answer based on a lucky guess or a trick it learned during its training?

This paper introduces a new test called CES (Code Execution Simulation) to find out the truth. Think of CES as a "lie detector" for code reasoning.

The Core Problem: The "Magic Trick" vs. Real Understanding

Imagine you are teaching a student to do long division.

  • Real Understanding: The student writes down every step: "I divide 10 by 2, I get 5. I multiply 5 by 2, I get 10..."
  • The "Magic Trick" (Shortcut): The student looks at the numbers, remembers a similar problem from a textbook they memorized, and just writes down the final answer: "5."

If you only check the final answer, the student looks perfect. But if you ask them to show their work, you might find they didn't actually do the math.

Current AI models are great at the "Magic Trick." They often get the right final answer for code problems without actually simulating the code step-by-step. They might guess based on the function's name, the natural language description, or because they've seen that exact problem before (data leakage).

How CES Works: The "Step-by-Step" Audit

CES changes the game. Instead of just asking the AI, "What is the output?", CES asks: "Walk me through every single step. What is the value of variable A? What is the value of variable B? Which path did you take?"

The paper introduces two main concepts to judge the AI:

1. Coherency (Is the story consistent?)

This checks if the AI's internal story makes sense, even if the final answer is wrong.

  • Coherent (Good): The AI says, "I added 2 and 2 to get 4. Then I multiplied 4 by 2 to get 8." Even if the math was actually supposed to be different, the AI is logically consistent. It's thinking through the process.
  • Incoherent (Bad): The AI says, "I added 2 and 2 to get 4. Then I magically turned that 4 into 100 because the function name sounds like 'hundred'."
    • The Catch: Sometimes, an AI gets the right final answer (100) but for the wrong, illogical reasons (hallucination or a shortcut). CES catches this. It says, "You got the right number, but your reasoning was a lie. We don't count that as a success."

2. Consistency (Can they do it again?)

This checks if the AI is reliable.

  • Strong Consistency: The AI can solve the same puzzle with different starting numbers and still get it right every time. It truly understands the logic.
  • Weak Consistency: The AI only gets it right if the puzzle looks exactly like one it's seen before. Change the numbers slightly, and it fails.
  • Random: The AI is just guessing. It gets it right 50% of the time, but it's pure luck.

What Did They Find?

The researchers tested 16 different AI models (including the famous GPT-4 and DeepSeek-R1) using this new test. Here are the surprising results:

  1. The "Smart" Models are the Worst Liars: The most advanced models (like GPT-4) were actually the worst at being consistent. They were great at guessing the final answer but terrible at explaining the steps logically. They relied heavily on "natural language shortcuts" (guessing based on words rather than code logic).
  2. The "Magic" is Common: A huge chunk of the "correct" answers the AI gave were actually suspicious. The AI got the right answer, but its step-by-step reasoning was completely wrong. It was like a student guessing the answer on a multiple-choice test but writing a fake explanation that happens to match the key.
  3. Bug Fixing is a Gamble: The paper looked at how AI fixes bugs. They found that when AI "fixes" a bug, it often isn't because it understood why the code broke. It's often because it recognized a pattern or guessed. If you give it a brand new type of bug it hasn't seen before, it might fail because it never actually learned how to "think" about the code execution.

The Big Takeaway

Think of current AI code experts as brilliant actors. They can memorize a script and deliver a perfect performance (the right code output). But if you ask them to improvise a scene they haven't rehearsed (a new, complex logic path), they often break character because they don't truly understand the plot (the execution logic).

CES is the director who stops the play and says, "Stop! Show me your script. Did you actually read the lines, or did you just memorize the ending?"

This tool helps us stop trusting AI just because it gets the right answer, and start demanding that it actually understands how it got there. This is crucial for safety, especially when we use AI to write code for things like medical devices or self-driving cars, where a "lucky guess" isn't good enough.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →