mlsanityData to 7 Oct 2026

Chain of Code: Reasoning with a Language Model-Augmented Code Emulator

arXiv 2312.04474 ↗First posted 7 Dec 2023cs.CL cs.AI cs.LGcited by 120

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

Abstract (arXiv)

Code provides a general syntactic structure to build complex programs and perform precise computations when paired with a code interpreter - we hypothesize that language models (LMs) can leverage code-writing to improve Chain of Thought reasoning not only for logic and arithmetic tasks, but also for semantic ones (and in particular, those that are a mix of both). For example, consider prompting an LM to write code that counts the number of times it detects sarcasm in an essay: the LM may struggle to write an implementation for "detect_sarcasm(string)" that can be executed by the interpreter (handling the edge cases would be insurmountable). However, LMs may still produce a valid solution if they not only write code, but also selectively "emulate" the interpreter by generating the expected output of "detect_sarcasm(string)". In this work, we propose Chain of Code (CoC), a simple yet surprisingly effective extension that improves LM code-driven reasoning. The key idea is to encourage LMs to format semantic sub-tasks in a program as flexible pseudocode that the interpreter can explicitly catch undefined behaviors and hand off to simulate with an LM (as an "LMulator"). Experiments demonstrate that Chain of Code outperforms Chain of Thought and other baselines across a variety of benchmarks; on BIG-Bench Hard, Chain of Code achieves 84%, a gain of 12% over Chain of Thought. In a nutshell, CoC broadens the scope of reasoning questions that LMs can answer by "thinking in code".

Key facts. Cited by 120 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 44 of its 49 references that are in the map. First posted on arXiv 7 Dec 2023.

Builds on

44 of 49 references.

Closest ancestors · 2

Same direction, newest first

  1. 2023ART: Automatic multi-step reasoning and tool-use for large language models16 Mar
  2. 2022Competition-Level Code Generation with AlphaCode8 Feb

Other references · 42

  1. 2020Language Models are Few-Shot Learnerscited by 32,199
  2. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  3. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  4. 2021Training Verifiers to Solve Math Word Problemscited by 9,743
  5. 2022ReAct: Synergizing Reasoning and Acting in Language Modelscited by 8,355
  6. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  7. 2022Self-Consistency Improves Chain of Thought Reasoning in Language Modelscited by 5,601
  8. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
  9. 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
  10. 2023Toolformer: Language Models Can Teach Themselves to Use Toolscited by 4,072
  11. 2021Program Synthesis with Large Language Modelscited by 3,509
  12. 2023Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detectioncited by 3,274
30 more
  1. 2023Tree of Thoughts: Deliberate Problem Solving with Large Language Modelscited by 3,155
  2. 2022Emergent Abilities of Large Language Modelscited by 2,483
  3. 2023Voyager: An Open-Ended Embodied Agent with Large Language Modelscited by 2,081
  4. 2022Beyond the Imitation Game: Quantifying and extrapolating the capabilities of language modelscited by 1,970
  5. 2023ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIscited by 1,880
  6. 2022Challenging BIG-Bench Tasks and Whether Chain-of-Thought Can Solve Themcited by 1,767
  7. 2022Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?cited by 1,413
  8. 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Modelscited by 1,397
  9. 2022Solving Quantitative Reasoning Problems with Language Modelscited by 1,359
  10. 2022Code as Policies: Language Model Programs for Embodied Controlcited by 1,172
  11. 2023PaLM 2 Technical Reportcited by 1,154
  12. 2022Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Taskscited by 1,057
  13. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
  14. 2023Graph of Thoughts: Solving Elaborate Problems with Large Language Modelscited by 873
  15. 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
  16. 2023Large Language Models as Optimizerscited by 830
  17. 2023CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquingcited by 751
  18. 2022PAL: Program-aided Language Modelscited by 635
  19. 2022Mixture-of-Experts with Expert Choice Routingcited by 611
  20. 2022ProgPrompt: Generating Situated Robot Task Plans using Large Language Modelscited by 598
  21. 2023ViperGPT: Visual Inference via Python Execution for Reasoningcited by 591
  22. 2022Decomposed Prompting: A Modular Approach for Solving Complex Taskscited by 554
  23. 2023Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Modelscited by 550
  24. 2022Socratic Models: Composing Zero-Shot Multimodal Reasoning with Languagecited by 513
  25. 2023Augmented Language Models: a Surveycited by 398
  26. 2022TALM: Tool Augmented Language Modelscited by 197
  27. 2023Large Language Models as General Pattern Machinescited by 196
  28. 2023Solving Challenging Math Word Problems Using GPT-4 Code Interpreter with Code-based Self-Verificationcited by 166
  29. 2022Language Model Cascadescited by 104
  30. 2021A Neural Network Solves, Explains, and Generates University Math Problems by Program Synthesis and Few-Shot Learning at Human Levelcited by 96

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2023: 1; 2024: 44; 2025: 42; 2026: 33.

120 papers.

Sort:

