Caterpillar of Thoughts: Optimal Rewinding for LLMs
- Caterpillar of Thoughts (CaT) is a test-time computation algorithm that formalizes LLM inference as adaptive exploration of a finite Markov chain with rewinding.
- It establishes that a minimal, non-branching backtracking strategy—yielding a 'caterpillar' spine—is sufficient to achieve optimal inference with exponential token gains.
- Practical implementations replace the exact oracle with a softmax value estimator, improving success rates and reducing token consumption on reasoning benchmarks.
Searching arXiv for the main paper and closely related test-time reasoning work. Caterpillar of Thoughts (CaT) is a test-time computation algorithm for LLMs introduced in "Caterpillar of Thoughts: The Optimal Test-Time Algorithm for LLMs" (Azarmehr et al., 24 Mar 2026). It formalizes inference-time reasoning as adaptive exploration of a finite, fully observable Markov chain with rewinding, in which the algorithm may resume generation from any previously observed state. Within that model, CaT is characterized as an optimal rewinding strategy: although backtracking can reduce the number of generations exponentially, the paper proves that only a very limited form of backtracking is theoretically sufficient. The resulting exploration tree is a caterpillar: if the leaves are removed, the remaining structure is a single path (Azarmehr et al., 24 Mar 2026).
1. Position within test-time computation
CaT addresses a general phenomenon in LLM inference: models can often produce substantially better outputs when allowed additional test-time computation, including sampling, chain of thought, backtracking, or revising partial solutions (Azarmehr et al., 24 Mar 2026). The paper treats these procedures not as ad hoc prompting heuristics but as algorithmic policies over partial generations. This reframing is intended to answer two questions that the abstract identifies as under-theorized: how inference-time computation should be structured, and what constitutes an optimal use of a fixed computation budget (Azarmehr et al., 24 Mar 2026).
Within this perspective, existing methods such as Chain-of-Thought (CoT) prompting (Wei et al., 2022) and Tree-of-Thoughts (ToT) (Yao et al., 2023) can be seen as specific algorithms in the same rewinding model (Azarmehr et al., 24 Mar 2026). The paper also places Best-of- in that family (Azarmehr et al., 24 Mar 2026). A common misconception in this area is that stronger test-time reasoning necessarily requires increasingly elaborate branching search. Under the paper’s formal assumptions, that is not the case: no complex branching is ever needed, because the optimal exploration tree is non-branching in a precise sense (Azarmehr et al., 24 Mar 2026).
2. Formal model: Markov chains with rewinding
The formal object is a finite Markov chain , where each state corresponds to a partial solution, such as a token prefix, and is the probability that the LLM extends into in one step, interpreted as one token or one block of tokens (Azarmehr et al., 24 Mar 2026).
A rewinding algorithm is defined adaptively. At step , the algorithm chooses any previously visited state with , rewinds to it, and then the chain takes one transition from to 0 according to 1. The parent relation is written as 2 (Azarmehr et al., 24 Mar 2026). This differs from a standard Markov chain trajectory, in which states are drawn passively without intervention.
The optimization target is a hitting-time objective. Given an initial state 3 and a designated target 4, the goal is to design a rewinding strategy that minimizes the expected total number of transitions until 5 is observed (Azarmehr et al., 24 Mar 2026). The notation is as follows: if 6 is the history and 7 is the set of distinct observed states, then 8 denotes the optimal expected remaining steps to 9 starting from the set 0; in particular, 1 (Azarmehr et al., 24 Mar 2026). The theory minimizes expectation rather than enforcing a strict hard cap, although the summary notes that one may also impose a hard budget 2 on the total number of token generations (Azarmehr et al., 24 Mar 2026).
A central recursion is given in Corollary 2.4. For any 3, define
4
Then
5
The intended interpretation is explicit: from 6, one keeps sampling one step until a strictly “better” state 7 is reached, and then pays its remaining cost (Azarmehr et al., 24 Mar 2026).
3. Structural theorem: the caterpillar characterization
The paper’s main structural claim is stated through the notion of a non-branching algorithm. A rewinding strategy is non-branching if, at each step 8, it only ever rewinds to the most recent state 9 or its parent 0. Equivalently, the exploration tree has exactly one spine and leaves only at distance at most 1 from it (Azarmehr et al., 24 Mar 2026).
Theorem 2.5 states that, given the initial state 2, Algorithm 1 (CaT) is a non-branching rewinding strategy and reaches 3 in expected 4 steps, i.e. optimally (Azarmehr et al., 24 Mar 2026). The theorem is supported by three ingredients given in the proof sketch. First, Lemma 2.2 shows that 5 depends only on the observed set 6, not on the tree shape. Second, Theorem 2.3 proves by induction that for any observed set 7 there is some 8 that achieves 9 under a non-branching strategy; equivalently,
0
Third, the optimal policy is therefore to track the current minimizer 1, sample single steps from 2 until a state 3 with 4 is found, and then update 5 (Azarmehr et al., 24 Mar 2026).
Together, these statements yield the paper’s defining geometric image. If the leaves of the generated state tree are removed, what remains is a path. The root-to-leaf path is the “thought spine,” and any side child is pruned immediately if it does not improve the value (Azarmehr et al., 24 Mar 2026). This suggests that, under the Markov-chain-with-rewinding model, the essential role of test-time computation is not to maintain a broad search frontier, but to identify a sequence of strictly improving states.
4. Algorithmic form and computational properties
Algorithm 1, the exact form of CaT, is succinct. It takes as input an initial state 6, a target 7, and an oracle 8. It initializes 9, repeatedly draws one successor 0, and replaces 1 by 2 only if 3. The loop terminates when 4 (Azarmehr et al., 24 Mar 2026). The exact algorithm therefore requires access to the optimal value function.
Because exact 5 is not available in practice, the paper replaces that oracle with an estimator 6, such as a learned critic or LLM score, inside a softmax-rewinding subroutine (Algorithm 5) (Azarmehr et al., 24 Mar 2026). This introduces a small amount of branching for robustness, but the backbone remains a caterpillar (Azarmehr et al., 24 Mar 2026). The practical guidance specifies that parent states are sampled from the observed set 7 with probability proportional to
8
with temperature 9 reported as working well (Azarmehr et al., 24 Mar 2026).
The paper’s illustrative example considers a linear chain 0 with “death” arcs of probability 1 leading to an absorbing sink (Azarmehr et al., 24 Mar 2026). Without rewinding, one almost surely dies. CaT instead rewinds to 2 until it samples 3 in expected 4 steps, then shifts the spine to 5 and repeats, for a total expected cost of 6 steps to reach 7 (Azarmehr et al., 24 Mar 2026).
A stronger separation appears in Lemma 2.6. In the chain of Figure 1 with 8, any non-rewinding or limited-backtracking strategy needs 9 samples to hit 0 with constant probability, whereas CaT uses only 1 samples in expectation (Azarmehr et al., 24 Mar 2026). The paper therefore attributes exponential gains to rewinding.
The finite-state value function 2 can itself be computed exactly. Algorithm 2 is described as “Dijkstra-like” and computes 3 exactly in 4 or 5 time by repeatedly adding to 6 the next state with minimal provisional distance
7
This is a dynamic-programming or shortest-path-like computation over the Markov chain (Azarmehr et al., 24 Mar 2026).
5. Empirical results on reasoning benchmarks
The empirical comparison is against Tree-of-Thoughts, using GPT-4 as the base LLM and identical prompting for child generation and evaluation (Azarmehr et al., 24 Mar 2026). The reported implementation uses the softmax variant of CaT rather than the exact oracle-based form.
On the Game of 24 benchmark, the task is to build an expression evaluating to 8 from four numbers by sequentially picking two numbers and an operator (Azarmehr et al., 24 Mar 2026). The evaluation uses 100 “hard” games, indices 901–1000, and reports success rate and average total tokens, defined as prompt plus generated tokens (Azarmehr et al., 24 Mar 2026). With a budget of 15 iterations and best of 2 runs, ToT (beam 5, 15 iters) attains a success rate of 74 with average tokens 19.2k, whereas CaT (best of 2, 15 iters) attains a success rate of 81 with average tokens 15.3k (Azarmehr et al., 24 Mar 2026). Figure 2 is described as showing a roughly log-linear correlation between number of steps and number of valid expressions generated, illustrating CaT’s efficiency (Azarmehr et al., 24 Mar 2026).
On 5×5 Crosswords, the task is to fill a 5×5 crossword grid from 10 clues, consisting of 5 across and 5 down clues (Azarmehr et al., 24 Mar 2026). The dataset comprises 20 held-out puzzles from GooBix, and the reported metrics are word accuracy, letter accuracy, puzzle success, and average tokens (Azarmehr et al., 24 Mar 2026). At 20 iterations, ToT achieves word accuracy 39.5, letter accuracy 64.8, games solved 5, and average tokens 73.4k, while CaT achieves word accuracy 50.0, letter accuracy 68.6, games solved 15, and average tokens 66.8k (Azarmehr et al., 24 Mar 2026).
The ablation notes identify several trade-offs. Softmax rewinding introduces occasional branching for robustness, with hyperparameters including temperature 9 and number of children per parent (Azarmehr et al., 24 Mar 2026). Best-of-2 runs mitigate being stuck on a suboptimal spine at small extra cost (Azarmehr et al., 24 Mar 2026). The summary reports that, empirically, CaT both raises success rates and reduces token consumption by approximately 20–30% (Azarmehr et al., 24 Mar 2026).
6. Robustness, implementation guidance, and limitations
The robustness analysis distinguishes between statistical and adversarial noise in the value estimates. Under Laplace-noise on 0, defined in Definition 4.1, the paper gives a stable variant, Algorithms 3–4, that attains a 1-approximation to the optimal hitting time at cost polynomial in 2 (Azarmehr et al., 24 Mar 2026). By contrast, Theorem 4.5 shows that adversarial multiplicative noise can force exponential blowup, so some statistical assumption is necessary (Azarmehr et al., 24 Mar 2026). In other words, the non-branching optimality claim is exact when 3 is known, but approximate inference depends critically on the quality of 4.
The practical guidance follows directly from that dependency. For the oracle, the summary recommends prompting the LLM, or a small verifier, to score the likelihood of success from a partial state 5 and then using the negative log-score as 6 (Azarmehr et al., 24 Mar 2026). For softmax rewinding, it recommends sampling parent states from 7 with probability proportional to 8, with 9 (Azarmehr et al., 24 Mar 2026). For the iteration budget, it suggests fixing 0–1 for medium-difficulty tasks and using Best-of-2 with 3–4 to improve robustness (Azarmehr et al., 24 Mar 2026). For child proposals, it recommends sampling only a few continuations, 5–6, from the selected parent rather than using a large beam (Azarmehr et al., 24 Mar 2026).
The limitations are explicit. The accuracy of 7 matters: overly noisy estimates can still mislead the spine, although softmax rewinding and multiple runs help (Azarmehr et al., 24 Mar 2026). Very deep or highly branching problems may require larger 8 or hybrid search, for example combining CaT with local tree expansions (Azarmehr et al., 24 Mar 2026). This suggests that CaT is best understood not as a universal replacement for all search procedures, but as a theorem-backed statement about the minimal branching structure required for optimality under the paper’s rewinding model (Azarmehr et al., 24 Mar 2026).