arXiv:2610.09186cs.LGOct 2026

Manuscript Offprint

arXiv:2610.09186

The Dichotomy Between Pattern Recognition and Step-by-Step Reasoning

Amrut Nadgir, Pratik Chaudhari, Vijay Balasubramanian

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

We argue that pattern recognition and step-by-step reasoning are two ends of a spectrum. A large language model (LLM) learns to reason step-by-step when data is structured such that the next token depends on a small amount of preceding context. Inference in LLMs resembles pattern recognition when the next token depends on a large amount of preceding context. If the next token depends on only the c most recent tokens, reasoning traces are paths on a De Bruijn graph whose nodes are c-length contexts and edges are next-token transitions between contexts. The set of reasoning traces of a task forms a directed acyclic subgraph of the De Bruijn graph. An LLM that has learned all edges of this subgraph can compose them to solve longer, unseen tasks, i.e., it reasons step-by-step. We prove that the number of edges is vanishingly small compared to the number of reasoning traces. Empirically, the number of training samples a transformer needs is a power law in the number of edges, so learning to reason step-by-step is sample efficient. We can induce De Bruijn structure in any task by maintaining a “state” that makes future reasoning independent of the past. The frequency of states in the reasoning trace determines c. We show, by fine-tuning Qwen2.5-1.5B-Instruct to solve equations and answer questions about stories, that frequent states (small c) result in higher accuracy but greater fragility to perturbations at test time. LLMs trained with a large c are only as good as models that perform pattern recognition without reasoning. A moderate density of states balances accuracy and robustness. We show that real-world data has De Bruijn structure: Qwen3-14B and Qwen3-32B retain over 75% of their accuracy on GSM8K, MATH-500 and GPQA-Diamond when attention is restricted to a sliding window less than 15% as long as the full reasoning trace.

1 INTRODUCTION

Large language models (LLMs) are successful at solving problems thought to require precise, step-by-step reasoning (Guo et al., 2025; Glazer et al., 2025; Hubert et al., 2026; Lewkowycz et al., 2022; Jimenez et al., 2023). This is because they can decompose a difficult prediction into a sequence of steps (Wei et al., 2022; Nadgir et al., 2026). This inference strategy seems inconsistent with how LLMs are trained: to predict the next token by imitating statistical patterns in the data. They should use “pattern recognition” to map “similar” inputs to “similar” outputs and thereby generalize to unseen data (Sejnowski, 2018). While a large body of machine learning literature characterizes how generalization is achieved in pattern recognition, there is relatively little literature on why reasoning emerges in LLMs and how it generalizes. It has been argued that reasoning in LLMs is a fundamentally different inference paradigm (Prystawski et al., 2023).

In this paper, we argue that step-by-step reasoning and pattern recognition are not mutually exclusive, they are two ends of a spectrum. When the next token depends on only a small amount of preceding context, LLMs learn to reason step-by-step. Inference in LLMs resembles pattern recognition when the training samples do not have this property.

Our study is motivated by two recent works. Nadgir et al. (2026) showed that chain-of-thought is successful because it enables the LLM to decompose the overall task into a sequence of smaller classification problems where the classes correspond to the tokens being predicted at each step. In effect, an LLM uses the prompt to traverse a prefix-tree of the set of its reasoning traces. The length of the reasoning trace, say nn, determines the depth of this prefix-tree. Cagnetta et al. (2026) showed that LLMs trained on DD tokens of natural language text can reliably capture correlations among only ∼D\sim \sqrt{D} nearby tokens. This puts a limit on the length of reasoning traces. For instance, one would need D∼1010D \sim 10^{10} tokens of in-distribution samples (directly relevant to the task) in order to learn reasoning traces that are of length n∼105n \sim 10^{5}. Pre-training datasets are big, ∼1013\sim 10^{13} tokens, but only a small fraction consists of reasoning traces relevant to a task. So there must be some additional structure that enables LLMs to generalize to newer and longer tasks.

