Transformers Provably Solve Parity Efficiently with Chain of Thought

## Abstract

Abstract This work provides the first theoretical analysis of training transformers to solve complex problems by recursively generating intermediate states, analogous to fine-tuning for chain-of-thought (CoT) reasoning. We consider training a one-layer transformer to solve the fundamental k 𝑘 k italic_k -parity problem, extending the work on RNNs by Wies et al. ( 2023 ) . We establish three key results: (1) any finite-precision gradient-based algorithm, without intermediate supervision, requires substantial iterations to solve parity with finite samples. (2) In contrast, when intermediate parities are incorporated into the loss function, our model can learn parity in one gradient update when aided by teacher forcing , where ground-truth labels of the reasoning chain are provided at each generation step. (3) Even without teacher forcing, where the model must generate CoT chains end-to-end, parity can be learned efficiently if augmented data is employed to internally verify the soundness of intermediate steps. These results rigorously show that task decomposition and stepwise reasoning naturally arise from optimizing transformers with CoT; moreover, self-consistency checking can improve reasoning ability, aligning with empirical studies of CoT.

## 1 Introduction

Large language models (LLMs) based on the transformer architecture (Vaswani et al., ) have achieved astounding success across a variety of natural language processing and machine learning tasks (see e.g. Wan et al., ; Minaee et al., ; Naveed et al., ; Zhao et al., ). However, they often struggle when tasked with solving complex reasoning problems, especially in a zero-shot setting without any form of intermediate guidance or supervision (Geva et al., ; Rae et al., ; Arkoudas, ; Wang et al., ). These failures are particularly evident in tasks requiring multi-hop reasoning or compounded logical steps (Sakarvadia et al., ).

A promising approach to overcome these limitations is chain-of-thought (CoT) reasoning, where the model is prompted or fine-tuned to solve complex tasks step-by-step by explicitly making intermediate reasoning steps to arrive at the desired answers (Wei et al., ; Kojima et al., ). Since its discovery, CoT reasoning has been shown to significantly enhance the problem-solving capabilities of LLMs while also increasing the interpretability and trustworthiness of the reasoning process, and has spawned numerous prompting techniques (Liu et al., ; Qiao et al., ) and applications for a variety of downstream tasks including common-sense reasoning, mathematical problem-solving, and symbolic or multi-modal reasoning; see e.g. Zhang et al. (); Yu et al. (); Chu et al. () for surveys on CoT. In particular, besides being used as a prompting method, directly training or fine-tuning models to generate CoT chains has also been demonstrated to significantly improve multi-step reasoning performance (Nye et al., ; Wei et al., ; Zelikman et al., ; Lightman et al., ).

Despite these empirical successes, however, the theoretical understanding of the CoT mechanism and task decomposition in transformers is still limited. Existing works focus on characterizing the expressivity of transformers equipped with CoT, providing constructions which can solve certain complexity classes (Feng et al., ; Chiang et al., ; Merrill and Sabharwal, , ; Li et al., ), studying the class of functions that can be learned in-context with CoT (Li et al., ; Bhattamishra et al., ), or analyzing the estimation error of multi-step models (Hu et al., ). Nevertheless, such approaches do not indicate how such capabilities might emerge when training transformers to generate reasoning chains. Li et al. () analyze the training dynamics of a one-layer transformer in an in-context learning setting and show that CoT ability may be acquired; however, they do not consider explicitly training with CoT chains, which is a more difficult problem since the objective depends on the recursive application of the transformer to itself.

In this paper, we seek to formalize the mechanism through which stepwise reasoning emerges in transformers optimized to generate CoT chains. We focus on the specific problem of *bit subset parity* (learning the parity of an unknown subset of $k$ bits from a $d$-bit input), which is known to be impossible to learn end-to-end with any finite-precision gradient-based algorithm in polynomial steps (Shalev-Shwartz et al., ; Shamir, ). In contrast, Wies et al. () have demonstrated that recurrent neural networks (RNNs) can solve parity efficiently when provided with intermediate supervision. We build on this direction to establish positive optimization guarantees for the transformer architecture. Our object of study is a one-layer transformer incorporating a softmax attention layer, feedforward layer and positional encoding, that is recursively applied to its own output to generate a sequence of intermediate parity computations to arrive at the desired output, analogous to CoT generation. Our contributions are summarized as follows.

- •
We extend the impossibility result for parity (given as Theorem 1), which was established only for population gradient descent, to the more realistic finite-sample setting in Theorem 2. We prove that any iterative algorithm with access to an adversarial approximate gradient oracle for the end-to-end empirical loss cannot solve a random target parity within a specific polynomial number of steps.
- •
In contrast, we show that when the loss is summed with respect to all intermediate states, by utilizing *teacher forcing* wherein ground-truth intermediate steps are provided during training,(^1^11Teacher forcing or process supervision is a training procedure for recurrent models in which the model receives the ground truth output at time $t$ as input at time $t+1$ during training (Goodfellow et al., , p.377). Many fine-tuning methods with ground-truth CoT chains implement teacher forcing, being more effective than output supervision with chains generated end-to-end (Deng et al., ; Tian et al., ; Lightman et al., ).) our model can learn any parity in a single gradient update (Theorem 5). This shows the benefits of training directly with CoT chains to acquire task decomposition ability.
- •
We further consider training with CoT chains generated end-to-end without teacher forcing, and show that parity can still be learned in a logarithmic number of steps if augmented data is employed to check the validity of intermediate steps (Theorem 7), thereby mimicking self-consistency checks often used in CoT reasoning (Zelikman et al., ; Wang et al., ; Huang et al., ).

Our results provide theoretical insights into how transformers can naturally and efficiently optimize to perform task decomposition, emphasizing the role of explicit intermediate supervision for complex tasks. Moreover, these findings corroborate recent empirical studies on CoT reasoning demonstrating improved performance through process supervision and internal validation of reasoning chains (Huang et al., ; Tian et al., ; Lightman et al., ).

### 1.1 Related Works

#### Complexity of transformers.

A line of work aims to understand the effectiveness of CoT from the perspective of complexity theory. Feng et al. () show that autoregressive transformers of constant size can solve basic arithmetic tasks by recursively generating CoT reasoning steps, which is not possible when directly generating the solution; this separation arises because looping the generated outputs back to its inputs increases the ‘effective depth’ of the model. Works such as Chiang et al. (); Merrill and Sabharwal () study the expressivity of fixed-precision transformer architectures in terms of classes of formal languages. Merrill and Sabharwal (); Li et al. () show that CoT reasoning enables recognizing wider language classes, and characterizes the increased expressivity depending on the length of the reasoning chain. Sanford et al. () studies the relation between transformers and massively parallel computation protocols, showing that logarithmic depth suffices to solve multi-hop induction tasks that cannot be efficiently solved by other sequence models. Additionally, Li et al. (); Bhattamishra et al. () study the class of functions that can be learned in context by transformers with CoT from the point of view of in-context learning.

#### Optimization and generalization of CoT.

Zhu et al. () study the ‘reversal curse’ via the training dynamics of a one-layer transformer and shows that the model fails to generalize from $A\to B$, $B\to C$ to $A\to C$ as an argument for the necessity of explicit step-by-step reasoning. Hu et al. () study CoT prompting from a statistical estimation perspective by introducing a multi-step latent variable model for CoT and analyzing its approximation, generalization and prompting-based errors. Notably, Li et al. () study the training dynamics of a one-layer attention-only transformer model in an in-context learning setting and show that CoT generalization capability can be obtained. However, this does not address the possibility or benefits of training with CoT chains. Lightman et al. () empirically study training LLMs with either process or outcome supervision, showing that the former significantly outperforms the latter when training to solve challenging reasoning tasks.

#### Parity and task decomposition.

The difficulty of learning parity without task decomposition is established in Shalev-Shwartz et al. (); Shamir (). The work most relevant to our paper is due to Wies et al. (), who study task decomposition for parity with classical Elman RNNs. They show that by incorporating intermediate states into the loss function and utilizing teacher forcing, parity can be solved in polynomial iterations and with polynomial embedding size. Theorem 5 of our paper extends this positive result to autoregressive transformers, rigorously establishing the benefits of CoT-based training.

## 2 Problem Setup

#### Notation.

We write $[n]:=\{1,2,\cdots,n\}$ for any integer $n$. Scalar operations apply componentwise to vectors, e.g. for $\bm{z}\in\operatorname{\mathbb{R}}^{n}$ we write $\phi(\bm{z})=(\phi(z_{1}),\cdots,\phi(z_{n}))^{\top}$, $\bm{z}^{2}=\bm{z}\odot\bm{z}=(z_{1}^{2},\cdots,z_{n}^{2})$ and $\left\lvert\bm{z}\right\rvert=(|z_{1}|,\cdots,|z_{n}|)^{\top}$. The 2-norm is always denoted by $\lVert\cdot\rVert$. The multi-linear inner product or contraction of $\bm{z}_{1},\cdots,\bm{z}_{r}\in\operatorname{\mathbb{R}}^{n}$ for any $r\in\operatorname{\mathbb{N}}$ is denoted as $\left\langle\bm{z}_{1},\cdots,\bm{z}_{r}\right\rangle:=\sum_{i=1}^{n}z_{1,i}
\cdots z_{r,i}$. In particular, $\left\langle\bm{z}_{1}\right\rangle=\bm{z}_{1}^{\top}\bm{1}_{n}$ and $\left\langle\bm{z}_{1},\bm{z}_{2}\right\rangle=\bm{z}_{1}^{\top}\bm{z}_{2}$.

### 2.1 The Parity Problem

Let $d\geq k\geq 2$ be integers and let $P$ denote the set of size $k$ subsets of $\{1,\cdots,d\}$ equipped with the uniform distribution. In this paper, we study the $k$-parity problem for $d$-bit inputs $\bm{x}=(x_{j})_{j=1}^{d}\sim\operatorname{Unif}(\{\pm 1\}^{d})$, where the output $y=\prod_{j\in p}x_{j}$ is determined by the parity of an unknown subset of bits $p\in P$. We will abuse notation and identify the set of indices $p$ with the corresponding parity mapping $\bm{x}\mapsto\prod_{j\in p}x_{j}$. Given $n$ samples $(\bm{x}^{i},y^{i})_{i\in[n]}$, our goal is to learn to predict the parity of any test input.

It is known that parity is fundamentally difficult in the sense that it cannot be solved in polynomial time by any finite-precision gradient-based algorithm, such as neural networks. More precisely, let $\{f_{\theta}\mid\theta\in\Theta\}$ be any differentiable (w.r.t. $\theta$) parametrized model with polynomially bounded gradients, $\lVert\nabla f_{\theta}(\bm{x})\rVert=O(\operatorname{poly}(d))$, and define the population loss $\bar{L}=\mathbb{E}_{\bm{x}}\left[(y-f_{\theta}(\bm{x}))^{2}\right]$. We presume access to an $\varepsilon$-*approximate gradient oracle* $\widetilde{\nabla}$ for $L$, which takes any $\theta\in\Theta$ as query and returns a vector $\widetilde{\nabla}\bar{L}(\theta)$ satisfying $\lVert\widetilde{\nabla}\bar{L}(\theta)-\nabla\bar{L}(\theta)\rVert_{2}\leq\varepsilon$, potentially in an adversarial manner. Then the following holds:

###### Theorem 1 ( Wies et al. ( 2023 ) , Theorem 4) .

Let $\ell_{0-1}$ be the zero-one loss. There exists an $O(e^{-d/3})$-approximate oracle $\widetilde{\nabla}$ such that(^2^22The original paper states that $\mathcal{A}$ can be any iterative gradient-based algorithm which receives an $\Omega(e^{-d/3})$-approximation of the gradient at each step. However, the result is only valid for certain adversarial perturbation schemes.) the output $\mathcal{A}(\theta)$ of any iterative algorithm which sequentially makes at most $O(\operatorname{poly}(d))$ queries to $\widetilde{\nabla}\bar{L}$ must satisfy

$$ $\displaystyle\mathbb{E}_{\bm{x}}\left[\ell_{0-1}(p(\bm{x}),f_{\mathcal{A}( \theta)}(\bm{x}))\right]\geq\textstyle\frac{1}{2}-O(e^{-d})$ $$

with probability at least $1-O(e^{-d/3})$, when the target parity $p$ is uniformly sampled from $P$.

The intuition is that the set $P$ of parity functions is exponentially large in the sense that all elements of $P$ are pairwise orthogonal with respect to the data distribution. This implies that the variance of each gradient call $\nabla\bar{L}(\theta)$ with respect to the target parity $p$ is exponentially small (Shalev-Shwartz et al., ) and is drowned out by the noise from the adversarial oracle, so that no information can be gained on the target without exponentially many queries. See Section 3.1 for more details.

Figure: Figure 1: A hierarchical decomposition of an $8$-parity problem for $d=16$. Here $x_{17}=x_{1}x_{4}$ so that $\mathsf{c}_{1}[17]=1$, $\mathsf{c}_{2}[17]=4$, $\mathsf{p}[17]=21$ and $\mathsf{h}[17]=1$.

###### Theorem 1 ( Wies et al. ( 2023 ) , Theorem 4) .

#### Task decomposition.

As in Wies et al. (), we assume $k=2^{v}$ for an integer $v$ for simplicity and decompose the problem into a hierarchy of $2$-parity computations which can be efficiently learned in a sequential manner by our model. This is expressed as a complete binary tree $\mathcal{T}$ of height $v$ and $2k-1$ nodes. The lowest level contains $k$ nodes representing the bits $x_{j_{m}}$ for $m\in[k]$. The remaining nodes are labeled $x_{d+1},\cdots,x_{d+k-1}$ starting from the next lowest level and moving upwards, left to right. The largest index in level $\ell$ for $0\leq\ell\leq v$ is denoted as $d_{\ell}=d+\sum_{j=1}^{\ell}2^{v-j}$, $d_{0}=d$. Also, for each $m>d$, the indices of the two child nodes of $x_{m}$ are denoted as $\mathsf{c}_{1}[m],\mathsf{c}_{2}[m]$ where $1\leq\mathsf{c}_{1}[m]<\mathsf{c}_{2}[m]<m$. In addition, the parent node index of $x_{m}$ is denoted as $\mathsf{p}[m]$ and the level or height of $x_{m}$ is denoted as $\mathsf{h}[m]$, so that $d_{\mathsf{h}[m]-1}<m\leq d_{\mathsf{h}[m]}$.

### 2.2 Transformer Model

Figure: (a) Recursive generation of intermediate states.

We study a one-layer transformer architecture employing absolute positional encoding and a single-head softmax attention layer followed by a shallow feedforward layer; skip connections are omitted for simplicity. See Figure 2 for a visualization of our setup.

Data encoding: Each input token $\bm{x}_{j}=(x_{j}^{i})_{i=1}^{n}$ for $j\in[d]$ is the $n$-dimensional vector consisting of the $j$th bit of each sample $\bm{x}^{i}$. We also add dummy tokens $\bm{x}_{d+1},\cdots,\bm{x}_{d+k-1}$ initially set to $\bm{0}_{n}$, which will learn to sequentially generate the actual intermediate nodes. Each $\bm{x}_{j}$ is concatenated with the one-hot positional encoding $\bm{e}_{j}\in\operatorname{\mathbb{R}}^{d+k-1}$ for $j\in[d+k-1]$ to form the internal input $\bm{p}_{j}=(\bm{x}_{j}^{\top}\;\bm{e}_{j}^{\top})^{\top}\in\operatorname{
\mathbb{R}}^{n+d+k-1}$ to the attention layer.

