CoTs as Probabilistic Programs: A Programmatic View of Thinking Step-by-Step in Language Models

Kyle Richardson, Yu Feng, Poorva Garg, Junyan Cheng, Guy Van den Broeck, Dan RothNeurIPS 2026

TL;DR

When a Large Language Model (LLM) "thinks step-by-step," what is that chain of text, mathematically speaking? Right now, we treat Chain-of-Thought (CoT) traces as unstructured strings, making it hard to unify how we prompt, train, and interpret models. This paper introduces Copper, a tiny probabilistic programming language that compiles messy text thoughts into formal executable code—unlocking exact probability queries, mathematical robustness guarantees, and clever single-call reasoning strategies.

What Problem Does This Paper Address?

Since Chain-of-Thought prompting took over AI, step-by-step traces have ended up everywhere: we use them to boost test-time accuracy, train reasoning models, and peek inside the black box for interpretability. Yet, across all these sub-fields, we lack a shared formal language for what a CoT trace actually denotes.

Because we treat traces in ad-hoc, task-specific ways, an insight gained while studying interpretability doesn't cleanly translate into a better training loss or prompting strategy. The authors ask a foundational question: what if we stopped treating CoTs merely as sequences of tokens, and started modeling them as formal probabilistic programs?

Copper translates raw text reasoning traces directly into executable probabilistic programs, allowing us to query exact probabilities and step sensitivities.

Methods

The authors design Copper, a lightweight, Python-like discrete probabilistic programming language tailored for LLM reasoning. Copper separates generating text from interpreting its logic across two levels:

  1. The Program Level (Syntax): Individual reasoning steps become Boolean random variables (Flip, essentially weighted coin flips). Logical dependencies between steps become standard if-then branches, reasoning failures raise ValueError exceptions, and final answers are return values. Crucially, Copper is agnostic to where step weights come from—you can plug in token likelihoods from logits, ask the model for its "verbalized confidence" (e.g., 0.8 confident), or use an external reward model.
  2. The Inference Level (Semantics): Computing the probability of an answer reduces to reachability—calculating the odds of navigating the if-then branches to hit a specific return statement. Copper compiles programs into tractable logical circuits and uses Weighted Model Counting (WMC)—a classic computer science technique that sums the probabilities of all valid logical paths—to compute exact, differentiable probabilities.
Reachability semantics turn reasoning paths into Boolean guards, showing exact conditions required to reach an answer or trigger an error.

To overcome the mathematical pitfalls of multiplying many probabilities together, the authors add a differentiable Factor operator, allowing custom aggregation of step scores (like averaging log-odds). Using this, they invent Bayesian multi-answer CoT: a prompting strategy that asks an LLM, in a single forward pass, to state candidate answers with initial prior confidences, and then generate supporting step-by-step evidence for each, selecting the winner via exact Bayesian inference.

Datasets

The authors evaluate GPT-4o, Llama-3.3-70B-Instruct, and Qwen-2.5-7B-Instruct across five existing commonsense and multi-choice reasoning benchmarks (no new datasets are introduced):

  • Binary QA: BoolQ and StrategyQA.
  • Multiple-Choice (from BIG-Bench Hard): Date Understanding, Geometric Shapes, and Salient Translation Error Detection.

Key Insights and Ideas

  • The "Length Confound" at the Program Level: Even if you normalize each step's probability by its token length, standard likelihood scoring multiplies step probabilities together (P1 and P2 and P3). Because probabilities are $\le 1$, longer, more thorough reasoning chains get mathematically penalized compared to short, shallow ones—even when the longer chain has higher average step quality! Rearranging branches can't fix this; you need non-multiplicative score aggregation (Factor).
  • Unifying AI Sub-fields as Program Queries: Once a CoT is a Copper program, disparate tasks become simple mathematical queries over the same object: prompting is marginal inference, interpretability is taking gradients with respect to step weights, and robustness is finding the smallest weight perturbation that flips the output.