Figure

Figure 1: De Bruijn graph: Edges (both bold and gray) show transitions from one 4-gram to another by appending a token. Bold edges form a directed acyclic subgraph (DAG). Green and orange shaded nodes are start and answer nodes in the DAG respectively. Each path corresponds to a reasoning trace.

Our key technical argument is that, if the set of valid next tokens can be predicted using a limited preceding context, say of length c, then we can compress the prefix-tree into a data structure that can be learned with few samples. The LLM transitions from one c-length context to another by producing a token. A De Bruijn graph B(V,c)B(V, c) with vocabulary V and context c has one node for each unique c-length context and one edge for each valid transition between contexts. Fig. 1 gives an example of such a graph with V = 2 and c = 4. Any finite-length prefix-tree with this structure is a directed acyclic subgraph of the De Bruijn graph, henceforth called a “De Bruijn DAG”. This is because including only forward-pointing edges ensures that all reasoning paths are finite.

  1. Learning to reason step-by-step is sample efficient when training data has De Bruijn structure. We prove that the number of paths required to cover every edge in a De Bruijn DAG is a vanishingly small fraction of the total number of paths. Therefore, if reasoning has De Bruijn structure, then transitions between successive contexts can be learnt with few samples. We also prove that sampling short reasoning traces is sufficient to cover every edge in the DAG. This makes it possible to generalize to longer reasoning problems than those in the training data. We show experimentally that the number of training samples required by a transformer to reproduce a set of reasoning traces scales as a power law of the number of edges in its De Bruijn DAG. Therefore, learning reasoning traces with the De Bruijn structure is indeed sample efficient. In addition, if the data has De Bruijn structure, a transformer trained only on short traces generalizes to much longer ones. The gap between achievable reasoning length at test time and available reasoning length at training time grows with the size of the De Bruijn DAG.

  2. The degree of De Bruijn structure in the training data determines how much an LLM uses pattern recognition or step-by-step reasoning. We can induce De Bruijn structure on any reasoning task by training an LLM to maintain a “state” that makes the future reasoning trace independent of the past. We fine-tune Qwen2.5-1.5B-Instruct to solve equations using reasoning traces that contain the current state at periodic intervals. More frequent state emissions entails that each succeeding token depends on fewer past tokens (i.e., more De Bruijn structure). We show that LLMs that are trained on data which contains the state more frequently have higher accuracy with fewer samples. They also perform reasoning more faithfully, i.e., when they produce the correct answer, the sequence of reasoning steps is also correct. However, such models are comparatively brittle to answer-preserving perturbations in their chain-of-thought at test-time. They tend to propagate errors in their predicted state into future reasoning steps. LLMs trained on reasoning traces without De Bruijn structure are no more accurate than pattern recognition, i.e., using no reasoning at all. This suggests that an LLM should be trained to use reasoning with a moderate amount of De Bruijn structure to balance accuracy on the task against robustness to unforeseen inputs. Our results generalize to a natural language task where the LLM answers questions about a story.

  3. Real-world reasoning traces exhibit De Bruijn structure. We apply an attention mask to Qwen3-14B and Qwen3-32B so that they can only attend to the prompt and c most recent tokens. Even for a value of c that is below one-tenth of the mean length of the reasoning trace, both models retain at least 90% of full-context accuracy on GSM8K (Cobbe et al., 2021), 80% on MATH-500 (Hendrycks et al., 2021) and 65% on GPQA-Diamond (Rein et al., 2023). This, together with the previous two results, suggests that the reasoning traces used to solve these benchmark tasks exhibit some degree of De Bruijn structure, even if the state is not explicitly represented in the traces.

2 LEARNING TO REASON STEP-BY-STEP IS SAMPLE EFFICIENT WHEN TRAINING DATA HAS DE BRUIJN STRUCTURE