Softmax attention layer: The attention layer is defined as in (1) in terms of key, query and value matrices $\mathbf{K},\mathbf{Q},\mathbf{V}$. We fix the first $n$ columns of $\mathbf{K},\mathbf{Q}$ to zero so that the attention scores are determined by only the positional encodings. This ensures that the transformer focuses on learning which positions contribute to the parity at each step. $\mathbf{K},\mathbf{Q}$ are then reparametrized by a single matrix $\mathbf{W}\in\operatorname{\mathbb{R}}^{(d+k-1)^{2}}$; conversely, the value matrix is set to only preserve the $\bm{x}$ component, as follows.

$$ $\mathbf{K}^{\top}\mathbf{Q}=\begin{pmatrix}\bm{0}_{n\times n}&\bm{0}_{n\times( d+k-1)}\\ \bm{0}_{(d+k-1)\times n}&\mathbf{W}\end{pmatrix},\quad\mathbf{V}=\begin{ pmatrix}\mathbf{I}_{n\times n}&\bm{0}_{n\times(d+k-1)}\end{pmatrix}.$ $$

This type of reparametrization is common in the literature (Zhang et al., ; Huang et al., ; Mahankali et al., ; Kim and Suzuki, ).

Feedforward layer: The feedforward layer realizes a fixed link function $\phi:[-1,1]\to[-1,1]$, applied elementwise and only to the $\bm{x}_{j}$ component; the positional encodings are not affected. To exploit the decomposition of our task into $2$-parities, we choose $\phi$ such that $\phi(0)=-1$, $\phi(\pm 1)=1$ so that sums are converted into parities, i.e. $\phi(\frac{a+b}{2})=ab$ for $a,b\in\{\pm 1\}$. Moreover, we require that $\phi^{\prime}(0)=\phi^{\prime}(\pm 1)=0$ and assume $\phi$ is symmetric and sufficiently regular, so that we may expand $\phi(t)=-1+ct^{2}+O(|t|^{4})$ and $\phi^{\prime}(t)=2ct+O(|t|^{3})$.

The transformer computes $\textstyle\operatorname{TF}(\bm{x}_{1},\cdots,\bm{x}_{d+k-1};\mathbf{W})=(\hat
{\bm{x}}_{1},\cdots,\hat{\bm{x}}_{d+k-1})$ where the original data $\hat{\bm{x}}_{j}=\bm{x}_{j},j\in[d]$ remain unchanged and tokens $\hat{\bm{x}}_{d+1},\cdots,\hat{\bm{x}}_{d+k-1}$ are computed as

$$ $\displaystyle\hat{\bm{x}}_{m}=\phi(\hat{\bm{z}}_{m}),\quad\hat{\bm{z}}_{m}= \sum_{j=1}^{m-1}\mathbf{V}\hat{\bm{p}}_{j}\cdot\mathsf{softmax}(\hat{\bm{p}}_{ j}^{\top}\mathbf{K}^{\top}\mathbf{Q}\hat{\bm{p}}_{m})=\sum_{j=1}^{m-1}\sigma_{ j}(\bm{w}_{m})\bm{x}_{j},$ (1) $$

where the softmax scores $\sigma_{j}(\bm{w}_{m})=e^{w_{j,m}}/\sum_{\alpha=1}^{m-1}e^{w_{\alpha,m}}$. Here, we have implicitly added the causal mask $w_{j,m}\leftarrow-\infty$ to the attention layer for $j\geq m$ or $m\leq d$. Note that each $\hat{\bm{z}}_{m},\hat{\bm{x}}_{m}$ will be contained in the cube $[-1,1]^{d}$ as long as the input tokens are also contained in $[-1,1]^{d}$.

#### Chain of thought.

Consider repeatedly applying $\operatorname{TF}(\cdot)$ to its own output to generate a ‘reasoning chain.’ Since the input tokens are fixed, the token $\hat{\bm{x}}_{d+1}$ will be updated once and then always yield the same value afterwards. Next, since $\hat{\bm{x}}_{d+2}$ depends on the input tokens and $\hat{\bm{x}}_{d+1}$, it will be updated twice before becoming fixed. Repeating this, the entire chain stops updating after at most $k-1$ steps, yielding the output

$$ $\displaystyle\operatorname{TF}^{(v)}(\bm{x}_{1},\cdots,\bm{x}_{d},\bm{0}_{n}, \cdots,\bm{0}_{n};\mathbf{W})=(\hat{\bm{x}}_{1},\cdots,\hat{\bm{x}}_{d+k-1})$ $$

where the intermediate predictions are recursively computed as $\hat{\bm{x}}_{m}=\phi(\sum_{j=1}^{m-1}\sigma_{j}(\bm{w}_{m})\hat{\bm{x}}_{j})$. Finally, the top node is returned as the model prediction $\hat{\bm{y}}=\hat{\bm{x}}_{d+k-1}$.

This process can be seen as a simplified version of CoT reasoning, albeit not in an in-context learning setting: instead of one-shot predicting $y^{i}$ from $\bm{x}^{i}$, the model starts by solving simpler subtasks and uses the information to attack compound problems, learning to generate intermediate reasoning steps $\bm{x}_{d+1}\to\cdots\to\bm{x}_{d+k-1}$ to finally arrive at the desired solution. Importantly, this process is not possible if the model is only trained on the one-shot data $(\bm{x}^{i},y^{i})_{i\in[n]}$ as we show in Section 3.1. Instead, we incorporate the prediction error for all intermediate states directly into our loss function (Lightman et al., ). We also consider shortening the reasoning chain by using a different causal mask in Section 3.3, which will result in improved control of error and faster convergence.

## 3 Main Results

### 3.1 Hardness of Parity without CoT

Before analyzing our transformer model, we first prove a negative learning result in the absence of intermediate supervision that extends Theorem 1, which was stated with respect to the population objective $\bar{L}$ and zero-one test loss $\ell_{0-1}$, to finite samples and mean squared loss.

Let $f_{\theta}:\{\pm 1\}^{d}\to\operatorname{\mathbb{R}}$ be any differentiable parametrized model and suppose we select the target parity $p$ uniformly at random from $P$. In the finite-sample setting, $n$ i.i.d. samples $(\bm{x}^{i},y^{i})_{i\in[n]}$ are generated as $\bm{x}^{i}\sim\operatorname{Unif}(\{\pm 1\}^{d})$, $y^{i}=p(\bm{x}^{i})$ and we are given access to (approximate) gradients from the empirical loss

$$ $\displaystyle L_{n}(\theta)=\frac{1}{2n}\sum_{i=1}^{n}(y^{i}-f_{\theta}(\bm{x} ^{i}))^{2}=\frac{1}{2}\lVert p-f_{\theta}\rVert_{n}^{2},$ $$

where $\lVert\cdot\rVert_{n}$ is the empirical norm. It is important that the model $f_{\theta}$ is applied to each $\bm{x}^{i}$ separately and does not cross-reference between different samples, as there exist more efficient parity-learning algorithms if the data is allowed to be manipulated freely. For example, Gaussian elimination can solve parity with $O(d)$ samples and $O(d^{3})$ iterations (Raz, ). Moreover, this implies that neural networks trained with stochastic gradient descent can also solve parity in polynomial time (Abbe and Sandon, ). Instead, in our setting the model is forced to learn from the averaged gradient signal and can only implicitly utilize the correlation between samples.

We show the following result for learning parities with finite-samples in Appendix A:

###### Theorem 2 (hardness of finite-sample parity) .

Suppose $k=\Theta(d)$.

- (1)
If $n=e^{\Omega(d)}$ and $f_{\theta}$ has polynomially bounded gradients, there exists an $e^{-\Omega(d)}$-approximate gradient oracle $\widetilde{\nabla}$ such that with probability $1-e^{-\Omega(d)}$ over random sampling, the output $\mathcal{A}(\theta)$ of any iterative (possibly randomized) algorithm which makes at most $O(\operatorname{poly}(d))$ queries to $\widetilde{\nabla}L_{n}$ has $L_{2}$-loss lower bounded as
$\mathbb{E}_{p\in P,\bm{x}}\left[(p(\bm{x})-f_{\mathcal{A}(\theta)}(\bm{x}))^{2
}\right]\geq 1-e^{-\Omega(d)}.$
- (2)
If $n=\Omega(d^{\nu})$ and $\lVert\nabla f_{\theta}\rVert=O(d^{\nu_{1}})$, there exists an $O(d^{-\nu_{2}})$-approximate gradient oracle $\widetilde{\nabla}$ such that with probability $1-e^{-\Omega(d)}$ over random sampling, the output $\mathcal{A}(\theta)$ of any iterative (possibly randomized) algorithm which makes at most $O(d^{\nu_{3}})$ queries to $\widetilde{\nabla}L_{n}$ has $L_{2}$-loss lower bounded, where $\nu=4\nu_{1}+4\nu_{2}+2\nu_{3}+2\nu_{4}+1$, as
$\mathbb{E}_{p\in P,\bm{x}}\left[(p(\bm{x})-f_{\mathcal{A}(\theta)}(\bm{x}))^{2
}\right]\geq 1-O(d^{-\nu_{4}}).$

We remark that the bounds are asymptotically optimal since $f_{\theta}\equiv 0$ is a valid estimator. Moreover, the expectation over $p\in P$ can be replaced by the corresponding ‘with high probability’ statement.

A counter-intuitive aspect of the above result is that parity becomes potentially more difficult when the number of samples increases. Indeed, with exponential samples $n=e^{\Omega(d)}$ (1) we basically recover the statement of Theorem 1, while the guarantees for $n=\operatorname{poly}(d)$ (2) are also polynomial in $d$. This is because the difficulty of parity (Theorem 1) fundamentally depends on the following result:

###### Proposition 3 ( Shalev-Shwartz et al. ( 2017 ) , Theorem 1) .

Suppose $x$ be a random variable in $\operatorname{\mathbb{R}}^{d}$. Let $\mathcal{H}$ be a class of bounded real-valued functions on $\operatorname{\mathbb{R}}^{d}$ such that $\mathbb{E}_{\bm{x}}[h(\bm{x})h^{\prime}(\bm{x})]=0$ for any two distinct $h,h^{\prime}\in H$ and $f_{\theta}$ a differentiable parametric model with gradients bounded by $\mathbb{E}_{\bm{x}}[\lVert\nabla f_{\theta}\rVert^{2}]\leq F(\theta)^{2}$. Then for the loss $F_{h}(\theta):=\mathbb{E}_{\bm{x}}[(h(\bm{x})-f_{\theta}(\bm{x}))^{2}]$ where $h$ is chosen uniformly at random from $\mathcal{H}$, the gradient variance is bounded as

$$ $\operatorname{Var}(\theta;\mathcal{H}):=\mathbb{E}_{h\in\mathcal{H}}\left[ \lVert\nabla F_{h}(\theta)-\mathbb{E}_{h^{\prime}\in H}[\nabla F_{h^{\prime}}( \theta)]\rVert^{2}\right]\leq\frac{F(\theta)^{2}}{|\mathcal{H}|}.$ $$

Since all $\binom{d}{k}=e^{\Theta(d)}$ parities in $P$ are pairwise orthogonal with respect to the uniform distribution $\operatorname{Unif}(\{\pm 1\}^{d})$, it follows that the variance of $\nabla\bar{L}$ is exponentially small and the target signal can be drowned out by a correspondingly small noise from the oracle. However, this is not true for the empirical distribution which cannot distinguish all elements in $P$ with only $\operatorname{poly}(d)$ samples; the empirical correlation of two random parities will generally be $\Theta(n^{-1/2})$. Therefore a more careful decorrelation argument is needed, resulting in the weaker guarantees of Theorem 2(2). Another technical difference is that Theorem 1 only considers the strong zero-one loss (more formally, their results can be seen to hold for any parity estimator $\hat{p}_{\mathcal{A}(\theta)}\in P$ depending on the algorithm output), while we prove the $L_{2}$ lower bound for any real-valued estimator $f_{\mathcal{A}(\theta)}$.

###### Theorem 2 (hardness of finite-sample parity) .

###### Proposition 3 ( Shalev-Shwartz et al. ( 2017 ) , Theorem 1) .

### 3.2 CoT with Teacher Forcing

When training with teacher forcing, at each position $d+1\leq m\leq d+k-1$, the ground-truth labels of the preceding intermediate states $\bm{x}_{1},\cdots,\bm{x}_{m-1}$ are fed into the transformer input to obtain the predictor $\hat{\bm{x}}_{m}$ at the $m$th position; $\hat{\bm{x}}_{m}=\operatorname{TF}(\bm{x}_{1},\cdots,\bm{x}_{m-1},\bm{0}_{n},
\cdots,\bm{0}_{n};\mathbf{W})_{m}$. The loss function then computes the squared error over all states,

$$ $L(\mathbf{W})=\frac{1}{2n}\sum_{m=d+1}^{d+k-1}\lVert\hat{\bm{x}}_{m}-\bm{x}_{m }\rVert^{2}.$ (2) $$

Since each sequence of values $\hat{x}_{d+1,i},\cdots,\hat{x}_{d+k-1,i}$ are generated depending only on the corresponding sample $\bm{x}^{i}$ and the parameter matrix $\mathbf{W}$, this can be rewritten in terms of the augmented labels $\bar{y}^{i}=(x_{d+1}^{i},\cdots,x_{d+k-1}^{i})^{\top}$ as

$$ $L(\mathbf{W})=\frac{1}{2n}\sum_{i=1}^{n}\lVert\bar{y}^{i}-f^{\circ}(\bm{x}^{i} ;\mathbf{W})\rVert^{2},\quad f_{m}^{\circ}(\bm{x}^{i};\mathbf{W})=\hat{x}_{m,i },\quad d+1\leq m\leq d+k-1$ $$

for a fixed mapping $f^{\circ}:\{\pm 1\}^{d}\times\operatorname{\mathbb{R}}^{(d+k-1)^{2}}\to
\operatorname{\mathbb{R}}^{k-1}$, mirroring the setting of Theorem 2. Hence our model does not cross-reference between samples; moreover, the gradient of $f^{\circ}$ is bounded as

###### Lemma 4 .

For all $\bm{x},\mathbf{W}$ it holds uniformly that $\lVert\nabla_{\mathbf{W}}f^{\circ}(\bm{x};\mathbf{W})\rVert\leq O(\sqrt{d})$.

At inference time, test inputs $\bm{x}_{1},\cdots,\bm{x}_{d}$ are randomly generated and the prediction for $\bm{y}_{\operatorname{test}}=p(\bm{x}_{1},\cdots,\bm{x}_{d})$ is computed by iterating $\operatorname{TF}$ to generate all $k$ reasoning steps without reference to ground-truth labels; $\hat{\bm{y}}_{\operatorname{test}}=\operatorname{TF}^{(k-1)}(\bm{x}_{1},\cdots
,\bm{x}_{d},\bm{0}_{n},\cdots,\bm{0}_{n};\mathbf{W})_{d+k-1}$. Our positive learning result in this setting is as follows.

###### Theorem 5 (CoT with teacher forcing) .

