Chain-of-Thought › Program-Aided Reasoning

Michael BrenndoerferMarch 3, 20262 min read
Language AI HandbookAll chapters
Part 39 of 67Reasoning
Chapter 294Chain-of-Thought › Program-Aided Reasoning
Reading section 9 of 16 · Program-Aided Reasoning · 2 minSection 9 of 16 · 2 min

Book contents

Section 9 of 16 · 2 min read

Chain-of-Thought › Program-Aided ReasoningOne section · Sections in this chapter9 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

A significant limitation of all purely textual CoT approaches is that they rely on the language model to perform arithmetic and symbolic manipulation reliably. For arithmetic especially, this reliability is limited: even large models make arithmetic errors in multi-step calculations, particularly when numbers are large or intermediate results must be tracked carefully.

Program-aided language models (PAL, Gao et al., 2022) address this limitation by delegating the computational steps to an interpreter. Rather than generating a natural language reasoning chain and extracting a number at the end, the model generates Python code that performs the reasoning, and the code is then executed to produce the final answer.

A PAL response to the muffin problem might look like:

In[3]:
Code
# A bakery makes 48 muffins per batch
muffins_per_batch = 48
# 3 morning batches and 2 afternoon batches
morning_batches = 3
afternoon_batches = 2
total_batches = morning_batches + afternoon_batches
# Total muffins produced
total_muffins = muffins_per_batch * total_batches
# Sell 85
sold = 85
# Remaining
remaining = total_muffins - sold
print(remaining)
Out[3]:
Console
155

The Python interpreter executes this and prints the answer. The language model's job shifts from performing arithmetic to writing code that correctly models the problem structure. This plays to the model's strengths: large models are excellent at code generation and considerably less reliable at mental arithmetic for large numbers.

PAL achieves substantially higher accuracy on arithmetic benchmarks than standard CoT, with improvements of 10-20% on GSM8K depending on the base model. The approach is particularly effective for problems involving large numbers, repeated operations, or tracking multiple variables, exactly the cases where CoT arithmetic errors accumulate.

The practical limitation is that PAL requires a Python interpreter in the inference pipeline and the ability to execute untrusted code safely. For production deployments, sandboxing this execution adds engineering complexity. The approach also assumes that the problem can be naturally expressed in procedural code, which holds for arithmetic and data-manipulation tasks but not for all reasoning domains.