Skip to main content

Program of Thoughts

Program of thoughts is a reasoning technique in which the model generates code — typically Python — to solve a numerical or logical problem, then executes the code to obtain the answer. It separates reasoning from computation: the language model handles the plan and the interpreter handles the arithmetic.

This reduces the arithmetic errors that pure chain-of-thought tends to accumulate when stringing together multi-step calculations in natural language. The trade-off is an execution dependency: a code-running tool must be in the loop, and the model must produce runnable code rather than pseudocode. Program of thoughts suits quantitative tasks — finance, physics, word problems with many steps — more than open-ended reasoning.

Example

Asked to compute compound interest on $12,400 at 4.75% APR over 8 years with monthly compounding, a program-of-thoughts prompt instructs the model to emit a Python snippet: `p=12400; r=0.0475/12; n=8*12; print(p*(1+r)**n)`. The snippet runs in a sandbox and returns the numeric result, which the model then wraps in a plain-English answer. Pure chain-of-thought on the same problem frequently drops a digit in the exponent step.

Frequently asked questions

What is Program of Thoughts?

Program of thoughts is a reasoning technique in which the model generates code — typically Python — to solve a numerical or logical problem, then executes the code to obtain the answer. It separates reasoning from computation: the language model handles the plan and the interpreter handles the arithmetic.

How does Program of Thoughts work?

This reduces the arithmetic errors that pure chain-of-thought tends to accumulate when stringing together multi-step calculations in natural language. The trade-off is an execution dependency: a code-running tool must be in the loop, and the model must produce runnable code rather than pseudocode.

Can you give an example of Program of Thoughts?

Asked to compute compound interest on $12,400 at 4.75% APR over 8 years with monthly compounding, a program-of-thoughts prompt instructs the model to emit a Python snippet: `p=12400; r=0.0475/12; n=8*12; print(p*(1+r)**n)`. The snippet runs in a sandbox and returns the numeric result, which the model then wraps in a plain-English answer. Pure chain-of-thought on the same problem frequently drops a digit in the exponent step.