Suppose $n=\Omega(d^{2+\epsilon})$ for $\epsilon>0$, $d$ is sufficiently large and let $\widetilde{\nabla}$ be any $O(d^{-2-\epsilon/8})$-approximate gradient oracle.(^3^33In fact, we only require that each component of the gradient has error at most $O(d^{-2-\epsilon/8})$ for Theorems 5, 7, which follows since the $L_{\infty}$ error is bounded above by $L_{2}$.) Set initialization $\mathbf{W}^{(0)}=\bm{0}$ and learning rate $\eta=\Theta(d^{2+\epsilon/16})$. Then for any target parity $p\in P$, it holds with probability $1-\exp(-d^{\epsilon/2})$ over random sampling that the one-step update $\mathbf{W}^{(1)}=\mathbf{W}^{(0)}-\eta\widetilde{\nabla}L(\mathbf{W}^{(0)})$ w.r.t. the objective (2) with teacher forcing achieves loss $\lVert\hat{\bm{y}}_{\operatorname{test}}-\bm{y}_{\operatorname{test}}\rVert_{
\infty}\leq O(d^{-\epsilon/8})$.

On the other hand, Theorem 2(2) shows that when $n=\Omega(d^{11+\epsilon})$, any iterative algorithm querying an $O(d^{-2-\epsilon/8})$-approximate oracle, with gradients bounded as in Lemma 4, requires more than $\widetilde{\Omega}(d^{\epsilon/4})$ queries to attain a nontrivial $(<\frac{1}{2})$ loss. This establishes a strict separation between learning parities without intermediate supervision and our CoT transformer. The gap increases with more samples as $\epsilon$ increases; moreover, when $n=e^{\Omega(d)}$, we have a much stronger separation by Theorem 2(1), where an exponential number of queries is required to learn $p$.

Sketch of proof. The result is shown by explicitly calculating the gradient with respect to each weight $w_{j,m}$ and extracting the gradient signal. As the softmax scores are uniform at initialization, the gradient can be expanded to obtain multilinear contraction or ‘interaction’ terms between the tokens $\bm{x}_{1},\cdots,\bm{x}_{m-1}$, one such example being

$$ $\displaystyle\frac{1}{n}\left\langle\bm{x}_{m},\hat{\bm{z}}_{m},\hat{\bm{z}}_{ m}\right\rangle=\frac{1}{n(m-1)^{2}}\sum_{\alpha,\beta}\left\langle\bm{x}_{m}, \bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle.$ $$

In the above equation, if $\alpha,\beta$ are the two child nodes of $m$, the parity $x_{\alpha}x_{\beta}x_{m}\equiv 1$ will be trivial and $\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle=n$. On the other hand, for nontrivial parities the interaction strength will generally be $O(\sqrt{n\log d})$ due to sample concentration. For sufficiently large $n$, the trivial parities dominate, allowing us to extract the leading term. Performing these computations up to fourth order interaction terms, we can show that the dominating signal of the gradient is $\Theta(d^{-2})$ when $j=\mathsf{c}_{1}[m],\mathsf{c}_{2}[m]$ and $O(d^{-2-\epsilon/8})$ otherwise. Hence the transformer learns to increase only the weights at the relevant positions for each subtask, and is able to compute the desired $2$-parity $\hat{\bm{x}}_{m}\approx\phi(\frac{1}{2}(\hat{\bm{x}}_{\mathsf{c}_{1}[m]}+\hat{
\bm{x}}_{\mathsf{c}_{2}[m]}))\approx\hat{\bm{x}}_{\mathsf{c}_{1}[m]}\hat{\bm{x
}}_{\mathsf{c}_{2}[m]}$ during its forward pass. ∎

###### Lemma 4 .

###### Theorem 5 (CoT with teacher forcing) .

### 3.3 CoT without Teacher Forcing

In this section, we extend Theorem 5 to training a transformer without teacher forcing. The main difficulty in this setting is that wrong answers propagate to later generation steps, exponentially amplifying errors and drowning out the main gradient signals. Error amplification is also a central practical issue of CoT (Zhang and Parkes, ; Wang et al., ). To solve this issue, we make some modifications to our transformer model.

First, we minimize the number of required reasoning steps by imposing a slightly stronger form of autoregressivity where each intermediate state $\bm{x}_{m}^{+}$ depends on all tokens $\bm{x}_{j}^{+}$, $j=1,\cdots,d_{\mathsf{h}[m]-1}$ up to the previous level, rather than the immediately preceding token. This can be expressed as the causal mask $w_{j,m}\leftarrow-\infty$ for $j>d_{\mathsf{h}[m]-1}$ or $m\leq d$; see Figure 3. This ensures that the model gradients are polynomially bounded as in Theorem 2 and that errors can propagate a logarithmic rather than a linear number of steps, and can be easily implemented as the indices $d_{\ell}$ are known.

Figure: Figure 3: Causal mask for $\mathbf{W}^{\top}$ with teacher forcing (left); without teacher forcing (right). The gray entries are set to $-\infty$.

Second, we implement a simple data augmentation technique where randomly generated $d$-bit strings $\bm{u}^{i}\sim\operatorname{Unif}\{\pm 1\}^{d}$ for $i\in[n^{\prime}]$ are appended to the original dataset $(\bm{x}^{i})_{i\in[n]}$. The resulting extended token embeddings are denoted as $\bm{x}_{j}^{+}=(\bm{x}_{j}^{\top}\,\bm{u}_{j}^{\top})^{\top}\in\operatorname{
\mathbb{R}}^{n+n^{\prime}}$ so that $\bm{p}_{j}=((\bm{x}_{j}^{+})^{\top}\,\bm{e}_{j}^{\top})^{\top}$, and the key, query and value matrices are appropriately enlarged. The ground truth labels as well as the intermediate states for the augmented data are unknown, so they are not included in the loss function; nevertheless, unlabeled data can still suffice for self-consistency (Huang et al., ). Instead, their purpose is to filter for ‘faulty reasoning’ in the following sense. If the input weights are not sufficiently trained, the output of a node $x_{j}$ will consist of all nearly $-1$s and thus be uninformative for computing any parities. If the augmented tokens newly generated in the previous iteration of $\operatorname{TF}(\cdot)$ (i.e. up to $\bm{u}_{d_{\ell-1}}$) are uninformative, we zero out the generated output on the basis that all subsequent reasoning will be wrong. This is achieved by adding the following filter after the feedforward layer $\phi$:

$$ $\iota_{\ell}(\bm{z}^{+})=\begin{cases}\bm{0}&\lVert\bm{u}_{j}+\bm{1}_{n^{ \prime}}\rVert_{\infty}<\varepsilon_{0}\;\;\text{for any}\;\;d_{\ell-2}<j\leq d _{\ell-1},\\ \bm{z}^{+}&\text{otherwise.}\end{cases}$ $$

Without teacher forcing, during training the entire reasoning chain is generated by iteratively applying $\operatorname{TF}$ to its own output until convergence, which takes $v=\log_{2}k$ rather than $k-1$ steps due to the imposed block autoregressivity. Hence $\operatorname{TF}^{(v)}(\bm{x}_{1}^{+},\cdots,\bm{x}_{d}^{+},\bm{0}_{n+n^{
\prime}},\cdots;\mathbf{W})=(\hat{\bm{x}}_{1}^{+},\cdots,\hat{\bm{x}}_{d+k-1}^
{+})$ where the tokens $\hat{\bm{x}}_{d+1}^{+},\cdots,\hat{\bm{x}}_{d+k-1}^{+}$ are recursively generated per level as

$$ $\displaystyle\textstyle\hat{\bm{x}}_{m}^{+}=\iota_{\mathsf{h}[m]}\circ\phi( \hat{\bm{z}}_{m}^{+}),\quad\hat{\bm{z}}_{m}^{+}=\sum_{j=1}^{d_{\mathsf{h}[m]-1 }}\sigma_{j}(\bm{w}_{m})\hat{\bm{x}}_{j}^{+}.$ (3) $$

The loss is computed against the ground-truth labels as in (2). Similarly to the teacher forcing setup, each sequence of generated states depends only on each sample $\bm{x}^{i}$ and the augmented data $\mathbf{U}=(\bm{u}^{i})_{i\in[n^{\prime}]}$, so we may express

$$ $L(\mathbf{W},\mathbf{U})=\frac{1}{2n}\sum_{i=1}^{n}\lVert\bar{y}^{i}-f^{\times }(\bm{x}^{i};\mathbf{W},\mathbf{U})\rVert^{2},\quad f_{m}^{\times}(\bm{x}^{i}; \mathbf{W},\mathbf{U})=\hat{x}_{m,i}$ (4) $$

for a fixed mapping $f^{\times}$, so that the samples are again not cross-referenced. By considering the propagation of gradients up the reasoning chain, the gradient of $f^{\times}$ can be shown to be bounded as:

###### Lemma 6 .

For all $\bm{x},\mathbf{W},\mathbf{U}$ we have $\lVert\nabla_{\mathbf{W}}f^{\times}(\bm{x};\mathbf{W},\mathbf{U})\rVert\leq O(
d^{g})$ where $g=\log_{2}\lVert\phi^{\prime}\rVert_{\infty}+1/2$.

The exact exponent depends on the shape of $\phi$. Since $\phi(0)=-1$ and $\phi(1)=1$, it must hold that $\lVert\phi^{\prime}\rVert_{\infty}>2$. Conversely, any such $\lVert\phi^{\prime}\rVert_{\infty}$ may be achieved by taking $\phi$ to be locally quadratic around $0,\pm 1$ and smoothly joining the curve segments with straight lines of slope $\pm(2+\epsilon)$. Furthermore, such a link function can be realized by a simple shallow feedforward layer using e.g. $O(1)$ ReQU neurons. Hence the exponent $g$ can be taken to be arbitrarily close to $1.5$.

Finally, we implement a simple weight quantization method by rounding each component of $\mathbf{W}$ to the nearest integer after every update; $\mathbf{W}^{(t+1)}=\mathsf{r}[\mathbf{W}^{(t)}-\eta\widetilde{\nabla}_{\mathbf
{W}}L(\mathbf{W}^{(t)},\mathbf{U})]$, where $\mathsf{r}:\operatorname{\mathbb{R}}\to\operatorname{\mathbb{Z}}$ is the nearest-integer operator. Equivalently, the gradient updates themselves are quantized. Integer-based quantization methods are widely used in practice to accelerate training and reduce memory usage (Wu et al., ; Jacob et al., ), and have been successfully implemented in LLMs to facilitate much more efficient finetuning (Dettmers et al., , ). In our theoretical setting, quantization will also allow us to simplify computations involving propagation of information.

In this setting, we obtain the following learning result.

###### Theorem 7 (CoT without teacher forcing) .

Suppose $n=\Omega(d^{2+\epsilon})$ for $\epsilon>0$, $n^{\prime}=\operatorname{poly}(d)$, $d$ is sufficiently large and let $\widetilde{\nabla}$ be any $O(d^{-2-\epsilon/8})$-approximate gradient oracle. Set $\mathbf{W}^{(0)}=\bm{0}$ and $\eta=\Theta(d^{2+\epsilon/16})$. Then for any target parity $p\in P$, it holds with probability $1-\exp(-d^{(\epsilon\wedge 1)/2})$ over random sampling of (original and augmented) data that the sequence of updates $\mathbf{W}^{(t+1)}=\mathsf{r}[\mathbf{W}^{(t)}-\eta\widetilde{\nabla}L(\mathbf
{W}^{(t)})]$ w.r.t. the objective (4) without teacher forcing achieves exponentially small loss $\lVert\hat{\bm{y}}_{\operatorname{test}}-\bm{y}_{\operatorname{test}}\rVert_{
\infty}\leq\exp(-\Omega(d^{\epsilon/16}))$ in $\log_{2}k$ iterations.

This gives the same order of separation from Theorem 2(2) as in Section 3.2. Hence transformers can learn parities even without teacher forcing, if the consistency of the chain of reasoning is suitably controlled for. Moreover, our result shows that logarithmic time suffices to learn parity by exploiting the hierarchical decomposition in Figure 1. This extends the circuit complexity result in Merrill and Sabharwal (), which states that bounded-depth transformers with a logarithmic number of CoT steps can express problems in log-space; Theorem 7 guarantees that transformers of depth one can *learn by gradient descent* any such function in the exponentially large class $P$.

Sketch of proof. The idea is to inductively show that each $2$-parity subtask $x_{m}$ at level $\ell$ will become solved at time $t=\ell$. When $t\leq\ell-2$, $x_{m}$ will not have access to its child nodes $x_{\mathsf{c}_{1}[m]},x_{\mathsf{c}_{2}[m]}$ since they will also not be optimized, so the weights do not change. At time $\ell-1$, its child nodes learn to output their respective parities with high precision, so the objective is approximately equivalent to that of Theorem 5. Then the gradient signal will similarly concentrate on $w_{\mathsf{c}_{1}[m],m},w_{\mathsf{c}_{2}[m],m}$ and $x_{m}$ will become solved in the next step. It remains to bound the gradients arising from the loss terms further down the chain $\bm{x}_{d+1}\to\cdots\to\bm{x}_{d+k-1}$ (propagation of error), and verify that irrelevant weights $w_{j,m}$ ($\mathsf{p}[j]\neq m$) and already optimized weights do not change. This is done by exploiting the effect of the filter $\iota$ and concentration bounds for the original and augmented samples. ∎

###### Lemma 6 .

###### Theorem 7 (CoT without teacher forcing) .

## 4 Conclusion

In this paper, we provide a theoretical foundation for training transformers with CoT to perform stepwise reasoning through task decomposition by studying the $k$-parity problem. Our results show that gradient-based learning of parity requires significant iterations without intermediate supervision, but task decomposition using teacher forcing enables efficient learning in a single gradient update. Furthermore, when transformers are trained to generate reasoning chains end-to-end, data augmentation and self-consistency checks enhance their ability to solve complex tasks. Our work offers a foundational understanding of how CoT can be leveraged in fine-tuning transformers to improve multi-step reasoning capability.

## Acknowledgments

JK was partially supported by JST CREST (JPMJCR2015). TS was partially supported by JSPS KAKENHI (24K02905) and JST CREST (JPMJCR2115).

## Appendix

## Appendix A Proof of Theorem 2

Denote the empirical inner product on $\operatorname{\mathbb{R}}^{d}$ by $\langle f,g\rangle_{n}=\frac{1}{n}\sum_{i=1}^{n}f(\bm{x}^{i})g(\bm{x}^{i})$ and the corresponding norm as $\lVert f\rVert_{n}^{2}=\langle f,f\rangle_{n}$. We also write

$$ $L_{n,p}(\theta)=\frac{1}{2}\lVert p-f_{\theta}\rVert_{n}^{2}=\frac{1}{2n}\sum_ {i=1}^{n}(p(\bm{x}^{i})-f_{\theta}(\bm{x}^{i}))^{2}$ $$

to emphasize the dependency of $L_{n}$ on $p$. Note that $(d/k)^{k}\leq\binom{d}{k}\leq(ed/k)^{k}$ so that $|P|=e^{\Theta(d)}$.

#### Bounding gradient variance.

Consider the variance of the empirical gradient $\nabla L_{n,p}$ w.r.t. the target parity $p$:

$$ $\operatorname{Var}_{n}(\theta;P):=\mathbb{E}_{p\in P}\left[\lVert\nabla L_{n,p }(\theta)-\mathbb{E}_{p^{\prime}\in P}[\nabla L_{n,p^{\prime}}(\theta)]\rVert^ {2}\right].$ $$

We proceed to evaluate the magnitude of $\operatorname{Var}_{n}(\theta;P)$. For $p,p^{\prime}\in P$ with $p\neq p^{\prime}$ it holds that

$$ $\displaystyle\langle p,p^{\prime}\rangle_{n}=\frac{1}{n}\sum_{i=1}^{n}\left( \prod_{j\in p}x_{j}^{i}\prod_{j^{\prime}\in p^{\prime}}x_{j^{\prime}}^{i} \right)=\frac{1}{n}\sum_{i=1}^{n}\left(\prod_{j\in p\Delta p^{\prime}}x_{j}^{i }\right).$ $$