Suppose that the set of valid next tokens can be predicted using only the most recent c tokens. In this section, we characterize the sample complexity of learning step-by-step reasoning on such data that has De Bruijn structure.

We can represent any set of reasoning traces as a prefix-tree. Any finite-length prefix-tree with De Bruijn structure is a directed acyclic subgraph of the De Bruijn graph B(V,c)B(V, c), called a De Bruijn DAG, or just DAG in short. We can construct an example DAG as follows. Pick a topological ordering π\pi of the nodes of B(V,c)B(V, c), mark the last N≥1N \geq 1 nodes as “answer” nodes and the first S≥1S \geq 1 nodes as the “start” nodes. The former correspond to sequences where reasoning traces terminate while the latter correspond to initial sequences. Prune all outgoing edges from answer nodes, all incoming edges into start nodes, all edges (u,v)(u, v) with π(v)<π(u)\pi(v) < \pi(u) in the topological ordering, and all edges and nodes that do not lie on start-to-answer reasoning traces. Let us call the DAG created by this procedure DπD_{\pi}. In App. A, we show that DπD_{\pi} can have the maximal number of distinct start-to-answer paths.

We will next characterize the number of samples required to learn all the edges of the DAG. Let Pmin⁡P_{\min} be the minimum number of start-to-answer paths required to cover every edge in the DAG and let PtotP_{\text{tot}} be the total number of paths in the DAG. Let LcoverL_{\text{cover}} be the minimum length of start-to-answer paths required to cover every edge and let LmaxL_{\text{max}} be the length of the longest path in the DAG. We prove the following two theorems in App. A.

Theorem 1. Let S,N<(c+m−1m−1)S, N < \binom{c+m-1}{m-1} for some integer 1<m<V/21 < m < V/2, and let ∣E∣|E| be the number of edges in DπD_\pi. There exists an ordering π\pi such that

Ptot≥∑t=0V−2m(V−2mt)candPmin≤∣E∣≤Vc(V+1)2.(1)P_{\mathrm{t o t}}\geq\sum_{t=0}^{V-2m}\binom{V-2m}{t}^{c}\quad\mathrm{a n d}\quad P_{\mathrm{m i n}}\leq|E|\leq\frac{V^{c}(V+1)}{2}. \tag{1}

The ratio Pmin⁡/Ptot≤∣E∣/Ptot→0P_{\min}/P_{\mathrm{tot}} \leq |E|/P_{\mathrm{tot}} \to 0 in the limit V→∞V \to \infty. Similarly, Pmin⁡/Ptot≤∣E∣/Ptot→0P_{\min}/P_{\mathrm{tot}} \leq |E|/P_{\mathrm{tot}} \to 0 in the limit c→∞c \to \infty provided V is sufficiently large.

Theorem 2. Let S,N<(c+m−1m−1)S, N < \binom{c+m-1}{m-1} for some integer 1<m<V/21 < m < V/2. There exists an ordering π\pi such that

Lmax⁡≥c(V−2m+1)andLcover≤2c+1.(2)L_{\max}\geq c(V-2m+1)\quad and\quad L_{cover}\leq2c+1. \tag{2}

In the limit V→∞V \to \infty, the ratio Lcover/Lmax→0L_{\text{cover}}/L_{\text{max}} \to 0.

Let us discuss some intuition behind these two results. The degree of the nodes in the De Bruijn graph B(V,c)B(V, c) is V. The degree of the De Bruijn DAG is less than V because of the pruned edges.

Figure

Number of Nodes ( VcV^{c})

Number of Nodes ( VcV^{c})

