program-aided language models (pal)
**PAL (Program-Aided Language Models)** is a reasoning technique where an LLM generates **executable code** (typically Python) to solve reasoning and mathematical problems instead of trying to compute answers directly through natural language. The code is then executed by an interpreter, and the result is returned as the answer.
**How PAL Works**
- **Step 1**: The LLM receives a reasoning question (e.g., "If a wafer has 300mm diameter and each die is 10mm × 10mm, how many dies fit?")
- **Step 2**: Instead of reasoning verbally, the model generates a **Python program** that computes the answer:
```
import math
wafer_radius = 150 # mm
die_size = 10 # mm
dies = sum(1 for x in range(-150,150,10) for y in range(-150,150,10) if x**2+y**2 <= 150**2)
```
- **Step 3**: The code is executed, and the **numerical result** is used as the final answer.
**Why PAL Outperforms Pure CoT**
- **Arithmetic Accuracy**: LLMs are notoriously bad at multi-step arithmetic. Code execution is **perfectly accurate**.
- **Complex Logic**: Loops, conditionals, and data structures in code handle complex reasoning that would be error-prone in natural language.
- **Verifiability**: The generated code is inspectable — you can verify the reasoning process, not just the answer.
- **Deterministic**: Given the same code, execution always produces the same result, unlike LLM text generation.
**Extensions and Variants**
- **PoT (Program of Thought)**: Similar concept — interleave natural language reasoning with code blocks.
- **Tool-Augmented Models**: Broader category where LLMs delegate to calculators, search engines, or APIs.
- **Code Interpreters**: ChatGPT's Code Interpreter and similar tools implement PAL's philosophy in production.
PAL demonstrates a powerful principle: **use LLMs for what they're good at** (understanding problems and generating code) and **use computers for what they're good at** (executing precise computations).