Since $\prod_{j\in p\Delta p^{\prime}}x_{j}^{i}$ is i.i.d. $\operatorname{Unif}(\{\pm 1\})$ for fixed $p,p^{\prime}$, by applying a union bound over Hoeffding’s inequality, it follows for $\delta:=\sqrt{4d/n}$ that

$$ $\displaystyle\Pr\left(\sup_{p\neq p^{\prime}}|\langle p,p^{\prime}\rangle_{n}| \geq\delta\right)\leq|P|(|P|-1)\exp\left(-\frac{n\delta^{2}}{2}\right)\leq \binom{d}{k}^{2}e^{-2d}\leq\left(\frac{2}{e}\right)^{2d}.$ $$

Then with probability at least $1-e^{-\Omega(d)}$ over random sampling, every off-diagonal component of the Gram matrix $G_{P}:=(\langle p,p^{\prime}\rangle_{n})_{p,p^{\prime}\in P}$ has magnitude at most $\delta$, while the diagonal entries are equal to $1$. By the Gershgorin circle theorem, the maximum eigenvalue of $G_{P}$ satisfies

$$ $|\lambda_{\mathrm{max}}(G_{P})-1|\leq(|P|-1)\delta,$ $$

thus $\lambda_{\mathrm{max}}(G_{P})\leq 2(1\vee|P|\delta)$. This implies that $P$ constitutes a partial frame for the empirical $L^{2}$ norm with the corresponding frame upper bound. More specifically, for $f:\operatorname{\mathbb{R}}^{d}\to\operatorname{\mathbb{R}}$, decompose

$$ $f=\sum_{p\in P}c_{p}\cdot p+f_{0},\quad f_{0}\in(\operatorname{span}P)^{\perp},$ $$

for some coefficient sequence $c=(c_{p})_{p\in P}$. It follows that

$$ $\lVert f\rVert_{n}^{2}\geq\lVert f-f_{0}\rVert_{n}^{2}=\sum_{p,p^{\prime}\in P }c_{p}c_{p^{\prime}}\langle p,p^{\prime}\rangle_{n}=\lVert G_{P}^{1/2}c\rVert^ {2}$ $$

and

$$ $\sum_{p\in P}\langle f,p\rangle_{n}^{2}=\sum_{p\in P}\Bigg{(}\sum_{p^{\prime} \in P}c_{p^{\prime}}\langle p,p^{\prime}\rangle\Bigg{)}^{2}=\lVert G_{P}c \rVert^{2}\leq\lambda_{\mathrm{max}}(G_{P})\lVert f\rVert_{n}^{2}.$ $$

Denoting $D=\dim\Theta$, we can therefore bound $\operatorname{Var}_{n}(\theta;P)$ as

$$ $\displaystyle\operatorname{Var}_{n}(\theta;P)$ $\displaystyle=\inf_{\mu\in\operatorname{\mathbb{R}}^{D}}\mathbb{E}_{p\in P} \left[\lVert\nabla L_{n,p}(\theta)-\mu\rVert^{2}\right]$ $\displaystyle\leq\mathbb{E}_{p\in P}\left[\left\lVert\frac{1}{n}\sum_{i=1}^{n} (f_{\theta}(\bm{x}^{i})-p(\bm{x}^{i}))\nabla f_{\theta}(\bm{x}^{i})-\frac{1}{n }\sum_{i=1}^{n}f_{\theta}(\bm{x}^{i})\nabla f_{\theta}(\bm{x}^{i})\right\rVert ^{2}\right]$ $\displaystyle=\mathbb{E}_{p\in P}\left[\sum_{j=1}^{D}\langle\nabla_{\theta_{j} }f_{\theta},p\rangle_{n}^{2}\right]=\frac{1}{|P|}\sum_{p\in P}\sum_{j=1}^{D} \langle\nabla_{\theta_{j}}f_{\theta},p\rangle_{n}^{2}$ $\displaystyle\leq\sum_{j=1}^{D}\frac{\lambda_{\mathrm{max}}(G_{P})}{|P|}\lVert \nabla_{\theta_{j}}f_{\theta}\rVert_{n}^{2}$ $\displaystyle\leq 2\left(\frac{1}{|P|}\vee\sqrt{\frac{4d}{n}}\right)\sup_{ \theta,\bm{x}}\lVert\nabla f_{\theta}(\bm{x})\rVert^{2}.$ $$

Now by Chebyshev’s inequality, for any $\varepsilon>0$ it holds that

$$ $\displaystyle\Pr\left(\lVert\nabla L_{n,p}(\theta)-\mathbb{E}_{p^{\prime}\in P }[\nabla L_{n,p^{\prime}}(\theta)]\rVert>\varepsilon\right)\leq\frac{ \operatorname{Var}_{n}(\theta;P)}{\varepsilon^{2}}.$ $$

#### Constructing the oracle.

As in Shamir (), we define the $\varepsilon$-approximate oracle $\widetilde{\nabla}$ as

$$ $\displaystyle\widetilde{\nabla}L_{n,p}(\theta)=\begin{cases}\mathbb{E}_{p^{ \prime}\in P}[\nabla L_{n,p^{\prime}}(\theta)]&\lVert\nabla L_{n,p}(\theta)- \mathbb{E}_{p^{\prime}\in P}[\nabla L_{n,p^{\prime}}(\theta)]\rVert> \varepsilon,\\ \nabla L_{n,p}(\theta)&\text{otherwise.}\end{cases}$ $$

By union bounding, we see that during $T$ steps the oracle always defaults to the mean gradient and does not reveal any information on the true parity $p$, with probability at least

$$ $\Pr(Q)\geq 1-\frac{2T}{\varepsilon^{2}}\left(\frac{1}{|P|}\vee\sqrt{\frac{4d}{ n}}\right)\sup_{\theta,\bm{x}}\lVert\nabla f_{\theta}(\bm{x})\rVert^{2},$ $$

where $Q\subseteq P$ denotes the corresponding subset of the hypothesis space. Note that the argument can be extended to any randomized algorithm and random initialization in a straightforward manner by lifting to the product probability space, and so we consider $Q$ to be fixed. Then for any target parity $p\in Q$, the output $\mathcal{A}(\theta)$ of the algorithm after $T$ steps does not depend on $p$, so the predictor $f=f_{\mathcal{A}(\theta)}$ is also fixed.

#### Lower bounding the loss.

We first remark that a simpler proof can be given for the sup norm error, which is enough to establish a separation. Consider arbitrary $p,p^{\prime}\in P$ with $p\neq p^{\prime}$ and let $\bm{x}\in\{\pm 1\}^{d}$ be such that $p(\bm{x})\neq p^{\prime}(\bm{x})$, then

$$ $\left\lvert p(\bm{x})-f(\bm{x})\right\rvert+\left\lvert p^{\prime}(\bm{x})-f( \bm{x})\right\rvert\geq\left\lvert 1-f(\bm{x})\right\rvert+\left\lvert-1-f(\bm {x})\right\rvert\geq 2.$ $$

Now let $\sigma:Q\to Q$ be any automorphism of $Q$ with no fixed points. The $L_{\infty}$ error can be bounded below by restricting to the noninformative set $Q$ as follows.

$$ $\displaystyle\mathbb{E}_{p\in P}\left[\sup_{\bm{x}}\left\lvert p(\bm{x})-f_{ \mathcal{A}(\theta)}(\bm{x})\right\rvert\right]$ $\displaystyle\geq\mathbb{E}_{p\in P}\left[1_{\{p\in Q\}}\sup_{\bm{x}}\left \lvert p(\bm{x})-f(\bm{x})\right\rvert\right]$ $\displaystyle=\frac{1}{2|P|}\sum_{p\in Q}\left({\sup_{\bm{x}}}\left\lvert p( \bm{x})-f(\bm{x})\right\rvert+{\sup_{\bm{x}}}\left\lvert\sigma\circ p(\bm{x})- f(\bm{x})\right\rvert\right)$ $\displaystyle\geq\frac{1}{2|P|}\cdot 2|Q|=\Pr(Q).$ $$

For mean squared error, we similarly restrict to $Q$ so that

$$ $\mathbb{E}_{p\in P,\bm{x}}\left[(p(\bm{x})-f_{\mathcal{A}(\theta)}(\bm{x}))^{2 }\right]\geq\mathbb{E}_{p\in P,\bm{x}}\left[1_{\{p\in Q\}}(p(\bm{x})-f(\bm{x}) )^{2}\right].$ $$

Since the range of $p$ is contained in $[-1,1]$, the above loss will not increase when $f$ is replaced by its clipped version $\bar{f}(\bm{x})=(f(\bm{x})\wedge 1)\vee(-1)$. Moreover, in Lemma 8 (proved at the end of the section) we show that $\left\lvert\mathbb{E}_{p\in P}[p(\bm{x})]\right\rvert\leq e^{-\Omega(d)}$ holds with probability $1-e^{-\Omega(d)}$ over the sample space of $\bm{x}$, so that

$$ $\displaystyle\left\lvert\mathbb{E}_{p\in P,\bm{x}}\left[p(\bm{x})\bar{f}(\bm{x })\right]\right\rvert\leq(1-e^{-\Omega(d)})\mathbb{E}_{p\in P}\left[p(\bm{x}) \right]+e^{-\Omega(d)}\leq e^{-\Omega(d)}$ $$

and also

$$ $\displaystyle\mathbb{E}_{p\in P,\bm{x}}\left[1_{\{p\in Q\}}p(\bm{x})\bar{f}( \bm{x})\right]$ $\displaystyle=\mathbb{E}_{p\in P,\bm{x}}\left[p(\bm{x})\bar{f}(\bm{x})\right]- \mathbb{E}_{p\in P,\bm{x}}\left[1_{\{p\notin Q\}}p(\bm{x})\bar{f}(\bm{x})\right]$ $\displaystyle\leq e^{-\Omega(d)}+(1-\Pr(Q))\mathbb{E}_{\bm{x}}\left[|\bar{f}( \bm{x})|\right]$ $\displaystyle\leq e^{-\Omega(d)}+\frac{(1-\Pr(Q))^{2}}{2\Pr(Q)}+\frac{\Pr(Q)}{ 2}\mathbb{E}_{\bm{x}}\left[\bar{f}(\bm{x})^{2}\right].$ $$

Therefore we may bound

$$ $\displaystyle\mathbb{E}_{p\in P,\bm{x}}\left[(p(\bm{x})-f_{\mathcal{A}(\theta) }(\bm{x}))^{2}\right]$ $\displaystyle\geq\mathbb{E}_{p\in P,\bm{x}}\left[1_{\{p\in Q\}}(p(\bm{x})-\bar {f}(\bm{x}))^{2}\right]$ $\displaystyle=\Pr(Q)-2\mathbb{E}_{p\in P,\bm{x}}\left[1_{\{p\in Q\}}p(\bm{x}) \bar{f}(\bm{x})\right]+\Pr(Q)\cdot\mathbb{E}_{\bm{x}}\left[\bar{f}(\bm{x})^{2}\right]$ $\displaystyle\geq\Pr(Q)-\frac{(1-\Pr(Q))^{2}}{\Pr(Q)}-2e^{-\Omega(d)}$ $\displaystyle\geq 2-\frac{1}{\Pr(Q)}-2e^{-\Omega(d)}$ $\displaystyle\geq 1-\frac{4T}{\varepsilon^{2}}\left(\frac{1}{|P|}\vee\sqrt{ \frac{4d}{n}}\right)\sup_{\theta,\bm{x}}\lVert\nabla f_{\theta}(\bm{x})\rVert^ {2}-2e^{-\Omega(d)},$ (5) $$

where we have used the inequality $2-(1-t)^{-1}\geq 1-2t$, valid for $t\in[0,\frac{1}{2}]$.

The proof is completed by evaluating the following cases.

- (1)
If $n=e^{\Omega(d)}$ and $T,\lVert\nabla f_{\theta}\rVert=O(\operatorname{poly}(d))$, the gradient variance is bounded as $\operatorname{Var}_{n}(\theta;P)\leq e^{-\Omega(d)}$. By taking $\varepsilon=\operatorname{Var}_{n}(\theta;P)^{1/3}$, it follows that $\Pr(Q)=1-e^{-\Omega(d)}$ and (5) yields the lower bound $1-e^{-\Omega(d)}$.
- (2)
If $n=\Omega(d^{\nu})$, $\lVert\nabla f_{\theta}\rVert=O(d^{\nu_{1}})$, $\varepsilon=\Theta(d^{-\nu_{2}})$ and $T=O(d^{\nu_{3}})$, the gradient variance is bounded as $\operatorname{Var}_{n}(\theta;P)\leq O(d^{2\nu_{1}+\nu_{3}+1/2-\nu/2})=O(d^{-2
\nu_{2}-\nu_{4}})$ and (5) yields the lower bound $1-O(d^{-\nu_{4}})$.

∎

###### Lemma 8 .

If $k=\Theta(d)$, it holds with probability at least $1-e^{-\Omega(d)}$ over random sampling that

$$ $\left\lvert\mathbb{E}_{p\in P}[p(\bm{x})]\right\rvert\leq e^{-\Omega(d)}.$ $$

###### Proof.

Let $m$ denote the number of $-1$s in $\bm{x}$. By the Chernoff bound for the binomial distribution,

$$ $\Pr\left(\left\lvert m-\frac{d}{2}\right\rvert\leq\frac{\delta d}{2}\right) \geq 1-2\exp\left(-\frac{\delta^{2}d}{6}\right)$ $$

for a constant $\delta\in(0,1)$ to be determined, so we assume the above event throughout the proof. Moreover denoting the complement parity $p^{c}=[d]\setminus p$, it holds that $p(\bm{x})=x_{1}\cdots x_{d}\cdot p^{c}(\bm{x})$ and $\left\lvert\mathbb{E}_{p\in P}[p(\bm{x})]\right\rvert=\left\lvert\mathbb{E}_{p
\in P}[p^{c}(\bm{x})]\right\rvert$, so it suffices to consider the case where $2k\leq d$.

Without loss of generality, we may assume that $\bm{x}=(-1,\cdots,-1,1,\cdots,1)$ so that $p(\bm{x})$ is decided as $(-1)^{\left\lvert p\cap[m]\right\rvert}$. We bound the cardinality of the set $P_{+}:=\{p\in P\mid p(\bm{x})=1\}$. Each parity in $P_{+}$ can be determined by choosing $2j$ elements from $[m]$ and $k-2j$ elements from $[d]\setminus[m]$. Denoting by $[t]_{j}$ the *coefficient* of operator of order $j$, we can evaluate

$$ $\displaystyle|P_{+}|$ $\displaystyle=\sum_{j=0}^{\lfloor m/2\rfloor}\binom{m}{2j}\binom{d-m}{k-2j}$ $\displaystyle=\sum_{j=0}^{\lfloor m/2\rfloor}\binom{m}{2j}[t]_{k-2j}(1+t)^{d-m }=\sum_{j=0}^{\lfloor m/2\rfloor}\binom{m}{2j}[t]_{k}(1+t)^{d-m}t^{2j}$ $\displaystyle=[t]_{k}(1+t)^{d-m}\sum_{j=0}^{\lfloor m/2\rfloor}\binom{m}{2j}t^ {2j}=\frac{1}{2}[t]_{k}(1+t)^{d-m}((1+t)^{m}+(1-t)^{m})$ $\displaystyle=\frac{1}{2}\binom{d}{k}+\frac{1}{2}[t]_{k}(1-t^{2})^{m^{\prime}} (1+st)^{d-2m^{\prime}}$ $\displaystyle=\frac{1}{2}\binom{d}{k}+\frac{s^{k}}{2}\sum_{j=0}^{\lfloor k/2 \rfloor}(-1)^{j}\binom{m^{\prime}}{j}\binom{d-2m^{\prime}}{k-2j},$ $$