Figure 2: Modeling and querying CoT. At the program level, CoT steps com- pose into different reasoning structures. At the program inference level, existing uses of CoT become queries over these programs, while the same formulation enables new forms of inference, such as robustness testing (bottom).
  • Verbal Confidence Beats Raw Logits for Priors: When models assign initial probabilities to candidate answers, reading their stated verbal confidence dramatically outperforms looking at raw token logits, which tend to suffer from severe label bias (stubbornly concentrating on a single answer like "yes" or "no").
  • Same Text, Different Explanations: By taking gradients over a fixed CoT trace scored by different models, Copper reveals that GPT-4o, Llama, and Qwen rely on completely different steps as load-bearing evidence to reach the exact same conclusion.

Key Results

  • Single-Call Efficiency vs. Accuracy Tradeoff: Bayesian multi-answer CoT beats direct prompting across all models and even outperforms multi-call search-based Tree-of-Thoughts on Qwen-7B (64.62% vs. 39.90%), though forcing models to output strict programmatic formatting incurs a slight accuracy dip (~3–7%) compared to vanilla CoT on larger models.
  • Superior Stability & Error Detection: Using first-order gradient estimates, Bayesian CoT shows larger robustness margins (requiring bigger parameter shifts to flip an answer) than likelihood-based programs in 5 out of 6 model-task pairs (e.g., median margin of 0.3131 vs. 0.1083 for Llama-70B on BoolQ). Furthermore, predictions with the top 10% largest margins are consistently more accurate than the bottom 10%.
  • Cross-Model Trace Reuse: Treating CoTs as reusable programs works both ways. Scoring GPT-4o's traces with Qwen-7B's weights boosts Qwen's micro-averaged accuracy by +5.7 percentage points (56.86% vs. 51.16%). Conversely, Llama-70B can salvage weak traces generated by Qwen, lifting performance from Qwen's 51.16% up to 65.31%.

Limitations and Future Work

  • Simplified Proxies: Copper assumes reasoning steps are conditionally independent coin flips given the program structure—a clean, useful proxy, but clearly a simplification of a transformer's dense, entangled probability distribution.
  • Formatting Overhead: Asking smaller or even frontier models to simultaneously reason, number steps, declare dependencies, and output verbal confidences in one shot taxes instruction-following, costing some raw accuracy compared to unconstrained text generation.
  • Future Directions: The authors envision using Copper's step-level gradients to filter and weight data for CoT distillation and reinforcement learning. They also propose expanding the language beyond basic if-then logic to include loops (iteration), external tool calls, and richer memory states to capture full agentic workflows.

Summary updated

Abstract

Chain-of-thought (CoT) prompting has fundamentally changed how language models are used, evaluated, and developed. CoT now touches many areas of contemporary research beyond prompting, from advanced test-time inference and model tuning to interpretability, yet much of this work treats CoT traces in task-specific ways, without a shared formal account of what they are or how they compose and support inference. We argue that probabilistic programs — ordinary programs extended with stochastic choices and probabilistic conditioning — provide a natural framework for modeling CoT reasoning. To demonstrate this, we derive \lang{}, a small discrete probabilistic programming language for CoT in which reasoning steps are stochastic choices, branches encode dependencies, trace likelihoods score executions, and answers are return values. Even with a minimal reachability-based semantics, \lang{} enables a first-principles analysis of trace likelihood, exposing why likelihood alone can be a misleading model of reasoning. Motivated by this limitation, we add differentiable operators for composing scores and feedback over CoT traces. The resulting framework links several uses of CoT — scoring, evidence aggregation, feedback propagation, model tuning, and step-level sensitivity analysis — within a single probabilistic program. Through case studies, we show how this approach yields novel test-time inference strategies and new analysis techniques, offering a promising direction for programming-language-based approaches to language-model reasoning.
BibTeX
@inproceedings{richardson2026cots,
  author = {Kyle Richardson and Yu Feng and Poorva Garg and Junyan Cheng and Guy Van den Broeck and Dan Roth},
  title = {{CoTs as Probabilistic Programs: A Programmatic View of Thinking Step-by-Step in Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=YEVrT8IA3J},
}
Figure