Figure 2: Data with De Bruijn structure can be learned with few, short traces. We created a synthetic dataset of De Bruijn graphs and DAGs for different values of c and V. Left: The minimum number of start-to-answer paths required to cover every edge in the DAG Pmin⁡P_{\min} shrinks relative to the total number of paths PtotP_{\text{tot}} as the number of nodes grows. Right: The minimum length of paths to cover every edge LcoverL_{\text{cover}} shrinks relative to the longest path LmaxL_{\text{max}}. Details: DAGs were created with S = 5 start nodes, N = 10 answer nodes. Dotted curves denote an average over random orderings for nodes in the DAG. Solid curves correspond to using a particular ordering π∗\pi^* in the proof of Thms. 1 and 2. We computed Pmin⁡P_{\min} using a min-flow problem and LcoverL_{\text{cover}} as the maximum over edges for the length of the shortest path from any start node to any answer node containing that edge. For random π\pi, curves show the mean ratio over random orderings and its standard error over ten DAGs (too small to see).

Since Lmax⁡≥c(V−2m+1)L_{\max} \geq c(V - 2m + 1) in Thm. 2, the total number of paths in the DAG is Vc(V−2m+1)V^{c(V - 2m + 1)} minus the number of pruned paths. If we ignore the pruned paths (for some intuition), the total number of paths is exponential in V. Since Lcover≤2c+1L_{\text{cover}} \leq 2c + 1, the minimum number of paths to cover all edges in the DAG is at most V2c+1V^{2c + 1}, polynomial in V. This is why the ratio Pmin⁡/Ptot→0P_{\min}/P_{\text{tot}} \to 0 as V→∞V \to \infty. In addition, for a large enough value of V>2m+1V > 2m + 1, we should expect the ratio Pmin⁡/Ptot→0P_{\min}/P_{\text{tot}} \to 0 as c→∞c \to \infty. The proof of Thms. 1 and 2 makes this intuition rigorous. Thm. 2 shows that it is sufficient for the training data to contain rather short reasoning traces. Altogether, these two results show that if reasoning traces have a De Bruijn structure, then an LLM with a large vocabulary can learn to reason step-by-step with short and few reasoning traces. These theorems are verified numerically in Fig. 2.

Figure

Figure 3: Transformers can learn paths on a De Bruijn DAG with few and short samples. We created a synthetic dataset of De Bruijn graphs and DAGs for different values of cc and VV, and trained transformers on start-to-answer paths from 5 replicate DAGs for each configuration (random π\pi, error bars are standard error). The green curve indicates the sample complexity (left) or the length of reasoning traces in the training data (right) required for achieving 95% path coverage, i.e., when the trained transformer assigns probability greater than 10% of the probability under the uniform distribution 1/Ptot1/P_{\mathrm{tot}} to >95%>95\% of paths. The blue curve corresponds to the situation where the trained transformer assigns a probability smaller than 5% to invalid next-tokens that do not lie on valid reasoning paths in the DAG. Left: The number of training samples required to reproduce paths of the DAG scales as a power law in the number of edges (∼x0.61\sim x^{0.61} for the blue curve and ∼x0.91\sim x^{0.91} for the green curve). Right: The length of reasoning traces in the training data scales linearly in LmaxL_{\mathrm{max}} and is smaller than LmaxL_{\mathrm{max}}. The gap between LtrainL_{\mathrm{train}} and the longest covered path grows with DAG size. Details in App. B.

Remark 3 (What is the ideal vocabulary size?). Since both ratios Pmin⁡/PtotP_{\min}/P_{\text{tot}} and Lcover/LmaxL_{\text{cover}}/L_{\text{max}} vanish as V→∞V \to \infty, it may seem that large vocabulary sizes are ideal for learning step-by-step reasoning. This is counter to the empirical preference for intermediate vocabulary sizes that are calibrated to model size and the amount of training data (Tao et al., 2024). This discrepancy is resolved by considering the complexity of a next-token prediction. The out-degree of any node in DπD_{\pi} increases with vocabulary size V, forcing the LLM to distinguish between a large number of valid next tokens at any step (Nadgir et al., 2026). The optimal vocabulary size is therefore governed by a trade-off between maximizing the sample efficiency of reconstructing the reasoning paths (favoring a large V) and minimizing errors when selecting the correct path (favoring a small V).