where $m^{\prime}=m\wedge(d-m)$ and $s=\pm 1$. It further follows that

$$ $\displaystyle\left\lvert\frac{|P_{+}|}{|P|}-\frac{1}{2}\right\rvert$ $\displaystyle\leq\frac{1}{2|P|}\sum_{j=0}^{\lfloor k/2\rfloor}\binom{m^{\prime }}{j}\binom{d-2m^{\prime}}{k-2j}\leq\frac{1}{2|P|}\sum_{j=0}^{\lfloor k/2 \rfloor}\binom{\lfloor d/2\rfloor}{j}\binom{\lfloor\delta d\rfloor}{k-2j}$ $\displaystyle\leq\frac{\lfloor k/2\rfloor}{2}\binom{d}{k}^{-1}\binom{\lfloor d /2\rfloor}{\lfloor k/2\rfloor}\binom{\lfloor\delta d\rfloor}{\lfloor\delta d/2 \rfloor}\leq\frac{d}{4}\binom{d-\lfloor d/2\rfloor-\lfloor\delta d\rfloor}{k- \lfloor k/2\rfloor-\lfloor\delta d/2\rfloor}^{-1}$ $\displaystyle\leq\frac{d}{4}\binom{\lfloor d/4\rfloor}{\lfloor k/4\rfloor}^{-1 }\leq\frac{d}{4}\left(\frac{d}{k}\right)^{-k/4}=e^{-\Theta(d)}.$ $$

Here, we have chosen $\delta=\frac{1}{4}\wedge\frac{k}{2d}=\Theta(1)$ and used the inequality $\binom{a_{1}+a_{2}+a_{3}}{b_{1}+b_{2}+b_{3}}\geq\binom{a_{1}}{b_{1}}\binom{a_{
2}}{b_{2}}\binom{a_{3}}{b_{3}}$. From this, we conclude that

$$ $\displaystyle\left\lvert\mathbb{E}_{p\in P}[p(\bm{x})]\right\rvert=\left\lvert \frac{|P\setminus P_{+}|-|P_{+}|}{|P|}\right\rvert\leq e^{-\Omega(d)}$ $$

with probability $1-e^{-\Omega(d)}$.
∎

###### Lemma 8 .

###### Proof.

## Appendix B Proof of Theorem 5

#### Proof of Lemma 4 .

For each $d+1\leq m\leq d+k-1$ and $1\leq j<m$, the only component of $f^{\circ}$ depending on $w_{j,m}$ is $f_{m}^{\circ}$ and

$$ $\displaystyle\left\lvert\frac{\partial f_{m}^{\circ}(\bm{x};\mathbf{W})}{ \partial w_{j,m}}\right\rvert$ $\displaystyle=\left\lvert\phi^{\prime}(\hat{z}_{m})\right\rvert\cdot\left \lvert\frac{\partial\hat{z}_{m}}{\partial w_{j,m}}\right\rvert$ $\displaystyle\leq\lVert\phi^{\prime}\rVert_{\infty}\left\lvert\frac{\partial \sigma_{j}(\bm{w}_{m})}{\partial w_{j,m}}x_{j}+\sum_{\alpha\neq j}\frac{ \partial\sigma_{\alpha}(\bm{w}_{m})}{\partial w_{j,m}}x_{\alpha}\right\rvert$ $\displaystyle=\lVert\phi^{\prime}\rVert_{\infty}\left\lvert\sigma_{j}(\bm{w}_{ m})(1-\sigma_{j}(\bm{w}_{m}))x_{j}-\sigma_{j}(\bm{w}_{m})\sum_{\alpha\neq j} \sigma_{\alpha}(\bm{w}_{m})x_{\alpha}\right\rvert$ $\displaystyle\leq\lVert\phi^{\prime}\rVert_{\infty}\sigma_{j}(\bm{w}_{m})(1- \sigma_{j}(\bm{w}_{m}))+\lVert\phi^{\prime}\rVert_{\infty}\sigma_{j}(\bm{w}_{m })\sum_{\alpha\neq j}\sigma_{\alpha}(\bm{w}_{m})$ $\displaystyle\leq 2\lVert\phi^{\prime}\rVert_{\infty}\sigma_{j}(\bm{w}_{m}).$ $$

Hence it follows that

$$ $\displaystyle\sum_{m=d+1}^{d+k-1}\lVert\nabla_{\mathbf{W}}f_{m}^{\circ}\rVert^ {2}\leq 4\lVert\phi^{\prime}\rVert_{\infty}^{2}\sum_{m=d+1}^{d+k-1}\sum_{j=1}^ {m-1}\sigma_{j}(\bm{w}_{m})^{2}\leq 4\lVert\phi^{\prime}\rVert_{\infty}^{2}(k- 1)=O(d),$ $$

as desired. ∎

We say that a parity $x_{j_{1}}\cdots x_{j_{r}}$ for $1\leq j_{1},\cdots,j_{r}\leq d+k-1$ is *trivial* if it always equals $1$, or equivalently if its reduction to the independent bits $x_{1},\cdots,x_{d}$ cancel out mod $2$. For example, the parity $x_{1}x_{4}x_{17}$ in Figure 1 is trivial. Define $I_{r,m}$ as the set of nontrivial index $r$-tuples less than $m$:

$$ $I_{r,m}=\{(j_{1},\cdots,j_{r})\mid 1\leq j_{1},\cdots,j_{r}\leq m-1,\,x_{j_{1} }\cdots x_{j_{r}}\not\equiv 1\}.$ $$

In particular, $I_{1,m}=[m-1]$ since no single parity is trivial.

###### Lemma 9 (concentration of interaction terms) .

If each bit $x_{j}^{i}$ for $i\in[n]$, $j\in[d]$ is i.i.d. generated from the uniform distribution on $\{\pm 1\}$, for any $p>0$ it holds with probability at least $1-p$ that

$$ $\max_{\begin{subarray}{c}1\leq r\leq 4\\ (j_{1},\cdots,j_{r})\in I_{r,m}\end{subarray}}\frac{\left\lvert\left\langle\bm {x}_{j_{1}},\cdots,\bm{x}_{j_{r}}\right\rangle\right\rvert}{n}\leq\kappa:= \sqrt{\frac{2}{n}\log\frac{32d^{4}}{p}}.$ $$

###### Proof.

Each tuple $(j_{1},\cdots,j_{r})\in I_{r,m}$ computes a specific nontrivial parity $x_{j_{1}}\cdots x_{j_{r}}$ for which the bits $x_{j_{1}}^{i}\cdots x_{j_{r}}^{i}$, $i=1,\cdots,n$ are i.i.d. $\operatorname{Unif}(\{\pm 1\})$ due to symmetry. By Hoeffding’s inequality we have that

$$ $\displaystyle\Pr\left(\left\lvert\left\langle\bm{x}_{j_{1}},\cdots,\bm{x}_{j_{ r}}\right\rangle\right\rvert\geq\lambda\right)\leq 2e^{-\lambda^{2}/2n}.$ $$

Moreover, $|I_{r,m}|\leq(d+k-1)^{r}\leq(2d-1)^{r}$ so that

$$ $\displaystyle|I_{1,m}|+\cdots+|I_{4,m}|\leq(2d-1)+\cdots+(2d-1)^{4}<(2d)^{4}.$ $$

Therefore it follows by union bounding that

$$ $\displaystyle\Pr\left(\max_{1\leq r\leq 4,(j_{1},\cdots,j_{r})\in I_{r,m}} \left\lvert\left\langle\bm{x}_{j_{1}},\cdots,\bm{x}_{j_{r}}\right\rangle\right \rvert\geq\lambda\right)\leq 32d^{4}e^{-\lambda^{2}/2n},$ $$

which implies the statement.
∎

In particular, we take $n=\Omega(d^{2+\epsilon})$ and $p=\exp(-d^{\epsilon/2})$ so that $\kappa=O(d^{-1-\epsilon/4})$. This will ensure that the informative gradient signals will dominate the irrelevant interaction terms.

We now proceed to the main proof of Theorem 5. The superscript $(0)$ at initialization is omitted for simplicity. The loss can be written more explicitly as

$$ $\displaystyle L(\mathbf{W})=\frac{1}{2n}\sum_{m=d+1}^{d+k-1}\lVert\phi(\hat{ \bm{z}}_{m})-\bm{x}_{m}\rVert^{2},\quad\hat{\bm{z}}_{m}=\sum_{j=1}^{m-1}\sigma _{j}(\bm{w}_{m})\bm{x}_{j}.$ $$

It is straightforward to verify for $1\leq\alpha<m$ that

$$ $\displaystyle\frac{\partial\sigma_{\alpha}(\bm{w}_{m})}{\partial w_{j,m}}=( \delta_{j\alpha}-\sigma_{\alpha}(\bm{w}_{m}))\sigma_{j}(\bm{w}_{m})=(\delta_{j \alpha}-\sigma_{j}(\bm{w}_{m}))\sigma_{\alpha}(\bm{w}_{m})$ $$

and

$$ $\displaystyle\frac{\partial\hat{\bm{z}}_{m}}{\partial w_{j,m}}$ $\displaystyle=\sum_{\alpha=1}^{m-1}(\delta_{j\alpha}-\sigma_{j}(\bm{w}_{m})) \sigma_{\alpha}(\bm{w}_{m})\bm{x}_{\alpha}=\sigma_{j}(\bm{w}_{m})(\bm{x}_{j}- \hat{\bm{z}}_{m}).$ $$

Then the gradient of $L$ with respect to each element $w_{j,m}$ at initialization can be computed as

$$ $\displaystyle\frac{\partial L}{\partial w_{j,m}}(\mathbf{W})$ $\displaystyle=\frac{1}{n}(\phi(\hat{\bm{z}}_{m})-\bm{x}_{m})^{\top}\frac{ \partial\phi(\hat{\bm{z}}_{m})}{\partial w_{j,m}}$ $\displaystyle=\frac{\sigma_{j}(\bm{w}_{m})}{n}\left\langle\phi(\hat{\bm{z}}_{m })-\bm{x}_{m},\phi^{\prime}(\hat{\bm{z}}_{m}),\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle$ (6) $\displaystyle=-\frac{1}{n(m-1)}\left\langle\bm{x}_{m},2c\hat{\bm{z}}_{m},\bm{x }_{j}-\hat{\bm{z}}_{m}\right\rangle$ (7) $\displaystyle\qquad+\frac{1}{n(m-1)}\left\langle-\bm{1}_{n}+c\hat{\bm{z}}_{m}^ {2},2c\hat{\bm{z}}_{m},\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle$ (8) $\displaystyle\qquad+\frac{1}{n(m-1)}\left\langle O(|\hat{\bm{z}}_{m}|^{4}),2c \hat{\bm{z}}_{m},\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle$ (9) $\displaystyle\qquad+\frac{1}{n(m-1)}\left\langle\phi(\hat{\bm{z}}_{m})-\bm{x}_ {m},O(|\hat{\bm{z}}_{m}|^{3}),\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle.$ (10) $$

###### Lemma 9 (concentration of interaction terms) .

###### Proof.

#### Computing interaction strengths.

The term (7) will be shown to contain the dominating gradient signal when $j=\mathsf{c}_{1}[m],\mathsf{c}_{2}[m]$, while the other terms can be bounded as perturbations. Let $\ell=\mathsf{h}_{2}[m]$ so that $x_{m}$ computes a $2^{\ell}$-parity.

For term (7), we substitute $\hat{\bm{z}}_{m}=\frac{1}{m-1}\sum_{\alpha}\bm{x}_{\alpha}$ at initialization to expand

$$ $\displaystyle\frac{1}{n}\left\langle\bm{x}_{m},\hat{\bm{z}}_{m},\bm{x}_{j}- \hat{\bm{z}}_{m}\right\rangle=\frac{1}{n(m-1)}\sum_{\alpha}\left\langle\bm{x}_ {m},\bm{x}_{\alpha},\bm{x}_{j}\right\rangle-\frac{1}{n(m-1)^{2}}\sum_{\alpha, \beta}\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle,$ $$

where the dummy indices $\alpha,\beta,\cdots$ are taken to run over $[m-1]$. Let us evaluate the third-order interaction terms $\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle$. If $\mathsf{h}[\alpha]=\ell$, $x_{m}x_{\alpha}$ computes the parity of $2^{\ell+1}$ independent bits from $x_{1},\cdots,x_{d}$ so $x_{m}x_{\alpha}x_{\beta}$ cannot be trivial, hence $(m,\alpha,\beta)\in I_{3,m}$ and $\left\lvert\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle
\right\rvert\leq n\kappa$ by Lemma 9. Similarly, $\mathsf{h}[\beta]=\ell$ implies that $(m,\alpha,\beta)\in I_{3,m}$. Suppose $\mathsf{h}[\alpha],\mathsf{h}[\beta]\leq\ell-1$; unless $\mathsf{h}[\alpha]=\mathsf{h}[\beta]=\ell-1$, the combined parity $x_{\alpha}x_{\beta}$ will not contain enough independent bits to cancel out the $2^{\ell}$ bits in $x_{m}$, so again $(m,\alpha,\beta)\in I_{3,m}$. Moreover if $\mathsf{h}[\alpha]=\mathsf{h}[\beta]=\ell-1$, $x_{m}x_{\alpha}x_{\beta}$ will be trivial if and only if $\{\alpha,\beta\}=\{\mathsf{c}_{1}[m],\mathsf{c}_{2}[m]\}$, in which case $\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle=n$. Thus we have that

$$ $\displaystyle\frac{1}{n}\sum_{\alpha}\left\langle\bm{x}_{m},\bm{x}_{\alpha}, \bm{x}_{\beta}\right\rangle=2+\frac{1}{n}\sum_{(m,\alpha,\beta)\in I_{3,m}} \left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{\beta}\right\rangle=2+O((m-1)^{ 2}\kappa).$ $$

Similarly, the contraction $\left\langle\bm{x}_{m},\bm{x}_{\alpha},\bm{x}_{j}\right\rangle$ can be nontrivial only if $\mathsf{p}[j]=m$ and only when $\alpha$ is the other child node of $x_{m}$, so that

$$ $\displaystyle\frac{1}{n}\sum_{\alpha}\left\langle\bm{x}_{m},\bm{x}_{\alpha}, \bm{x}_{j}\right\rangle=\begin{cases}1+O((m-1)\kappa)&\mathsf{p}[j]=m,\\ O((m-1)\kappa)&\text{otherwise.}\end{cases}$ $$

Since $\kappa=O(d^{-1-\epsilon/4})$ and $d<m\leq 2d-1$, we can therefore isolate the leading term of order $\Theta(d^{-2})$ as

$$ $\displaystyle-\frac{1}{n(m-1)}\left\langle\bm{x}_{m},2c\hat{\bm{z}}_{m},\bm{x} _{j}-\hat{\bm{z}}_{m}\right\rangle$ $\displaystyle=-\frac{2c}{(m-1)^{2}}(1_{\{\mathsf{p}[j]=m\}}+O(d\kappa))+\frac{ 2c}{(m-1)^{3}}(2+O(d^{2}\kappa))$ $\displaystyle=-\frac{2c}{(m-1)^{2}}1_{\{\mathsf{p}[j]=m\}}+O(d^{-2-\epsilon/4}).$ $$

