Can LLMs Reason About Program Semantics? A Comprehensive Evaluation of LLMs on Formal Specification Inference
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
- 2024Qwen2.5-Coder Technical Report18 Sep
- 2024Reasoning Runtime Behavior of a Program with LLM: How Far Are We?25 Mar
- 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code12 Mar
Other references · 20
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2021Measuring Mathematical Problem Solving With the MATH Datasetcited by 5,203
- 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Modelscited by 1,397
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
- 2024DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Modelcited by 1,093
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
- 2022Multi-lingual Evaluation of Code Generation Modelscited by 158
- 2023Can Large Language Models Infer Causation from Correlation?cited by 142
8 more
- 2023Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issuescited by 78
- 2024Enchanting Program Specification Synthesis by Large Language Models using Static Analysis and Program Verificationcited by 55
- 2020On the Generalizability of Neural Program Models with respect to Semantic-Preserving Program Transformationscited by 41
- 2015On the "Naturalness" of Buggy Codecited by 35
- 2023Ranking LLM-Generated Loop Invariants for Program Verificationcited by 33
- 2024Robustness, Security, Privacy, Explainability, Efficiency, and Usability of Large Language Models for Codecited by 26
- 2021Challenging Machine Learning-based Clone Detectors via Semantic-preserving Code Transformationscited by 15
- 2024Towards Reliable Evaluation of Neural Program Repair with Natural Robustness Testingcited by 5
Built on by
Citing papers per year: 2025: 7; 2026: 7.
14 papers.
Sort:
By area:
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunitiescited by 26
- 2025The Hitchhiker's Guide to Program Analysis, Part II: Deep Thoughts by LLMscited by 4
- 2025CodeReasoner: Enhancing the Code Reasoning Ability with Reinforcement Learningcited by 4
- 2025Evaluating Code Reasoning Abilities of Large Language Models Under Real-World Settingscited by 3
- 2026AutoReSpec: A Framework for Generating Specification using Large Language Modelscited by 3
- 2025Evaluating Program Semantics Reasoning with Type Inference in System Fcited by 2
- 2026Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specificationscited by 2
- 2026CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generationcited by 2
- 2026Perish or Flourish? A Holistic Evaluation of Large Language Models for Code Generation in Functional Programmingcited by 1
- 2026VeriContest: A Competitive-Programming Benchmark for Verifiable Code Generationcited by 1
- 2025From Benchmark Data To Applicable Program Repair: An Experience Reportcited by 0
- 2025Enhancing Neural Code Representation with Additional Contextcited by 0
2 more
- 2026SpecPylot: Python Specification Generation using Large Language Modelscited by 0
- 2026Self-Spec Verifiable Code Generationcited by 0
- 2026Self-Spec Verifiable Code Generation30 Sep 2026
- 2026VeriContest: A Competitive-Programming Benchmark for Verifiable Code Generation8 May 2026
- 2026SpecPylot: Python Specification Generation using Large Language Models17 Apr 2026
- 2026CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generation14 Apr 2026
- 2026AutoReSpec: A Framework for Generating Specification using Large Language Models4 Apr 2026
- 2026Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specifications31 Mar 2026
- 2026Perish or Flourish? A Holistic Evaluation of Large Language Models for Code Generation in Functional Programming5 Jan 2026
- 2025Evaluating Code Reasoning Abilities of Large Language Models Under Real-World Settings16 Dec 2025
- 2025Enhancing Neural Code Representation with Additional Context14 Oct 2025
- 2025Evaluating Program Semantics Reasoning with Type Inference in System F28 Sep 2025
- 2025From Benchmark Data To Applicable Program Repair: An Experience Report22 Aug 2025
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunities15 Aug 2025
- 2025The Hitchhiker's Guide to Program Analysis, Part II: Deep Thoughts by LLMscited by 4
- 2026AutoReSpec: A Framework for Generating Specification using Large Language Modelscited by 3
- 2026Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specificationscited by 2
- 2026CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generationcited by 2
- 2026Perish or Flourish? A Holistic Evaluation of Large Language Models for Code Generation in Functional Programmingcited by 1
- 2026VeriContest: A Competitive-Programming Benchmark for Verifiable Code Generationcited by 1
- 2025From Benchmark Data To Applicable Program Repair: An Experience Reportcited by 0
- 2025Enhancing Neural Code Representation with Additional Contextcited by 0
- 2026SpecPylot: Python Specification Generation using Large Language Modelscited by 0
- 2026Self-Spec Verifiable Code Generationcited by 0
- 2026Self-Spec Verifiable Code Generation30 Sep 2026
- 2026VeriContest: A Competitive-Programming Benchmark for Verifiable Code Generation8 May 2026
- 2026SpecPylot: Python Specification Generation using Large Language Models17 Apr 2026
- 2026CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generation14 Apr 2026
- 2026AutoReSpec: A Framework for Generating Specification using Large Language Models4 Apr 2026
- 2026Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specifications31 Mar 2026
- 2026Perish or Flourish? A Holistic Evaluation of Large Language Models for Code Generation in Functional Programming5 Jan 2026
- 2025Enhancing Neural Code Representation with Additional Context14 Oct 2025
- 2025From Benchmark Data To Applicable Program Repair: An Experience Report22 Aug 2025
- 2025The Hitchhiker's Guide to Program Analysis, Part II: Deep Thoughts by LLMs16 Apr 2025
Similar, not cited
Close in wording, no citation either way
- 2025Understanding Formal Reasoning Failures in LLMs as Abstract Interpreters
- 2025LLMs Lean on Priors, Not Programming Language Semantics
- 2025CoRe: Benchmarking LLMs Code Reasoning Capabilities through Static Analysis Tasks
- 2025Disproving Program Equivalence with LLMs
- 2025EquiBench: Benchmarking Large Language Models' Reasoning about Program Semantics via Equivalence Checking
- 2026Inferring Code Correctness from Specification
- 2025Do Code Semantics Help? A Comprehensive Study on Execution Trace-Based Information for Code Large Language Models
- 2025Demystifying Errors in LLM Reasoning Traces: An Empirical Study of Code Execution Simulation