In Fig. 3 (left), we show using transformers trained on synthetic data, that the number of samples required to learn the paths in the DAG is a power law in the number of edges in the DAG. Thm. 1 shows that the number of edges ∣E∣|E| in the DAG scales significantly slower than the total number of paths PtotP_{tot}. Together, these two results suggest that learning reasoning paths with De Bruijn structure becomes more sample efficient as the size of the DAG increases. In addition, Fig. 3 (right) shows that models assign non-trivial probability to paths that are significantly longer than anything seen in the training data. This is consistent with the result in Thm. 2.

De Bruijn structure must be explicitly represented in the data to achieve low sample complexity. Some reasoning traces might not contain explicit De Bruijn structure but have some other hidden structure instead. A transformer may be able to learn these traces with few samples if it learns the hidden structure instead of the explicit next-token transitions. We design an experiment in Fig. 4 to isolate this phenomenon. Consider the set of start-to-answer paths on a De Bruijn DAG. Partition each path into consecutive blocks of s tokens and, within each block, permute the elements of the vocabulary by a fixed, block-specific permutation. For example, sequences 1324 and 4344 with vocabulary size V = 4 are remapped to 1321 and 4311 respectively if the block size s = 2 via the remapping 4→14 \rightarrow 1, 2→22 \rightarrow 2 in the second block. All reasoning traces in the dataset are permuted by the same set of block-specific permutations. This remapping is a bijection, so it preserves the underlying structure of the DAG. However, the structure is no longer explicit in the tokens because the permutations depend on position (even if the permutations are consistent across all traces).

Figure

Figure 4: Sample complexity of learning remapped reasoning traces. Connected line segments correspond to remapping with block lengths s=4,8,16s = 4, 8, 16; there are 10 different DAGs drawn on this plot. Dashed lines indicate the fit obtained in Fig. 3 for the original reasoning traces. Smaller values of ss have a larger number of edges and sample complexity. Learning on remapped traces follows a similar power-law trend as seen in Fig. 3.

Task: solve for x: −4∗(2∗x+13)+10=−122-4*(2*x + 13) + 10 = -122. output your answer after ####.

No state emission ( k=∞k = \infty): subtract 10 from both sides. divide both sides by -4. subtract 13 from both sides. divide both sides by 2. #### 10.

Frequent state emission ( k=1k = 1): subtract 10 from both sides. current equation is −4∗(2∗x+13)=−132-4*(2*x + 13) = -132. add 5 to both sides. current equation is −4∗(2∗x+13)+5=−127-4*(2*x + 13) + 5 = -127. subtract 5 from both sides. current equation is −4∗(2∗x+13)=−132-4*(2*x + 13) = -132. divide both sides by -4. current equation is 2∗x+13=332*x + 13 = 33. subtract 13 from both sides. current equation is 2∗x=202*x = 20. divide both sides by 2. current equation is x=10x = 10. #### 10.

Figure 5: An equation-solving task. The red text is a perturbation inserted at inference-time. The step-by-step reasoning model ( k=1k = 1) adapted to this perturbation by undoing the operation in the next step.

Before remapping, a De Bruijn DAG is a highly compressed representation of the prefix-tree of reasoning paths. This is no longer true after remapping; each edge in the original DAG needs to be repeated in the remapped DAG if it appears in different blocks. The new DAG therefore has many more edges than the original one. If the transformer learns the underlying De Bruijn structure from the remapped sequences, it should only require as many samples as the original problem. If, instead, the transformer relies on the structure explicit in the trace, then sample complexity should scale with the edges in the remapped DAG. In Fig. 4, we see the latter situation. This indicates that the number of samples a transformer needs to learn reasoning traces is small if there is explicit De Bruijn structure in the data; implicit structure may not lead to improvements in sample complexity. This is consistent with Thms. 1 and 2 as well as the empirical observations of Vafa et al. (2024).