Next, for term (8), we expand

$$ $\displaystyle\frac{1}{n}\left\langle-\bm{1}_{n}+c\hat{\bm{z}}_{m}^{2},2c\hat{ \bm{z}}_{m},\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle=-\frac{2c}{n}\left\langle \hat{\bm{z}}_{m},\bm{x}_{j}\right\rangle+\frac{2c}{n}\left\langle\hat{\bm{z}}_ {m}^{2}\right\rangle+\frac{2c^{2}}{n}\left\langle\hat{\bm{z}}_{m}^{3},\bm{x}_{ j}\right\rangle-\frac{2c^{2}}{n}\left\langle\hat{\bm{z}}_{m}^{4}\right\rangle.$ $$

The second-order terms can be computed as

$$ $\displaystyle\frac{1}{n}\left\langle\hat{\bm{z}}_{m},\bm{x}_{j}\right\rangle= \frac{1}{n(m-1)}\Bigg{(}\left\langle\bm{x}_{j},\bm{x}_{j}\right\rangle+\sum_{ \alpha\neq j}\left\langle\bm{x}_{\alpha},\bm{x}_{j}\right\rangle\Bigg{)}=\frac {1}{m-1}+O(\kappa),$ $\displaystyle\frac{1}{n}\left\langle\hat{\bm{z}}_{m}^{2}\right\rangle=\frac{1} {n(m-1)^{2}}\Bigg{(}\sum_{\alpha}\left\langle\bm{x}_{\alpha},\bm{x}_{\alpha} \right\rangle+\sum_{\alpha\neq\beta}\left\langle\bm{x}_{\alpha},\bm{x}_{\beta} \right\rangle\Bigg{)}=\frac{1}{m-1}+O(\kappa).$ $$

We evaluate the fourth-order interaction terms by looking at when $(\alpha,\beta,\gamma,\delta)\notin I_{4,m}$ can occur. Without loss of generality, suppose $\mathsf{h}[\alpha]\leq\mathsf{h}[\beta]\leq\mathsf{h}[\gamma]\leq\mathsf{h}[\delta]$.

- (i)
If $\mathsf{h}[\beta]<\mathsf{h}[\gamma]<\mathsf{h}[\delta]$, the parities of $x_{\alpha},x_{\beta},x_{\gamma}$ must combine without overlaps to cancel out $x_{\delta}$, so it must hold that $x_{\gamma}$ is a child of $x_{\delta}$ and $x_{\alpha},x_{\beta}$ are the two children of the other child. This subtree is fully determined by the choice of the index $\delta$ and one of its child nodes, so there are at most $O(d)$ trivial $4$-tuples in this case.
- (ii)
If $\mathsf{h}[\beta]=\mathsf{h}[\gamma]<\mathsf{h}[\delta]$, it still must hold that $\mathsf{h}[\gamma]=\mathsf{h}[\delta]-1$. Moreover, both $x_{\beta},x_{\gamma}$ must be children of $x_{\delta}$; otherwise, the bits of $x_{\delta}$ and the non-child node cannot be canceled out by the remaining nodes. Then either $x_{\beta}=x_{\gamma}$ or $x_{\beta}x_{\gamma}=x_{\delta}$, and in both cases we see that $x_{\alpha}x_{\beta}x_{\gamma}x_{\delta}$ cannot be trivial.
- (iii)
If $\mathsf{h}[\beta]<\mathsf{h}[\gamma]=\mathsf{h}[\delta]$, it must be that $\gamma=\delta$, otherwise the bits of $x_{\gamma}x_{\delta}$ cannot be canceled out by $x_{\alpha}x_{\beta}$. It follows that $x_{\alpha}x_{\beta}\equiv 1$ and $\alpha=\beta$, so there are $O(d^{2})$ trivial $4$-tuples in this case.
- (iv)
If $\mathsf{h}[\beta]=\mathsf{h}[\gamma]=\mathsf{h}[\delta]$, it must again hold that two indices must be equal, and the remaining two indices must also be equal, so there are also $O(d^{2})$ trivial $4$-tuples.

Hence it follows that

$$ $\displaystyle\frac{1}{n}\left\langle\hat{\bm{z}}_{m}^{4}\right\rangle$ $\displaystyle=\frac{1}{n(m-1)^{4}}\sum_{\alpha,\beta,\gamma,\delta}\left \langle\bm{x}_{\alpha},\bm{x}_{\beta},\bm{x}_{\gamma},\bm{x}_{\delta}\right\rangle$ $\displaystyle=\frac{1}{n(m-1)^{4}}\sum_{(\alpha,\beta,\gamma,\delta)\notin I_{ 4,m}}n+\frac{1}{n(m-1)^{4}}\sum_{(\alpha,\beta,\gamma,\delta)\in I_{4,m}}O(n\kappa)$ $\displaystyle=\frac{|[m-1]^{4}\setminus I_{4,m}|}{(m-1)^{4}}+\frac{|I_{4,m}|}{ (m-1)^{4}}O(\kappa)=O(d^{-2}+\kappa).$ $$

Furthermore, suppose $\alpha,\beta,\gamma,\delta$ are constrained to contain the index $j$. Then case (i) above counts $O(1)$ nontrivial tuples, while case (i), while cases (iii),(iv) count at most $O(d)$ tuples since there is only one free index to be determined. Hence we also have

$$ $\displaystyle\frac{1}{n}\left\langle\hat{\bm{z}}_{m}^{3},\bm{x}_{j}\right \rangle=\frac{1}{n(m-1)^{3}}\sum_{\alpha,\beta,\gamma}\left\langle\bm{x}_{ \alpha},\bm{x}_{\beta},\bm{x}_{\gamma},\bm{x}_{j}\right\rangle=\frac{O(d)}{(m- 1)^{3}}+O(\kappa)=O(d^{-2}+\kappa).$ $$

Combining the above, we obtain that

$$ $\displaystyle\frac{1}{n(m-1)}\left\langle-\bm{1}_{n}+c\hat{\bm{z}}_{m}^{2},2c \hat{\bm{z}}_{m},\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle=-\frac{2c}{(m-1)^{2} }+\frac{2c}{(m-1)^{2}}+\frac{O(\kappa)}{m-1}=O(d^{-2-\epsilon/4}).$ $$

For term (9), we note that $\left\langle|\hat{\bm{z}}_{m}|^{4}\right\rangle=\left\langle\hat{\bm{z}}_{m}^{
4}\right\rangle=O(nd^{-2}+n\kappa)$ as derived above. Then since each component of $\hat{\bm{z}}_{m}$, $\bm{x}_{j}-\hat{\bm{z}}_{m}$ are contained in $[-1,1],[-2,2]$, respectively, we have that

$$ $\displaystyle\frac{1}{n(m-1)}\left\langle O(|\hat{\bm{z}}_{m}|^{4}),2c\hat{\bm {z}}_{m},\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle=\frac{4c}{n(m-1)}O(\left \langle|\hat{\bm{z}}_{m}|^{4}\right\rangle)=O(d^{-2-\epsilon/4}).$ $$

Finally for term (10), by the Cauchy-Schwarz inequality we have

$$ $\displaystyle\frac{1}{n}\left\langle|\hat{\bm{z}}_{m}|^{3}\right\rangle$ $\displaystyle=\frac{1}{n}\sum_{i=1}^{n}|\hat{z}_{m,i}|^{3}$ $\displaystyle\leq\frac{1}{n}\left(\sum_{i=1}^{n}\hat{z}_{m,i}^{2}\right)^{1/2} \left(\sum_{i=1}^{n}\hat{z}_{m,i}^{4}\right)^{1/2}=\frac{1}{n}\left\langle\hat {\bm{z}}_{m}^{2}\right\rangle^{1/2}\left\langle\hat{\bm{z}}_{m}^{4}\right \rangle^{1/2}$ $\displaystyle=\frac{1}{n}O(nd^{-1})^{1/2}\cdot O(nd^{-2}+n\kappa)^{1/2}=O(d^{- 1-\epsilon/8}),$ $$

and so we may bound

$$ $\displaystyle\frac{1}{n(m-1)}\left\langle\phi(\hat{\bm{z}}_{m})-\bm{x}_{m},O(| \hat{\bm{z}}_{m}|^{3}),\bm{x}_{j}-\hat{\bm{z}}_{m}\right\rangle=\frac{4}{n(m-1 )}O(\left\langle|\hat{\bm{z}}_{m}|^{3}\right\rangle)=O(d^{-2-\epsilon/8}).$ $$

From (7)-(10) we conclude that

$$ $\displaystyle\frac{\partial L}{\partial w_{j,m}}(\mathbf{W})=-\frac{2c}{(m-1)^ {2}}1_{\{\mathsf{p}[j]=m\}}+O(d^{-2-\epsilon/8}),$ $$

and the same result applies to the approximate gradient $\widetilde{\nabla}_{w_{j,m}}L$ at initialization since the cutoff does not apply and each component of the noise is bounded by $O(d^{-2-\epsilon/8})$.

#### Concentration of softmax scores.

Taking $\eta=d^{2+\epsilon/16}$, the updated weights $\mathbf{W}^{(1)}=-\eta\widetilde{\nabla}L(\mathbf{W})$ become

$$ $\displaystyle w_{j,m}^{(1)}=\frac{2cd^{2+\epsilon/16}}{(m-1)^{2}}1_{\{\mathsf{ p}[j]=m\}}+O(d^{-\epsilon/16}).$ $$

In particular, for each $j\neq\mathsf{c}_{1}[m],\mathsf{c}_{2}[m]$ the softmax scores satisfy

$$ $\sigma_{j}(\bm{w}_{m}^{(1)})=e^{w_{j,m}^{(1)}}/\textstyle\sum_{\alpha}e^{w_{ \alpha,m}^{(1)}}\leq e^{w_{j,m}^{(1)}-w_{\mathsf{c}_{1}[m],m}^{(1)}}\leq\exp(- \Omega(d^{\epsilon/16})).$ $$

As softmax scores must sum to $1$, it holds that $\sigma_{\mathsf{c}_{1}[m]}(\bm{w}_{m}^{(1)})+\sigma_{\mathsf{c}_{2}[m]}(\bm{w}
_{m}^{(1)})\geq 1-\exp(-\Omega(d^{\epsilon/16}))$ and moreover

$$ $\frac{\sigma_{\mathsf{c}_{1}[m]}(\bm{w}_{m}^{(1)})}{\sigma_{\mathsf{c}_{2}[m]} (\bm{w}_{m}^{(1)})}=e^{w_{\mathsf{c}_{1}[m],m}^{(1)}-w_{\mathsf{c}_{2}[m],m}^{ (1)}}\leq\exp(O(d^{-\epsilon/16}))\leq 1+O(d^{-\epsilon/16})$ $$

from the inequality $e^{t}\leq 1+O(t)$ for small $t>0$. By symmetry, $\sigma_{\mathsf{c}_{2}[m]}(\bm{w}_{m}^{(1)})/\sigma_{\mathsf{c}_{1}[m]}(\bm{w}
_{m}^{(1)})\leq 1+O(d^{-\epsilon/16})$. By simple algebraic manipulation, we can conclude that

$$ $\displaystyle\frac{1}{2}-O(d^{-\epsilon/16})\leq\sigma_{\mathsf{c}_{1}[m]}(\bm {w}_{m}^{(1)}),\sigma_{\mathsf{c}_{2}[m]}(\bm{w}_{m}^{(1)})\leq\frac{1}{2}+O(d ^{-\epsilon/16}).$ $$

That is, the updated attention layer $\hat{\bm{z}}_{m}^{(1)}=\sum_{j}\sigma_{j}(\bm{w}_{m}^{(1)})\bm{x}_{j}$ has learned to take the average of the two child nodes and ignore the remaining input tokens at each step.

#### Evaluating the forward pass.

Now to bound the updated prediction loss, we evaluate the error $\lVert\hat{\bm{x}}_{m}^{(1)}-\bm{x}_{m}\rVert_{\infty}$ of each step of the forward pass for $d+1\leq m\leq d+k-1$. More precisely, define the increasing sequence

$$ $\epsilon_{m}=\max_{d<j\leq m}\left\lVert\hat{\bm{x}}_{j}^{(1)}-\bm{x}_{j} \right\rVert_{\infty},\quad\epsilon_{d}=0.$ $$

Then

$$ $\displaystyle\left\lVert\hat{\bm{x}}_{\mathsf{c}_{1}[m]}^{(1)}-\bm{x}_{\mathsf {c}_{1}[m]}\right\rVert_{\infty},\left\lVert\hat{\bm{x}}_{\mathsf{c}_{2}[m]}^{ (1)}-\bm{x}_{\mathsf{c}_{1}[m]}\right\rVert_{\infty}\leq\epsilon_{\mathsf{c}_{ 1}[m]},\epsilon_{\mathsf{c}_{2}[m]}\leq\epsilon_{m-1},$ $$

and for the intermediate values $\hat{\bm{z}}_{m}^{(1)}$ we have

$$ $\displaystyle\left\lVert\hat{\bm{z}}_{m}^{(1)}-\frac{\bm{x}_{\mathsf{c}_{1}[m] }+\bm{x}_{\mathsf{c}_{2}[m]}}{2}\right\rVert_{\infty}\leq\left\lVert\hat{\bm{z }}_{m}^{(1)}-\frac{\hat{\bm{x}}_{\mathsf{c}_{1}[m]}^{(1)}+\hat{\bm{x}}_{ \mathsf{c}_{2}[m]}^{(1)}}{2}\right\rVert_{\infty}+\epsilon_{m-1}$ $\displaystyle\leq\sum_{\mathsf{p}[j]\neq m}\sigma_{j}(\bm{w}_{m}^{(1)})+\left \lvert\sigma_{\mathsf{c}_{1}[m]}(\bm{w}_{m}^{(1)})-\frac{1}{2}\right\rvert+ \left\lvert\sigma_{\mathsf{c}_{2}[m]}(\bm{w}_{m}^{(1)})-\frac{1}{2}\right \rvert+\epsilon_{m-1}$ $\displaystyle\leq 2d\exp(-\Omega(d^{\epsilon/16}))+O(d^{-\epsilon/16})+ \epsilon_{m-1}$ $\displaystyle\leq C_{1}d^{-\epsilon/16}+\epsilon_{m-1},$ $$

for some constant $C_{1}>0$. Since $\phi$ behaves like a quadratic near $0,\pm 1$, it follows that

$$ $\displaystyle\epsilon_{m}=\lVert\hat{\bm{x}}_{m}^{(1)}-\bm{x}_{m}\rVert_{ \infty}=\left\lVert\phi(\hat{\bm{z}}_{m}^{(1)})-\phi\left(\frac{\bm{x}_{ \mathsf{c}_{1}[m]}+\bm{x}_{\mathsf{c}_{2}[m]}}{2}\right)\right\rVert_{\infty} \leq C_{2}(C_{1}d^{-\epsilon/16}+\epsilon_{m-1})^{2}$ $$

for some constant $C_{2}>0$ depending only on $\phi$. Then for sufficiently large $d$, by choosing $C_{3}$ such that $C_{2}(C_{1}+C_{3}d^{-\epsilon/16})^{2}\leq C_{3}$, for $\epsilon_{m-1}\leq C_{3}d^{-\epsilon/8}$ it follows that