By area:

  1. 2024A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applicationscited by 428
  2. 2024Data Interpreter: An LLM Agent For Data Sciencecited by 222
  3. 2024Forest-of-Thought: Scaling Test-Time Compute for Enhancing LLM Reasoningcited by 110
  4. 2025A Survey of Frontiers in LLM Reasoning: Inference Scaling, Learning to Reason, and Agentic Systemscited by 108
  5. 2024Functional Benchmarks for Robust Evaluation of Reasoning Performance, and the Reasoning Gapcited by 79
  6. 2024RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Horizon Generationcited by 75
  7. 2024Combining Induction and Transduction for Abstract Reasoningcited by 53
  8. 2024Granite-Function Calling Model: Introducing Function Calling Abilities via Multi-task Learning of Granular Taskscited by 52
  9. 2024Beyond Chain-of-Thought: A Survey of Chain-of-X Paradigms for LLMscited by 48
  10. 2025Code to Think, Think to Code: A Survey on Code-Enhanced Reasoning and Reasoning-Driven Code Intelligence in LLMscited by 47
  11. 2024A Survey of Prompt Engineering Methods in Large Language Models for Different NLP Taskscited by 46
  12. 2024From Code to Correctness: Closing the Last Mile of Code Generation with Hierarchical Debuggingcited by 46
38 more
  1. 2025Open Deep Search: Democratizing Search with Open-source Reasoning Agentscited by 46
  2. 2026Code as Agent Harnesscited by 40
  3. 2025ARM: Adaptive Reasoning Modelcited by 38
  4. 2024Benchmarking Agentic Workflow Generationcited by 36
  5. 2025Flow-of-Action: SOP Enhanced LLM-Based Multi-Agent System for Root Cause Analysiscited by 32
  6. 2024CoA-VLA: Improving Vision-Language-Action Models via Visual-Textual Chain-of-Affordancecited by 29
  7. 2024ROS-LLM: A ROS framework for embodied AI with task feedback and structured reasoningcited by 27
  8. 2025TIGeR: Tool-Integrated Geometric Reasoning in Vision-Language Models for Roboticscited by 27
  9. 2024Instance-adaptive Zero-shot Chain-of-Thought Promptingcited by 25
  10. 2024Steering Large Language Models between Code Execution and Textual Reasoningcited by 24
  11. 2024EVOR: Evolving Retrieval for Code Generationcited by 22
  12. 2024StateAct: Enhancing LLM Base Agents via Self-prompting and State-trackingcited by 21
  13. 2024Code Prompting Elicits Conditional Reasoning Abilities in Text+Code LLMscited by 19
  14. 2024Divide-and-Conquer Meets Consensus: Unleashing the Power of Functions in Code Generationcited by 19
  15. 2023Mixed Distillation Helps Smaller Language Model Better Reasoningcited by 18
  16. 2025Minions: Cost-efficient Collaboration Between On-device and Cloud Language Modelscited by 17
  17. 2025R1-Code-Interpreter: LLMs Reason with Code via Supervised and Multi-stage Reinforcement Learningcited by 15
  18. 2025Generalizable End-to-End Tool-Use RL with Synthetic CodeGymcited by 14
  19. 2025TUMIX: Multi-Agent Test-Time Scaling with Tool-Use Mixturecited by 13
  20. 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
  21. 2025An Efficient and Precise Training Data Construction Framework for Process-supervised Reward Model in Mathematical Reasoningcited by 12
  22. 2024Tree-of-Code: A Tree-Structured Exploring Framework for End-to-End Code Generation and Execution in Complex Task Handlingcited by 11
  23. 2025CodeSteer: Symbolic-Augmented Language Models via Code/Text Guidancecited by 11
  24. 2025Blueprint First, Model Second: A Framework for Deterministic LLM Workflowcited by 11
  25. 2024Learning to Reason via Program Generation, Emulation, and Searchcited by 9
  26. 2024Cognitive Kernel: An Open-source Agent System towards Generalist Autopilotscited by 9
  27. 2025A Systematic Survey on Large Language Models for Evolutionary Optimization: From Modeling to Solvingcited by 9
  28. 2024Large Language Models Synergize with Automated Machine Learningcited by 8
  29. 2024CodeNav: Beyond tool-use to using real-world codebases with LLM agentscited by 8
  30. 2025Policy Guided Tree Search for Enhanced LLM Reasoningcited by 8
  31. 2025ARC-GEN: A Mimetic Procedural Benchmark Generator for the Abstraction and Reasoning Corpuscited by 8
  32. 2024FLARE: Faithful Logic-Aided Reasoning and Explorationcited by 7
  33. 2025Language-to-Space Programming for Training-Free 3D Visual Groundingcited by 7
  34. 2025Beyond Single-Task: Robust Multi-Task Length Generalization for LLMscited by 7
  35. 2026User as Code: Executable Memory for Personalized Agentscited by 7
  36. 2024Adversarial Math Word Problem Generationcited by 6
  37. 2025Unveiling the Magic of Code Reasoning through Hypothesis Decomposition and Amendmentcited by 6
  38. 2025RedTeamLLM: an Agentic AI framework for offensive securitycited by 6

50 most cited of 120 All 120 (JSON)

Similar, not cited

Close in wording, no citation either way

  1. 2025Scaling Code-Assisted Chain-of-Thoughts and Instructions for Model Reasoning
  2. 2025Chain of Execution Supervision Promotes General Reasoning in Large Language Models
  3. 2025On Code-Induced Reasoning in LLMs
  4. 2025Premise-Augmented Reasoning Chains Improve Error Identification in Math reasoning with LLMs
  5. 2026Hierarchical Chain-of-Thought: Enhancing LLM Reasoning Performance and Efficiency
  6. 2024Language Models as Compilers: Simulating Pseudocode Execution Improves Algorithmic Reasoning in Language Models
  7. 2025An Empirical Study of Reasoning Steps in Thinking Code LLMs
  8. 2024Break the Chain: Large Language Models Can be Shortcut Reasoners