mlsanityData to 7 Oct 2026

Can LLMs Reason About Program Semantics? A Comprehensive Evaluation of LLMs on Formal Specification Inference

arXiv 2503.04779 ↗First posted 22 Feb 2025cs.PL cs.AI cs.SEcited by 14

On the map: LLM reasoning → Reasoning for agents, planning and code

Abstract (arXiv)

Large Language Models (LLMs) are increasingly being used to automate programming tasks. Yet, LLMs' capabilities in reasoning about program semantics are still inadequately studied, leaving significant potential for further exploration. This paper introduces FormalBench, a comprehensive benchmark designed to evaluate LLMs' reasoning abilities on program semantics, particularly via the task of synthesizing formal program specifications to assist verifying program correctness. This task requires both comprehensive reasoning over all possible program executions and the generation of precise, syntactically correct expressions that adhere to formal syntax and semantics. Using this benchmark, we evaluated the ability of LLMs in synthesizing consistent and complete specifications. Our findings show that LLMs perform well with simple control flows but struggle with more complex structures, especially loops, even with advanced prompting. Additionally, LLMs exhibit limited robustness against semantic-preserving transformations. We also highlight common failure patterns and design self-repair prompts, improving success rates by 25%.

Key facts. Cited by 14 papers in the map (data through 7 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 23 of its 50 references that are in the map. First posted on arXiv 22 Feb 2025.

Builds on

23 of 50 references.

Closest ancestors · 3

Same direction, newest first

  1. 2024Qwen2.5-Coder Technical Report18 Sep
  2. 2024Reasoning Runtime Behavior of a Program with LLM: How Far Are We?25 Mar
  3. 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code12 Mar

Other references · 20

  1. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  2. 2021Measuring Mathematical Problem Solving With the MATH Datasetcited by 5,203
  3. 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
  4. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  5. 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Modelscited by 1,397
  6. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
  7. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  8. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  9. 2024DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Modelcited by 1,093
  10. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
  11. 2022Multi-lingual Evaluation of Code Generation Modelscited by 158
  12. 2023Can Large Language Models Infer Causation from Correlation?cited by 142
8 more
  1. 2023Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issuescited by 78
  2. 2024Enchanting Program Specification Synthesis by Large Language Models using Static Analysis and Program Verificationcited by 55
  3. 2020On the Generalizability of Neural Program Models with respect to Semantic-Preserving Program Transformationscited by 41
  4. 2015On the "Naturalness" of Buggy Codecited by 35
  5. 2023Ranking LLM-Generated Loop Invariants for Program Verificationcited by 33
  6. 2024Robustness, Security, Privacy, Explainability, Efficiency, and Usability of Large Language Models for Codecited by 26
  7. 2021Challenging Machine Learning-based Clone Detectors via Semantic-preserving Code Transformationscited by 15
  8. 2024Towards Reliable Evaluation of Neural Program Repair with Natural Robustness Testingcited by 5

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 7; 2026: 7.

14 papers.

Sort:

By area:

Similar, not cited

Close in wording, no citation either way

  1. 2025Understanding Formal Reasoning Failures in LLMs as Abstract Interpreters
  2. 2025LLMs Lean on Priors, Not Programming Language Semantics
  3. 2025CoRe: Benchmarking LLMs Code Reasoning Capabilities through Static Analysis Tasks
  4. 2025Disproving Program Equivalence with LLMs
  5. 2025EquiBench: Benchmarking Large Language Models' Reasoning about Program Semantics via Equivalence Checking
  6. 2026Inferring Code Correctness from Specification
  7. 2025Do Code Semantics Help? A Comprehensive Study on Execution Trace-Based Information for Code Large Language Models
  8. 2025Demystifying Errors in LLM Reasoning Traces: An Empirical Study of Code Execution Simulation