$$ $\displaystyle\epsilon_{m}\leq C_{2}(C_{1}d^{-\epsilon/16}+C_{3}d^{-\epsilon/8} )^{2}\leq C_{3}d^{-\epsilon/8},$ $$

thus $\epsilon_{m}=O(d^{-\epsilon/8})$ inductively for all $m$. We conclude that $\lVert\hat{\bm{y}}-\bm{y}\rVert_{\infty}=\lVert\hat{\bm{x}}_{d+k-1}^{(1)}-\bm{
x}_{d+k-1}^{(1)}\rVert_{\infty}$ is bounded for all inputs as $O(d^{-\epsilon/8})$. ∎

## Appendix C Proof of Theorem 7

#### Proof of Lemma 6 .

For the iterative generation scheme (3), each $w_{j,m}$ affects $\hat{x}_{m}$ as well as all nodes $\hat{x}_{\alpha}$ on higher levels $\mathsf{h}[\alpha]>\mathsf{h}[m]$ through $\hat{x}_{m}$. We bound the contribution of each term to the total gradient inductively with respect to the level. Define for each $d<m\leq d+k-1$, $1\leq j\leq m-1$ and $0<\ell\leq v$ the quantity

$$ $\xi_{j,m,\ell}:=\max_{\alpha\leq d_{\ell}}\left\lvert\frac{\partial\hat{x}_{ \alpha}}{\partial w_{j,m}}\right\rvert.$ $$

We denote $\kappa:=\lVert\phi^{\prime}\rVert_{\infty}$ for brevity. Clearly $\xi_{j,m,\ell}=0$ for $\ell<\mathsf{h}[m]$ and

$$ $\displaystyle\xi_{j,m,\mathsf{h}[m]}=\left\lvert\frac{\partial\hat{x}_{m}}{ \partial w_{j,m}}\right\rvert\leq\kappa\sigma_{j}(\bm{w}_{m})|x_{j}-\hat{z}_{m }|\leq 2\kappa\sigma_{j}(\bm{w}_{m}).$ $$

Moreover for any $\alpha$ with $\mathsf{h}[\alpha]=\ell>\mathsf{h}[m]$, we can bound by the chain rule

$$ $\displaystyle\left\lvert\frac{\partial\hat{x}_{\alpha}}{\partial w_{j,m}}\right\rvert$ $\displaystyle\leq|\phi^{\prime}(\hat{z}_{\alpha})|\cdot\left\lvert\sum_{\beta= d_{\mathsf{h}[m]}+1}^{d_{\ell-1}}\sigma_{\beta}(\bm{w}_{\alpha})\frac{\partial \hat{x}_{\beta}}{\partial w_{j,m}}\right\rvert\leq\kappa\xi_{j,m,\ell-1},$ $$

yielding the relation $\xi_{j,m,\ell}\leq\kappa\xi_{j,m,\ell-1}$. Iterating, we obtain that $\xi_{j,m,\ell}\leq 2\kappa^{\ell-\mathsf{h}[m]+1}\sigma_{j}(\bm{w}_{m})$. Therefore we can bound the total gradient by the following.

$$ $\displaystyle\sum_{\alpha=d+1}^{d+k-1}\lVert\nabla_{\mathbf{W}}f_{\alpha}^{ \times}\rVert^{2}$ $\displaystyle=\sum_{\ell=1}^{v}\sum_{\alpha=d_{\ell-1}+1}^{d_{\ell}}\lVert \nabla_{\mathbf{W}}f_{\alpha}^{\times}\rVert^{2}$ $\displaystyle=\sum_{\ell=1}^{v}\sum_{\alpha=d_{\ell-1}+1}^{d_{\ell}}\sum_{m=d+ 1}^{d+k-1}\sum_{j=1}^{m-1}\left\lvert\frac{\partial\hat{x}_{\alpha}}{\partial w _{j,m}}\right\rvert^{2}$ $\displaystyle\leq\sum_{m=d+1}^{d+k-1}\sum_{j=1}^{m-1}\sum_{\ell=1}^{v}(d_{\ell }-d_{\ell-1})\xi_{j,m,\ell}^{2}$ $\displaystyle\leq\sum_{m=d+1}^{d+k-1}\sum_{j=1}^{m-1}\sigma_{j}(\bm{w}_{m})^{2 }\sum_{\ell=1}^{v}2^{v-\ell}\cdot 4\kappa^{2\ell-2\mathsf{h}[m]+2}$ $\displaystyle\leq 4\sum_{m=d+1}^{d+k-1}2^{v}\kappa^{-2\mathsf{h}[m]+2}\sum_{ \ell=1}^{v}\left(\frac{\kappa^{2}}{2}\right)^{\ell}\leq\frac{4\kappa^{2}}{ \kappa^{2}-2}\sum_{m=d+1}^{d+k-1}\kappa^{2v-2\mathsf{h}[m]+2}$ $\displaystyle\leq\frac{4\kappa^{2}}{\kappa^{2}-2}\sum_{\ell=1}^{v}(d_{\ell}-d_ {\ell-1})\kappa^{2v-2\ell+2}=\frac{4\kappa^{4}}{\kappa^{2}-2}\sum_{\ell=1}^{v} (2\kappa^{2})^{v-\ell}$ $\displaystyle\leq\frac{4\kappa^{2}}{(\kappa^{2}-2)(2\kappa^{2}-1)}(2\kappa^{2} )^{v}=O(d^{2\log_{2}\kappa+1}),$ $$

since $2^{v}=k=O(d)$. ∎

We first provide a concentration bound for the augmented data, which we take to hold throughout the proof by conditioning on the high probability event.

###### Lemma 10 (concentration of augmented data) .

For $n^{\prime}=\operatorname{poly}(d)$, with probability $1-e^{-\Omega(\sqrt{d})}$ over random sampling of the augmented data $\bm{u}_{1},\cdots,\bm{u}_{d}$, it holds that $\lVert\bm{u}_{j}+\bm{1}_{n^{\prime}}\rVert_{\infty}=2$ for all $1\leq j\leq d+k-1$ and

$$ $\max_{0\leq\ell\leq v}\left\lVert\frac{1}{d_{\ell}}\sum_{j=1}^{d_{\ell}}\bm{x} _{j}^{+}\right\rVert_{\infty}\leq O(d^{-1/4}).$ $$

###### Proof.

The nodes $x_{d_{\ell-1}+1},\cdots,x_{d_{\ell}}$ at each level $\ell$ compute independent parities, even though parities at different levels can be correlated. By Hoeffding’s inequality and union bounding over coordinates, it follows that

$$ $\displaystyle\left\lVert\sum_{j=d_{\ell-1}+1}^{d_{\ell}}\bm{x}_{j}^{+}\right \rVert_{\infty}\leq\sqrt{2(d_{\ell}-d_{\ell-1})\log\frac{2n^{\prime}}{p}}=2^{ \frac{v-\ell+1}{2}}\sqrt{\log\frac{2n^{\prime}}{p}}$ $$

with probability at least $1-p$. Again union bounding, the above holds for all levels $0\leq\ell\leq v$ simultaneously with probability at least $1-vp$, so that

$$ $\displaystyle\left\lVert\frac{1}{d_{\ell}}\sum_{j=1}^{d_{\ell}}\bm{x}_{j}^{+} \right\rVert_{\infty}\leq\sum_{\ell^{\prime}=0}^{\ell}\frac{2^{\frac{v-\ell^{ \prime}+1}{2}}}{d}\sqrt{\log\frac{2n^{\prime}}{p}}\leq 2(\sqrt{2}+1)\sqrt{ \frac{1}{d}\log\frac{2n^{\prime}}{p}}=O(d^{-1/4})$ $$

for all $\ell$ if $p=e^{-\sqrt{d}}$. In addition, the probability that $\bm{u}_{j}=-\bm{1}_{n^{\prime}}$ for some $j\leq d+k-1$ is bounded by $2d\cdot 2^{-n^{\prime}}=e^{-\Omega(d)}$; otherwise, at least one entry is equal to $2$.
∎

Now to prove Theorem 7, we show by induction that with high probability, the weights can be written for constants $C_{\ell}=\Theta(1)$ as

$$ $w_{j,m}^{(t)}=\begin{cases}\mathsf{r}[C_{\mathsf{h}[m]}d^{\epsilon/16}]& \mathsf{h}[m]\leq t,\mathsf{p}[j]=m,\\ -\infty&j>d_{\mathsf{h}[m]-1}\text{ or }m\leq d,\\ 0&\text{otherwise}.\end{cases}$ (11) $$

Clearly (11) is satisfied when $t=0$. Suppose (11) holds at time $t-1$ for $t\geq 1$.

###### Lemma 10 (concentration of augmented data) .

###### Proof.

#### Evaluating the forward pass.

We first evaluate the forward pass iteration of the transformer up to level $\mathsf{h}[m]\leq t$; fixing $0<C<\min_{\ell\leq v}C_{\ell}$, it holds that

$$ $\sigma_{j}(\bm{w}_{m}^{(t)})\leq\frac{1}{\exp(w_{\mathsf{c}_{1}[m],m}^{(t)})+ \exp(w_{\mathsf{c}_{2}[m],m}^{(t)})+d_{\mathsf{h}[m]-1}-2}\leq\exp(-Cd^{ \epsilon/16})$ $$

when $\mathsf{p}[j]\neq m$ and

$$ $\frac{1-d\exp(-Cd^{\epsilon/16})}{2}\leq\sigma_{\mathsf{c}_{1}[m]}(\bm{w}_{m}^ {(t)}),\sigma_{\mathsf{c}_{2}[m]}(\bm{w}_{m}^{(t)})\leq\frac{1}{2}.$ $$

For the augmented tokens, define the increasing per-level error sequence

$$ $\epsilon_{\ell}=\max_{d<j\leq d_{\ell}}\left\lVert\hat{\bm{x}}_{j}^{+(t)}-\bm{ x}_{j}^{+}\right\rVert_{\infty},\quad\epsilon_{0}=0.$ $$

We recursively bound $\epsilon_{\ell}$ as before up to $\epsilon_{t}$; this will simultaneously verify that the filter $\iota$ is not applied for the first $t+1$ levels since $\lVert\bm{u}_{j}^{(t)}+\bm{1}_{n^{\prime}}\rVert_{\infty}\geq 2-\epsilon_{t}$ due to Lemma 10.

For each state $\hat{\bm{z}}_{m}^{+(t)}$ with $\mathsf{h}[m]=\ell$ we have

$$ $\displaystyle\left\lVert\hat{\bm{z}}_{m}^{+(t)}-\frac{\bm{x}_{\mathsf{c}_{1}[m ]}^{+}+\bm{x}_{\mathsf{c}_{2}[m]}^{+}}{2}\right\rVert_{\infty}$ $\displaystyle\leq\sum_{\mathsf{p}[j]\neq m}\sigma_{j}(\bm{w}_{m}^{(t)})+\left \lvert\sigma_{\mathsf{c}_{1}[m]}(\bm{w}_{m}^{(t)})-\frac{1}{2}\right\rvert+ \left\lvert\sigma_{\mathsf{c}_{2}[m]}(\bm{w}_{m}^{(t)})-\frac{1}{2}\right \rvert+\epsilon_{\ell-1}$ $\displaystyle\leq(2d-2)\exp(-Cd^{\epsilon/16})+\epsilon_{\ell-1}.$ $$

Since $\phi$ behaves like a quadratic near $0,\pm 1$, it follows that

$$ $\displaystyle\epsilon_{\ell}\leq C_{2}((2d-2)\exp(-Cd^{\epsilon/16})+\epsilon_ {\ell-1})^{2},$ $$

and we can inductively verify $\epsilon_{\ell}\leq\exp(-Cd^{\epsilon/16})$ as well as $\lVert\hat{\bm{z}}_{m}^{+(t)}-\bm{z}_{m}^{+}\rVert_{\infty}\leq 2d\exp(-Cd^{
\epsilon/16})$ holds for all $\ell\leq t$ for sufficiently large $d$.

On the other hand, for the forward pass for levels $\mathsf{h}[m]>t$ the softmax scores are uniform over $d_{\mathsf{h}[m]-1}$ tokens; moreover, the filter $\iota$ will be applied to all tokens on level $t+2$ and higher. Indeed, the output of nodes on level $\mathsf{h}[m]=t+1$ reads

$$ $\displaystyle\hat{\bm{x}}_{m}^{+(t)}=\phi(\hat{\bm{z}}_{m}^{+(t)}),\quad\hat{ \bm{z}}_{m}^{+(t)}=\frac{1}{d_{t}}(\hat{\bm{x}}_{1}^{+(t)}+\cdots+\hat{\bm{x}} _{d_{t}}^{+(t)})=\frac{1}{d_{t}}(\bm{x}_{1}^{+}+\cdots+\bm{x}_{d_{t}}^{+})+O( \epsilon_{\ell}),$ $$

so that $\lVert\hat{\bm{z}}_{m}^{+(t)}\rVert_{\infty}\leq O(d^{-1/4})$ by Lemma 10. Then

$$ $\lVert\hat{\bm{u}}_{m}^{(t)}+\bm{1}_{n^{\prime}}\rVert_{\infty}\leq C_{2} \lVert|\hat{\bm{z}}_{m}^{+(t)}|^{2}\rVert\leq O(d^{-1/2})$ $$

so that if $O(d^{-1/2})<\varepsilon_{0}$, the filter zeroes out the output of each node on level $t+2$. Then the intermediate states of nodes $x_{m^{\prime}}$ on level $t+2$ read

$$ $\displaystyle\hat{\bm{z}}_{m^{\prime}}^{+(t)}=\frac{1}{d_{t+1}}(\hat{\bm{x}}_{ 1}^{+(t)}+\cdots+\hat{\bm{x}}_{d_{t}}^{+(t)})=\frac{d_{t}}{d_{t+1}}\hat{\bm{z} }_{m}^{+(t)},$ $$

which again activates the filter. Repeating this process for the remaining levels, we conclude that $\lVert\hat{\bm{z}}_{m}^{+(t)}\rVert_{\infty}\leq O(d^{-1/4})$ and so $\lVert\hat{\bm{x}}_{m}^{+(t)}+\bm{1}_{n+n^{\prime}}\rVert_{\infty}\leq O(d^{-1
/2})$ holds simultaneously for all nodes $\mathsf{h}[m]>t$ (and all timesteps $t$ for which (11) is valid).

#### Evaluating the updates.

Define $\bar{\bm{z}}_{m}^{(t)}=\frac{1}{d_{t}}\sum_{j=1}^{d_{t}}\bm{x}_{j}$ so that

$$ $\lVert\hat{\bm{z}}_{m}^{(t)}-\bar{\bm{z}}_{m}^{(t)}\rVert_{\infty}\leq\frac{1} {d_{t}}\sum_{j=1}^{d_{t}}\lVert\hat{\bm{x}}_{j}^{(t)}-\bm{x}_{j}\rVert_{\infty }\leq\exp(-Cd^{\epsilon/16}).$ $$

We proceed to evaluate the gradient of $L$ at (11). For the weights $w_{j,m}$ with $\mathsf{h}[m]=t+1$, by isolating the errors from the forward pass we have

$$ $\displaystyle\frac{\partial}{\partial w_{j,m}}\left(\frac{1}{2n}\lVert\hat{\bm {x}}_{m}^{(t)}-\bm{x}_{m}\rVert^{2}\right)$ $\displaystyle=\frac{1}{n}\left\langle\phi(\hat{\bm{z}}_{m}^{(t)})-\bm{x}_{m}, \frac{\partial\phi(\hat{\bm{z}}_{m}^{(t)})}{\partial w_{j,m}}\right\rangle$ $\displaystyle=\frac{\sigma_{j}(\bm{w}_{m}^{(t)})}{n}\left\langle\phi(\hat{\bm{ z}}_{m}^{(t)})-\bm{x}_{m},\phi^{\prime}(\hat{\bm{z}}_{m}^{(t)}),\hat{\bm{x}}_{ j}^{(t)}-\hat{\bm{z}}_{m}^{(t)}\right\rangle$ $\displaystyle=\frac{1}{nd_{t}}\left\langle\phi(\bar{\bm{z}}_{m}^{(t)})-\bm{x}_ {m},\phi^{\prime}(\bar{\bm{z}}_{m}^{(t)}),\bm{x}_{j}-\bar{\bm{z}}_{m}^{(t)}\right\rangle$ $\displaystyle\qquad+O\left(\frac{4}{d_{t}}(1+\lVert\phi^{\prime}\rVert_{\infty }+\lVert\phi^{\prime\prime}\rVert_{\infty})\lVert\hat{\bm{z}}_{m}^{(t)}-\bar{ \bm{z}}_{m}^{(t)}\rVert_{\infty}\right)$ $\displaystyle=\frac{1}{nd_{t}}\left\langle\phi(\bar{\bm{z}}_{m}^{(t)})-\bm{x}_ {m},\phi^{\prime}(\bar{\bm{z}}_{m}^{(t)}),\bm{x}_{j}-\bar{\bm{z}}_{m}^{(t)} \right\rangle+O(\exp(-Cd^{\epsilon/16})).$ $$

Then the first term is identical to the initial gradient (6) analyzed in the proof of Theorem 5 except for the differences in indices, and from the same computation we obtain the leading term:

$$ $\displaystyle\frac{\partial}{\partial w_{j,m}}\left(\frac{1}{2n}\lVert\hat{\bm {x}}_{m}^{(t)}-\bm{x}_{m}\rVert^{2}\right)=-\frac{2c}{d_{t}^{2}}1_{\{\mathsf{p }[j]=m\}}+O(d^{-2-\epsilon/8}),$ $$

which holds with probability $1-\exp(-d^{\epsilon/2})$ if $n=\Omega(d^{2+\epsilon})$ under the same setting of Lemma 9.

For all other nodes on level $t+1$ or below, the output does not depend on the weight $w_{j,m}$, so the gradient of the squared error with respect to $w_{j,m}$ is zero. Moreover, all nodes on level $t+2$ or above are zeroed out due to the filter and hence also has zero gradient. Then the oracle error is absorbed into the second term and the update after time $t+1$ with learning rate fixed to $\eta=d^{2+\epsilon/16}\eta_{0}$ reads

$$ $\displaystyle w_{j,m}^{(t)}-\eta\widetilde{\nabla}_{w_{j,m}}L(\mathbf{W}^{(t)} )=2c\eta_{0}\frac{d^{2+\epsilon/16}}{d_{\mathsf{h}[m]-1}^{2}}1_{\{\mathsf{p}[j ]=m\}}+O(d^{-\epsilon/16}).$ $$

By choosing $\eta_{0}$ such that none of the leading terms lands exactly on a half-integer, we have that for sufficiently large $d$,

$$ $\displaystyle w_{\mathsf{c}_{1}[m],m}^{(t+1)}=w_{\mathsf{c}_{2}[m],m}^{(t+1)}= \mathsf{r}\left[2c\eta_{0}\frac{d^{2+\epsilon/16}}{d_{\mathsf{h}[m]-1}^{2}} \right],\quad w_{j,m}^{(t+1)}=\mathsf{r}[O(d^{-\epsilon/16})]=0$ $$

if $\mathsf{p}[j]\neq m$. We verify that

$$ $\displaystyle\frac{c\eta_{0}}{2}\leq C_{\ell}=2c\eta_{0}\frac{d^{2+\epsilon/16 }}{d_{\ell-1}^{2}}\leq 2c\eta_{0}.$ $$

Also, the weights $w_{j,m}$ such that $\mathsf{h}[m]\geq t+2$ only affect the nodes that are zeroed out, so that the gradient is also bounded as $O(d^{-\epsilon/16})$ and $w_{j,m}^{(t+1)}=0$.

It remains to evaluate the gradient signal of weights $w_{j,m}$ with $\mathsf{h}[m]\leq t$, which have already been updated in previous steps. Define the error

$$ $\displaystyle\xi_{j,m,\ell}:=\max_{1\leq\alpha\leq d_{\ell}}\left\lVert\frac{ \partial\hat{\bm{x}}_{\alpha}^{(t)}}{\partial w_{j,m}}\right\rVert_{\infty}.$ $$

This is similar to the error control in the proof of Lemma 6, but we exploit the fact that parities up to level $t$ are solved to obtain a much tighter bound. Let us expand $\phi^{\prime}(t)=2c^{\prime}(1-t)+O((1-t)^{2})$ near $1$ and $2c^{\prime}(-1-t)+O((1+t)^{2})$ near $-1$ for some positive constant $c^{\prime}$. Recall

$$ $\lVert\hat{\bm{z}}_{\alpha}^{+(t)}-\bm{z}_{\alpha}^{+}\rVert_{\infty}\leq 2d \exp(-Cd^{\epsilon/16}),\quad\mathsf{h}[\alpha]\leq t$ $$

holds in the forward pass, so each component $\hat{\bm{z}}_{\alpha,i}^{(t)}$ is $O(\exp(-Cd^{\epsilon/16}))$-close to either of $\pm 1$. It follows that $|\phi^{\prime}(\hat{\bm{z}}_{\alpha,i}^{(t)})|=O(\exp(-Cd^{\epsilon/16}))$, so we can bound

$$ $\displaystyle\xi_{j,m,\mathsf{h}[m]}=\left\lVert\frac{\partial\hat{\bm{x}}_{m} ^{(t)}}{\partial w_{j,m}}\right\rVert_{\infty}\leq 2\lVert\phi^{\prime}(\hat{ \bm{z}}_{m}^{(t)})\rVert_{\infty}\sigma_{j}(\bm{w}_{m})\leq O(\exp(-Cd^{ \epsilon/16})).$ $$

Moreover, for any $\alpha$ on level $\mathsf{h}[\alpha]=\ell$, $\mathsf{h}[m]<\ell\leq t$ the magnitude of the derivative of the output $\hat{\bm{x}}_{\alpha}^{(t)}$ can be bounded as

$$ $\displaystyle\left\lVert\frac{\partial\hat{\bm{x}}_{\alpha}^{(t)}}{\partial w_ {j,m}}\right\rVert_{\infty}$ $\displaystyle\leq\left\lVert\phi^{\prime}(\hat{\bm{z}}_{\alpha}^{(t)})\right \rVert_{\infty}\sum_{\beta=1}^{d_{\ell-1}}\sigma_{\beta}(\bm{w}_{\alpha}^{(t)} )\left\lVert\frac{\partial\hat{\bm{x}}_{\beta}^{(t)}}{\partial w_{j,m}}\right \rVert_{\infty}\leq O(\exp(-Cd^{\epsilon/16}))\xi_{j,m,\ell-1}.$ $$

This implies that $\xi_{j,m,t}=\xi_{j,m,t-1}=\cdots=\xi_{j,m,\mathsf{h}[m]}\leq O(\exp(-Cd^{
\epsilon/16}))$. Furthermore, for any $\alpha$ on level $\mathsf{h}[\alpha]=t+1$ it holds that

$$ $\displaystyle\left\lVert\frac{\partial\hat{\bm{x}}_{\alpha}^{(t)}}{\partial w_ {j,m}}\right\rVert_{\infty}$ $\displaystyle\leq\lVert\phi^{\prime}\rVert_{\infty}\sum_{\beta=1}^{d_{t}} \sigma_{\beta}(\bm{w}_{\alpha}^{(t)})\left\lVert\frac{\partial\hat{\bm{x}}_{ \beta}^{(t)}}{\partial w_{j,m}}\right\rVert_{\infty}\leq\lVert\phi^{\prime} \rVert_{\infty}\xi_{j,m,t}\leq O(\exp(-Cd^{\epsilon/16})).$ $$

Thus we have for all $\alpha$ with $\mathsf{h}[\alpha]\leq t+1$,

$$ $\displaystyle\frac{\partial}{\partial w_{j,m}}\left(\frac{1}{2n}\lVert\hat{\bm {x}}_{\alpha}^{(t)}-\bm{x}_{\alpha}\rVert^{2}\right)$ $\displaystyle=\frac{1}{n}\left\langle\hat{\bm{x}}_{\alpha}^{(t)}-\bm{x}_{ \alpha},\frac{\partial\hat{\bm{x}}_{\alpha}^{(t)}}{\partial w_{j,m}}\right \rangle\leq 2\left\lVert\frac{\partial\hat{\bm{x}}_{\alpha}^{(t)}}{\partial w_ {j,m}}\right\rVert_{\infty}=O(\exp(-Cd^{\epsilon/16})),$ $$

and the nodes on level $t+2$ or above are zeroed out due to the filter. Hence the gradient signal is exponentially small and

$$ $\displaystyle\widetilde{\nabla}_{w_{j,m}}L(\mathbf{W}^{(t)})=O(d\exp(-Cd^{ \epsilon/16}))+O(d^{-2-\epsilon/8}),$ $$

so that $w_{j,m}^{(t+1)}=\mathsf{r}[w_{j,m}^{(t)}+O(d^{-\epsilon/16})]=w_{j,m}^{(t)}$. This concludes the proof of (11).

Finally, after time $t=v$ the weights at all levels have been updated, so that repeating the analysis of the forward pass yields that

$$ $\lVert\hat{\bm{y}}_{\operatorname{test}}-\bm{y}_{\operatorname{test}}\rVert_{ \infty}=\left\lVert\hat{\bm{x}}_{d+k-1}^{(t)}-\bm{x}_{d+k-1}\right\rVert_{ \infty}\leq\epsilon_{v}\leq\exp(-Cd^{\epsilon/16}),$ $$

as was to be shown. ∎

## Peer Reviews

confidence: 3
contribution: 4
initial_rating: 8
presentation: 4
questions: I did not came up with any useful and educated questions. I believe the paper is of high quality and will need to study it in more depth.
soundness: 4
strengths: I find the work to be of very high quality and very relevant to the current research in reasoning abilities of language model. The theoretical setup is in my opinion well chosen, very concise and easy to understand.  Even though this is a theoretical paper, the authors are well aware of the current research on the applied side and the questions studied reflect it. I believe it is a strong accept, but I'm giving accept because I'm not sure whether theoretical results of this kind should have spotlight talks at ICLR.
summary: The paper provides a theoretical foundations which explain the benefits of chain-of-though. The authors study a simple setup of k-parity problem with 1-layer Transformer and in this case provide a separation results for transformer trained without intermediate supervision and one trained with teacher forcing. They also provide positive results for the case where the transformer can generate chain-of-thought but is not explicitly supervised with the intermediate results. They show conditions which are required in this case (data augmentation and self-consistency checking).
weaknesses: I was not able to judge how limiting is the setup described in the paper overall, but for example the special masking seems quite artificial but I understand that it is required for the theoretical results. It would be nice if the authors explicitly describe the limitations they are aware of.

---

confidence: 3
contribution: 3
initial_rating: 8
presentation: 3
questions: 1. For the k-parity problem, each layer’s intermediate state corresponds to a simple “2-parity” check, which is straightforward to define. In more complex tasks, however, defining such intermediate states may not be as intuitive. How could this approach be extended to real-world reasoning tasks where intermediate state decomposition is less clear?
2. The paper uses data augmentation to validate intermediate states in the reasoning process. If applied to practical reasoning tasks, would this data augmentation method require significant adjustments to be effective?
3. Given the proposed architecture, are there potential challenges that might arise in real-world training, particularly concerning stability and computational complexity?
soundness: 3
strengths: 1. The paper innovatively uses the k-parity problem to theoretically analyze how transformers develop stepwise reasoning capabilities.
2. This paper introduces a novel hierarchical decomposition of the k-parity problem and designs a corresponding transformer architecture to handle this structure effectively.
3. This paper proposes mechanisms like data augmentation and self-consistency checks, enabling transformers to perform CoT reasoning even in the absence of explicit intermediate supervision.
4. The paper provides clear and logically rigorous analysis for the k-parity problem, offering strong, well-structured insights within this specific context.
summary: This paper provides a theoretical exploration of how transformers develop stepwise reasoning capabilities through recursive task decomposition, using the k-parity problem as a case study. Through formal mathematical proofs and asymptotic complexity analysis, the authors establish three key findings: without intermediate supervision, solving k-parity with finite-precision gradient-based algorithms requires exponentially many steps, extending prior impossibility results to finite-sample settings. In contrast, with teacher forcing—where ground-truth intermediate steps are provided—the model efficiently learns the task in a single gradient update, underscoring the value of explicit supervision for complex reasoning. Additionally, even without teacher forcing, the model achieves accurate reasoning by employing data augmentation to validate intermediate steps, implementing a form of self-consistency check that allows for logarithmic convergence. This research emphasizes theoretical analysis through mathematical proofs and complexity analysis, offering insights into how transformers can perform chain-of-thought reasoning and task decomposition, thereby aligning with recent empirical advances in complex reasoning tasks.
weaknesses: 1. The theoretical analysis is heavily focused on the k-parity problem, which, while illustrative, may not extend seamlessly to more complex or varied reasoning tasks. This limits the applicability of the findings to broader transformer applications.
2. The paper lacks empirical experiments to support the theoretical conclusions, which could leave readers questioning the practical effectiveness of the proposed methods in real-world scenarios or on diverse datasets.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 4
questions: Q1. Is there any particular reason why one-layer transformer has been chosen? Would the same results (or even stronger) apply to 2 layer transformer?

Q2. Could we apply the same idea to less structured task which lack the hierarchical structure, hence the "easier" teaching forcing?
soundness: 4
strengths: S1. The study is very rigorous, sharing some lights on the importance of CoT on multi hop reasoning. 

S2. The introduction of the causal mask is indeed very simple to explain and very intuitive, but also very effective to limit the error compounding. I think this is the main contribution, given teaching forcing is not really useful on this problem.

S3. This work extended previous related work on more realistic setting, offering a clearer picture of why CoT is indeed essential for the given problem.
summary: Authors showed that CoT here is beneficial to learn a very hard problem, i.e. bit subset parity. Authors trained a one-layer transformer with a fixed CoT and with a tree based approach to determine the subset and they showed that without CoT it's not possible to learn an algorithm to detect the right bit, _assuming_ data cannot be manipulated freely. They introduced a causal mask to allow less error propagation during CoT.
weaknesses: W1. Main weakness is a lack of empirical validation. I would love to see just a trained model on various settings (like with and without teacher forcing, parity problem sizes with different $k$ and $d$ values) to show that without teaching forcing the model is indeed able to learn the task. 

W2. The claim on the conclusion about finetuning transformer to improve multi step reasoning seems really too strong. In particular, it would be nice to show that it's easy to produce CoT data for all reasoning tasks before claiming this. So I would rephrase that sentence or provide a more detailed discussion on why authors believe their results may extend to other reasoning tasks.

Meta-review: The submission studies a simple setup of k-parity problem with 1-layer Transformer and provides a separation results for transformer trained without intermediate supervision and one trained with teacher forcing, thereby showing the importance of chain-of-thought.

+ The paper is clearly written.
+ The analysis is thorough.

- Initially, there were some concerns about the lack of empirical evaluation.

Decision: Accept (Oral)