\documentclass[11pt]{amsart} \pdfsuppressptexinfo=-1 \usepackage[margin=1.1in]{geometry} \usepackage{amsmath,amssymb,amsthm,mathtools} \usepackage{booktabs,enumitem,array} \usepackage[hidelinks]{hyperref} \hypersetup{pdftitle={A matching threshold of 2e-3 for the rotated surface code under circuit-level noise},pdfauthor={Tejasvi Singh Tomar}} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{corollary}[theorem]{Corollary} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \numberwithin{equation}{section} \setlength{\emergencystretch}{2em} \newcommand{\Pfail}{P_{\mathrm{fail}}} \newcommand{\pst}{p_\ast} \newcommand{\dX}{\delta^{X}} \newcommand{\dZ}{\delta^{Z}} \newcommand{\cD}{\mathcal{D}} \newcommand{\cF}{\mathcal{F}} \newcommand{\ver}{\textsuperscript{\dag}} \begin{document} \title[Matching threshold for the rotated surface code]{A matching threshold of $2\times10^{-3}$ for the rotated surface code under circuit-level noise} \author{Tejasvi Singh Tomar} \renewcommand{\urladdrname}{{\itshape ORCID}} \urladdr{\href{https://orcid.org/0000-0003-4668-3639}{https://orcid.org/0000-0003-4668-3639}} \date{20 October 2026} \subjclass[2020]{81P73; 94B35, 05C38, 68V05} \keywords{Quantum error correction, surface code, fault tolerance, threshold, minimum-weight perfect matching, circuit-level noise, computer-assisted proof} \begin{abstract} We consider the rotated surface code of odd distance $d$ with its standard syndrome-extraction circuit, under circuit-level depolarizing noise in which every gate, idle step, preparation and measurement fails independently with probability $p$, decoded by minimum-weight perfect matching with the log-likelihood weights of single faults. We prove that a memory experiment with $T$ rounds fails with probability at most $0.061\,(T+1)(d+1)\,\lambda^{d}/(1-\lambda)$, where $\lambda=0.999\,(p/p_{\ast\ast})^{9/25}$, for every $p\le p_{\ast\ast}=2\times10^{-3}$. Hence the logical error rate per round decays exponentially in $d$ for all $p\le p_{\ast\ast}$. Earlier rigorous thresholds for matching on surface-code circuits are $1.7\times10^{-4}$, due to Dennis, Kitaev, Landahl and Preskill, and $7.4\times10^{-4}$, due to Fowler. We keep their reduction of a failure to a weighted self-avoiding path in the decoding graph, but bound these paths by a local criterion for non-backtracking walks, which gives the threshold $1.04\times10^{-3}$ in closed form. To reach $2\times10^{-3}$ we use the minimality of the correction along the path, for a canonical choice among the minimum-weight corrections: labellings of short stretches of the path into error and correction edges that contradict this minimality are excluded, and the remaining labelled walks are counted with a potential function that is checked in exact arithmetic. For a leaner schedule with fused measure-and-reset steps the two arguments give $1.53\times10^{-3}$ and $3\times10^{-3}$, respectively. With error rates that depend on the type of operation, they certify exponential decay for error models built from the published component error rates of Quantinuum's Helios and H2 and of IBM's Heron~r3 processor ibm\_boston, mapped onto this circuit. All theorems are also proved in the proof assistant Lean~4, with all computations checked by its kernel. Any argument that bounds the failure probability by the probability of an increasing event, ours included, is limited by the smallest such event that contains all failures, and Monte Carlo estimates place the threshold of this event near $4\times10^{-3}$ for this circuit. \end{abstract} \maketitle \section{Setting and result}\label{sec:setting} The rotated surface code decoded by minimum-weight perfect matching is a standard model of a fault-tolerant quantum memory. Under circuit-level noise, simulations place its threshold near $0.5$--$1\%$ \cite{WFH11,FMMC12}, and for the circuit considered here the logical failure curves cross near $5\times10^{-3}$ (Remark~\ref{rem:numerical}). But rigorous thresholds are much smaller. The path argument of Dennis, Kitaev, Landahl and Preskill \cite{DKLP02} gives $1.7\times10^{-4}$, and Fowler's refinement \cite{Fow12} reaches $7.4\times10^{-4}$, each for its own circuit and noise model. For the standard syndrome-extraction circuit we prove $1.04\times10^{-3}$ in closed form and $2\times10^{-3}$ with a computer-verified certificate, by a local criterion for weighted non-backtracking walks and by the minimality of the correction along the failure path. All theorems are also proved in the proof assistant Lean~4, with all computations checked by its kernel (Section~\ref{sec:lean4}). \subsection{Code and circuit}\label{sec:circuit} Fix an odd distance $d\ge3$. The data qubits sit at the points of \[ \cD=\{(x,y): x,y\in\{1,3,\dots,2d-1\}\}. \] A point $m=(x,y)$ with $x,y\in\{0,2,\dots,2d\}$ has the diagonal neighbourhood $N(m)=\{m+(\pm1,\pm1)\}\cap\cD$. It has \emph{X type} if $x/2+y/2$ is odd and \emph{Z type} otherwise. The measure qubits are the points $m$ with $|N(m)|\ge2$, excluding X-type points with $x\in\{0,2d\}$ and Z-type points with $y\in\{0,2d\}$. There are $d^2-1$ of them. An X-type (Z-type) measure qubit $m$ measures the stabilizer $\prod_{q\in N(m)}X_q$ ($\prod_{q\in N(m)}Z_q$). Write \[ \dX=\bigl((1,1),(-1,1),(1,-1),(-1,-1)\bigr),\qquad \dZ=\bigl((1,1),(1,-1),(-1,1),(-1,-1)\bigr). \] One round of syndrome extraction consists of eight steps. \begin{enumerate}[label=\textup{(S\arabic*)},leftmargin=3em] \item Reset every measure qubit to $|0\rangle$. \item Apply $H$ to every X-type measure qubit. \item[(S3--S6)] In step $2+k$, $k=1,\dots,4$, apply $\mathrm{CX}(m\to m+\dX_k)$ for each X-type $m$ with $m+\dX_k\in\cD$, and $\mathrm{CX}(m+\dZ_k\to m)$ for each Z-type $m$ with $m+\dZ_k\in\cD$. \setcounter{enumi}{6} \item Apply $H$ to every X-type measure qubit. \item Measure every measure qubit in the $Z$ basis. \end{enumerate} Each qubit takes part in at most one operation per step. The layout and the four CX layers coincide with those of the circuits \texttt{surface\_code:rotated\_memory\_x/z} generated by Stim \cite{Gid21}. The orders $\dX$ and $\dZ$ are the standard ones that orient hook errors perpendicular to the logical operator they could shorten \cite{TS14,FMMC12}. In the \emph{memory experiment in basis $Z$}, every data qubit is prepared in $|0\rangle$ in step (S1) of round $0$. Rounds $0,\dots,T-1$ follow, for some $T\ge1$, and then all data qubits are measured in the $Z$ basis. Let $s_{m,r}$ be the outcome of $m$ in round $r$ and $f_q$ the final outcome of $q$. For every Z-type $m$ the \emph{detectors} are \[ D_{m,0}=s_{m,0},\qquad D_{m,r}=s_{m,r}\oplus s_{m,r-1}\ (1\le r\le T-1),\qquad D_{m,T}=s_{m,T-1}\oplus\bigoplus_{q\in N(m)}f_q . \] We call $r$ the \emph{layer} of $D_{m,r}$. The logical outcome is $\bigoplus_{q\in\cD,\,y(q)=1}f_q$, the value of $Z_L$ on the bottom row. The experiment in basis $X$ is the same with $|+\rangle$, $X$-basis final measurements, X-type detectors and $X_L$ on the left column $x(q)=1$. Without noise all detectors and the logical outcome equal $0$ (Table~\ref{tab:verify}, V1). \subsection{Noise}\label{sec:noise} A \emph{location} is one of the following. Each location fails independently with probability $p$. \begin{itemize}[leftmargin=2em] \item A reset or preparation. A failed reset to $|0\rangle$ (preparation of $|+\rangle$) is followed by $X$ (by $Z$). \item A measurement. A failed measurement reports the flipped outcome. \item An $H$ gate, or a qubit that is idle during a step. Failure is followed by $X$, $Y$ or $Z$, each with probability $1/3$. \item A CX gate. Failure is followed by one of the $15$ non-identity two-qubit Paulis, each with probability $1/15$. \end{itemize} A qubit is idle in a step if no reset, gate or measurement acts on it. Thus data qubits are idle in steps (S1) (except in round $0$), (S2), (S7), (S8) and in each of (S3)--(S6) in which they have no CX partner. Z-type measure qubits are idle in (S2) and (S7) and in the CX steps without a partner, while X-type measure qubits are idle in the CX steps without a partner. A \emph{fault outcome} is a location together with the Pauli or flip that follows its failure. Its probability is $p\,\pi(f)$ with $\pi(f)\in\{1,\tfrac13,\tfrac1{15}\}$. \subsection{Decoding graph and decoder}\label{sec:decoder} We describe basis $Z$. Basis $X$ is the same with the roles of the two types exchanged. Let $V$ be the set of detectors $D_{m,r}$. The \emph{signature} $\sigma(f)\subseteq V$ of a fault outcome $f$ is the set of detectors that change when $f$ is the only failure, and $\ell(f)\in\{0,1\}$ records whether the logical outcome changes. By Lemma~\ref{lem:graphlike}, $|\sigma(f)|\le2$, and $\ell(f)$ depends only on $\sigma(f)$. The \emph{decoding graph} $G$ has vertex set $V\cup\{b_1,b_2\}$ and one edge $e(f)$ for each nonempty signature: $e(f)=\sigma(f)$ if $|\sigma(f)|=2$, and $e(f)=\{u,b_1\}$ or $\{u,b_2\}$ if $\sigma(f)=\{u\}$ and $\ell(f)=1$ or $\ell(f)=0$, respectively. For an edge $e$ put \[ c_e=\sum_{f:\,e(f)=e}\pi(f),\qquad q_e=c_e\,p . \] The weights are $w_e=\log\bigl((1-r_e)/r_e\bigr)$ for numbers $r_e$ with $q_e(1-q_e)\le r_e\le q_e$. Two choices are common: $r_e=q_e$, and $r_e$ equal to the probability that an odd number of outcomes with $e(f)=e$ occur. The second lies in this range by the Bonferroni inequality. For a location $\ell$ let $c_{\ell,e}$ be the sum of $\pi(f)$ over the outcomes $f$ of $\ell$ with $e(f)=e$. We call the multiset of the nonzero numbers $c_{\ell,e}$, over all locations $\ell$, the \emph{profile} of $e$. Because the outcomes of a location exclude each other, the second choice equals $\bigl(1-\prod_\ell(1-2c_{\ell,e}p)\bigr)/2$. Thus both choices depend only on $p$ and on the profile of $e$. We call weights as above \emph{profile weights} if $r_e=\psi(p,\text{profile of }e)$ for one function $\psi$. For $p\le2\times10^{-3}$ each $q_e$ is at most $\tfrac{154}{15}\cdot2\times10^{-3}<0.021$ (Lemma~\ref{lem:graphlike}), so all weights are positive. For a set $C$ of edges let $\partial C\subseteq V$ be the set of detectors of odd degree in $C$. Given the set $\mathcal A\subseteq V$ of detectors that equal $1$, the decoder returns a set $C$ of minimum weight with $\partial C=\mathcal A$, and it predicts that the logical outcome was flipped if and only if $|C\cap\delta(b_1)|$ is odd, where $\delta(b_1)$ is the set of edges at $b_1$. A minimum-weight perfect matching of $\mathcal A$, with boundary copies and shortest-path distances, yields such a set as the symmetric difference of its paths. We prove the results below for every minimizer $C$. The decoder \emph{fails} if its prediction differs from the actual flip of the logical outcome. \subsection{Result} \begin{theorem}\label{thm:main} Let $d\ge3$ be odd, $T\ge1$, $B\in\{X,Z\}$ and $0{\raggedright\arraybackslash}p{0.66\textwidth}r@{}} \toprule edge & contributing outcomes (units of $p/15$) & $15c_e$\\ \midrule $(0,0,\pm1)$ & reset flip $15$; idle in (S2) $10$; each of the $4$ CX: $(I/Z,X/Y)$ on (data, $m$) $4$; idle in (S7) $10$; measurement flip $15$ & $66$\\ $\pm(2,2,0)$ & kind A, $q$: CX in (S6) of round $r-1$, $(X/Y,I/Z)$ $4$; idles in (S7), (S8), (S1), (S2) $4\times10$; CX in (S3), $(X/Y,X/Y)$ $4$ & $48$\\ $\pm(2,-2,0)$ & kind B, $q$: CX in (S5) of round $r-1$, $(X/Y,I/Z)$ $4$; X-type $q+(1,1)$ in (S5) of round $r-1$, $(X/Y,I/Z)$ $4$; its CX onto $q$ in (S6), $X/Y$ on $q$ $8$; idles $4\times10$; X-type $q-(1,1)$: CX onto $q$ in (S3), $(I/Z,X/Y)$ and $(X/Y,I/Z)$ $8$, its CX in (S4), $(X/Y,X/Y)$ $4$; CX $q\to q+(-1,1)$ in (S4), $(X/Y,X/Y)$ $4$ & $72$\\ $\pm(2,2,-1)$ & kind A, $q$ between (S3) and (S6): CX in (S3) $(X/Y,I/Z)$ $4$; CX onto $q$ in (S4) and (S5), $(I/Z,X/Y)$ $4+4$; CX in (S6) $(X/Y,X/Y)$ $4$ & $16$\\ $\pm(2,-2,-1)$ & kind B, $q$ between (S4) and (S5): CX in (S4) $(X/Y,I/Z)$ $4$; CX in (S5) $(X/Y,X/Y)$ $4$ & $8$\\ $\pm(4,0,-1)$ & X-type $m'$ after (S4): its CX in (S4) $(X/Y,I/Z)$ $4$; its CX in (S5) $(X/Y,X/Y)$ $4$ & $8$\\ \bottomrule \end{tabular} \caption{Outcomes producing the twelve edges at a bulk detector (basis $Z$, Lemma~\ref{lem:bulk}). The kind-A and kind-B qubits are the data qubits shared by the two ends of the edge.} \label{tab:bulk} \end{table} \subsection{Locality and node types} The \emph{type} of a detector $v\in V$ is the multiset of pairs (offset of the other end, $c_e$) over the edges $e$ at $v$, where an edge to $b_1$ or $b_2$ is recorded with the label $b_1$ or $b_2$ in place of the offset. \begin{lemma}\label{lem:locality} Let $v=D_{m,r}$. \begin{enumerate}[label=\textup{(\alph*)}] \item If $v\in\sigma(f)$, then $f$ acts on a qubit at $\ell^\infty$-distance at most $2$ from $m$, in round $r-1$ or $r$ \textup{(}in round $T-1$ or in the final measurement if $r=T$\textup{)}. \item The type of $v$ is determined by the positions of the qubits at $\ell^\infty$-distance at most $6$ from $m$ and the X or Z types of the measure qubits among them, by $\min(r,2)$ and by $\min(T-r,2)$. \item For all odd $d\ge3$ and all $T\ge1$, every detector of $G_{d,T}$ has the type of a detector of $G_{d',T'}$ for some $d'\in\{3,5,7,9\}$ and $T'\in\{1,\dots,5\}$. The same reduction applies to the statements of Lemma~\ref{lem:graphlike}. \end{enumerate} \end{lemma} \begin{proof} (a) We use the propagation rules from the proof of Lemma~\ref{lem:bulk}. In basis $Z$ only $X$ components matter, and basis $X$ is the same with $Z$ components and the roles of the two types of measure qubits exchanged. An $X$ on a data qubit $q$ is copied by the gate $\mathrm{CX}(q\to m')$ onto each Z-type measure qubit $m'$ with $q\in N(m')$, where it flips the outcome of $m'$ and is removed by the next reset of $m'$. It is copied nowhere else, because $q$ is the target of its CX gates with X-type measure qubits. An $X$ on a Z-type measure qubit flips its outcome and is removed by the next reset, whereas an $X$ on an X-type measure qubit $m'$ is copied onto the data qubits of $N(m')$ that $m'$ meets later in the same round. The latter does not change the outcome of $m'$, and it is removed by the next reset. Hence the propagated $X$ part of a single-qubit outcome lies, on data qubits, within distance $1$ of the faulty qubit, and the detectors it flips lie within distance $2$ of it. A two-qubit outcome is the product of its two factors, and detector values are linear in the Pauli frame. In time, a measure qubit is reset at the start of each round, and a data error that is present from round $\rho$ on changes $s_{m',\rho'}$ for all $\rho'\ge\rho$ or for all $\rho'\ge\rho+1$, so it flips layers $\rho$ and $\rho+1$ only. The final layer compares the last round with the data measurement, which sees the same error. (b) By (a), the outcomes with $v$ in their signature act within distance $2$ of $m$, so their CX partners lie within distance $3$. By the rules in (a), the signature and the logical effect of such an outcome in round $\rho$ are determined by the steps at which CX gates act, in rounds $\rho$ and $\rho+1$, on its qubits, on the data qubits within distance $1$ of them and on the measure qubits adjacent to those. Hence all of these qubits lie within distance $5$ of $m$. Which gates act on a qubit, and in which step, depends only on which of its diagonal neighbours exist, and these lie within distance $6$ of $m$. Whether round $r-1$ is round $0$, and whether layer $r$ or $r+1$ is the final one, is recorded by $\min(r,2)$ and $\min(T-r,2)$. (c) The bulk pattern of qubit positions and measure-qubit types is invariant under the lattice generated by $(4,0)$, $(0,4)$ and $(2,2)$, and the measure qubits of each of the two types form a single coset of it. Along the side $y=0$ the X-type measure qubits sit at $x\equiv2\pmod4$, along $y=2d$ at $x\equiv0$, along $x=0$ the Z-type ones sit at $y\equiv0$ and along $x=2d$ at $y\equiv2\pmod 4$. For odd $d$ this pattern, measured from the nearest corner, does not depend on $d$. Hence, for a detector in a given basis, the configuration within distance $6$ of $m$ is determined by the distances from $m$ to the four sides, truncated at $7$. If $d\ge9$, each quadruple of truncated distances that occurs in $G_{d,T}$ also occurs in $G_{9,T}$. Indeed, the range $[7,11]$ of coordinates at distance at least $7$ from both opposite sides of $G_9$ contains the even coordinates $8$ and $10$, one of each residue modulo $4$, so the parity condition that makes $m$ X-type or Z-type can be met there. Likewise, for $T\ge5$ the layer data $(\min(r,2),\min(T-r,2))$ of all layers occur for $T'=5$. Part (b) then implies the claim for the types of detectors. The statements of Lemma~\ref{lem:graphlike} concern single outcomes, edges and the neighbours of $b_1$, and they reduce in the same way. For the logical effect, after round $\rho+1$ the propagated frame of an outcome in round $\rho$ no longer changes on the data qubits, so $\ell(f)$ is the parity of its $X$ part on the bottom row at that time, which is again determined locally. An outcome with empty signature is handled in the same way, with the configuration around the outcome in place of the configuration around a detector. Finally, the number of neighbours of $b_1$ is a sum over detectors. By the types, a detector is adjacent to $b_1$ exactly when it has height $2$, and each layer has $(d+1)/2$ detectors of height $2$. \end{proof} \begin{corollary}[\ver]\label{cor:types} In each basis the detectors of all graphs $G_{d,T}$, $d\ge3$ odd and $T\ge1$, have exactly $29$ types. They are listed in Appendix~\ref{app:types}. \end{corollary} \section{From matching failure to weighted paths}\label{sec:paths} Fix an experiment and let $\cF$ be the set of fault outcomes that occur. At most one outcome occurs per location. Let $E$ be the set of edges $e$ such that the number of $f\in\cF$ with $e(f)=e$ is odd. Since detector values are linear in the Pauli frame, the set of detectors equal to $1$ is $\partial E$. The logical outcome is linear in the Pauli frame as well, and by Lemma~\ref{lem:graphlike}(b) an outcome flips it if and only if its edge ends at $b_1$. Therefore the logical outcome flips if and only if $|E\cap\delta(b_1)|$ is odd. \begin{lemma}\label{lem:path} If the decoder fails with the minimizer $C$, then $E\triangle C$ contains a simple path from $b_1$ to $b_2$. \end{lemma} \begin{proof} Let $R=E\triangle C$. Since $\partial C=\partial E$, each detector has even degree in $R$. Failure means that $|C\cap\delta(b_1)|$ and $|E\cap\delta(b_1)|$ have different parity, so $b_1$ has odd degree in $R$. As the degrees in $R$ sum to $2|R|$, the vertex $b_2$ has odd degree as well. In each connected component of $(V\cup\{b_1,b_2\},R)$ the number of odd-degree vertices is even. Hence $b_1$ and $b_2$ lie in the same component, and that component contains a simple path between them. \end{proof} \begin{lemma}\label{lem:length} Every simple path from $b_1$ to $b_2$ in $G_{d,T}$ has at least $d$ edges. \end{lemma} \begin{proof} By Lemma~\ref{lem:graphlike}(c,d), the path enters $V$ at height $2$, leaves it from height $2d-2$, and each of its edges inside $V$ changes the height by at most $2$. Thus it has at least $(2d-4)/2=d-2$ edges inside $V$, and two edges at the boundary vertices. \end{proof} \begin{lemma}\label{lem:half} Let $\gamma\subseteq E\triangle C$ be a simple path from $b_1$ to $b_2$. Then $w(\gamma\cap E)\ge w(\gamma)/2$. \end{lemma} \begin{proof} We follow the argument of \cite[Sec.~4]{DKLP02}. Because the detector boundary of $\gamma$ is empty, $C\triangle\gamma$ is also a valid output, and $w(C)\le w(C\triangle\gamma)=w(C)-w(C\cap\gamma)+w(\gamma\setminus C)$. Since $\gamma\subseteq E\triangle C$, we have $\gamma\setminus C=\gamma\cap E$ and $w(C\cap\gamma)=w(\gamma)-w(\gamma\cap E)$. \end{proof} \begin{lemma}\label{lem:prob} For every set $S$ of edges, $\Pr(S\subseteq E)\le\prod_{e\in S}q_e$. \end{lemma} \begin{proof} If $S\subseteq E$, then for each $e\in S$ some $f_e\in\cF$ has $e(f_e)=e$. The $f_e$ are distinct, because each outcome has one edge. Two distinct outcomes at the same location never occur together, while outcomes at distinct locations are independent. Hence \[ \Pr(S\subseteq E)\le\sum_{(f_e)_{e\in S}}\Pr(f_e\in\cF\ \forall e)\le\sum_{(f_e)_{e\in S}}\ \prod_{e\in S}p\,\pi(f_e)=\prod_{e\in S}q_e.\qedhere \] \end{proof} \begin{lemma}\label{lem:tilt} Put $a_e=2\sqrt{q_e/(1-q_e)}$. For every path $\gamma$, \[ \sum_{S\subseteq\gamma,\ w(S)\ge w(\gamma)/2}\ \prod_{e\in S}q_e\ \le\ \prod_{e\in\gamma}a_e . \] \end{lemma} \begin{proof} Each term on the left satisfies $w(S)-w(\gamma\setminus S)\ge0$, so it is at most $\prod_{e\in S}q_e\,e^{(w(S)-w(\gamma\setminus S))/2}$. Summing this over all $S\subseteq\gamma$, we obtain $\prod_{e\in\gamma}\bigl(q_e e^{w_e/2}+e^{-w_e/2}\bigr)$. With $e^{w_e}=(1-r_e)/r_e$ and $q_e(1-q_e)\le r_e\le q_e$ we get \[ q_e\sqrt{\frac{1-r_e}{r_e}}\le\frac{q_e}{\sqrt{q_e(1-q_e)}}=\sqrt{\frac{q_e}{1-q_e}},\qquad \sqrt{\frac{r_e}{1-r_e}}\le\sqrt{\frac{q_e}{1-q_e}}, \] so each factor is at most $a_e$. \end{proof} \begin{proposition}\label{prop:sum} Let $\Gamma$ be the set of simple paths from $b_1$ to $b_2$ in $G_{d,T}$. Then $\Pfail\le\sum_{\gamma\in\Gamma}\prod_{e\in\gamma}a_e$. \end{proposition} \begin{proof} By Lemmas~\ref{lem:path} and~\ref{lem:half}, failure implies that some $\gamma\in\Gamma$ and $S=\gamma\cap E$ satisfy $S\subseteq E$ and $w(S)\ge w(\gamma)/2$. We apply the union bound over $\gamma$ and $S$, then Lemmas~\ref{lem:prob} and~\ref{lem:tilt}. \end{proof} \section{A local criterion for non-backtracking walks}\label{sec:criterion} \begin{lemma}\label{lem:criterion} Let $G$ be a finite graph with vertex set $V\cup\{b_1,b_2\}$, without an edge between $b_1$ and $b_2$, and let $a_e>0$ for each edge $e$. Let $\lambda>0$ and suppose that \[ \Sigma(v):=\sum_{e\ni v}\frac{a_e}{\lambda+a_e}\le1\qquad\text{for every }v\in V, \] where the sum includes edges to $b_1$ and $b_2$. Put $\kappa=\lambda+\max_{e\ni b_2}a_e$ and $\Sigma(b_1)=\sum_{e\ni b_1}a_e/(\lambda+a_e)$. Then for every $L\ge2$ the simple paths from $b_1$ to $b_2$ with $L$ edges satisfy \[ \sum_{\gamma}\ \prod_{e\in\gamma}a_e\ \le\ \kappa\,\Sigma(b_1)\,\lambda^{L-1}. \] \end{lemma} \begin{proof} For an oriented edge $\varepsilon=(u\to v)$ put $h(\varepsilon)=1/(\lambda+a_\varepsilon)$. For $m\ge1$ and an oriented edge $(x_0\to x_1)$ with $x_0\in V\cup\{b_1\}$ and $x_1\in V$, let $W_m(x_0\to x_1)$ be the sum of $\prod_{i=1}^{m}a_{x_ix_{i+1}}$ over all walks $x_1,x_2,\dots,x_{m+1}$ with $x_{m+1}=b_2$, $x_2,\dots,x_m\in V$, consecutive vertices adjacent and $x_{i+1}\ne x_{i-1}$ for $1\le i\le m$. We show by induction on $m$ that \begin{equation}\label{eq:induction} W_m(x_0\to x_1)\le\kappa\,\lambda^{m}\,h(x_0\to x_1). \end{equation} Because the edge $\{x_0,x_1\}$ contributes $a_{x_0x_1}/(\lambda+a_{x_0x_1})$ to $\Sigma(x_1)$, the hypothesis implies \begin{equation}\label{eq:local} \sum_{e\ni x_1,\ e\ne\{x_0,x_1\}}\frac{a_e}{\lambda+a_e}\le1-\frac{a_{x_0x_1}}{\lambda+a_{x_0x_1}}=\lambda\,h(x_0\to x_1). \end{equation} For $m=1$, $W_1(x_0\to x_1)=a_{x_1b_2}$ if $x_1$ is adjacent to $b_2$ and $0$ otherwise. Since $a_{x_1b_2}=(\lambda+a_{x_1b_2})\cdot a_{x_1b_2}/(\lambda+a_{x_1b_2})\le\kappa\,a_{x_1b_2}/(\lambda+a_{x_1b_2})$, \eqref{eq:induction} follows from \eqref{eq:local}. For $m\ge2$, \[ W_m(x_0\to x_1)=\sum_{\substack{x_2\in V\setminus\{x_0\}\\ x_2\sim x_1}}a_{x_1x_2}W_{m-1}(x_1\to x_2)\le\kappa\lambda^{m-1}\sum_{x_2}\frac{a_{x_1x_2}}{\lambda+a_{x_1x_2}}\le\kappa\lambda^{m}h(x_0\to x_1), \] by induction and \eqref{eq:local}. A simple path $b_1,x_1,\dots,x_{L-1},b_2$ is a walk of this kind, so the sum in the lemma is at most $\sum_{x_1\sim b_1}a_{b_1x_1}W_{L-1}(b_1\to x_1)\le\kappa\lambda^{L-1}\Sigma(b_1)$. \end{proof} On the $k$-regular tree with all $a_e=a$ the criterion reads $ka/(\lambda+a)\le1$, that is $\lambda\ge(k-1)a$. Since this is the exact growth rate of non-backtracking walks there, the criterion is sharp on trees. On a lattice with unequal edges it gives the growth rate of weighted non-backtracking walks exactly: if all nodes have the same multiset $\{a_e\}$ and $\Sigma\equiv1$, then $h$ is a positive eigenvector of the weighted non-backtracking operator with eigenvalue $\lambda$. \section{Proof of Theorem~\ref{thm:main}}\label{sec:proof} \subsection{The criterion holds at every detector} Let $\lambda=31\sqrt p$ and write $a_e=\sqrt p\,\alpha_e(p)$ with $\alpha_e(p)=2\sqrt{c_e/(1-c_ep)}$. Then \[ \Sigma(v)=\sum_{e\ni v}\frac{\alpha_e(p)}{31+\alpha_e(p)}, \] which increases with $p$. Thus it suffices to check $\Sigma(v)\le1$ at $p=\pst$. There $31\sqrt{\pst}=0.999719\ldots\ge0.9997$, and $\Sigma(v)$ decreases in $\lambda$, so it suffices to check \begin{equation}\label{eq:check} \sum_{e\ni v}\frac{a_e}{0.9997+a_e}\le1\qquad\text{at }p=\pst . \end{equation} By Corollary~\ref{cor:types} we need to check only $29$ types per basis. For the bulk type of Lemma~\ref{lem:bulk} the computation is short: \[ \begin{array}{c|ccccc} 15\,c_e & 72 & 66 & 48 & 16 & 8\\ \text{multiplicity} & 2 & 2 & 2 & 2 & 4\\\hline a_e & 0.141662 & 0.135603 & 0.115570 & 0.066650 & 0.047116\\ a_e/(0.9997+a_e) & 0.124117 & 0.119442 & 0.103625 & 0.062503 & 0.045009 \end{array} \] and the weighted sum is $0.999409$. The other $28$ types satisfy \eqref{eq:check} with left side at most $0.9629$${}^\dagger$. We list the values for all types in Appendix~\ref{app:types}. The check is done in exact rational arithmetic, with rational upper bounds for the square roots (Table~\ref{tab:verify}, V6). \subsection{Assembly} We first check that the graph $G_{d,T}$ satisfies the hypotheses of Lemma~\ref{lem:criterion}. Each edge comes from a nonempty signature, which contains a detector, so there is no edge between $b_1$ and $b_2$. Since there is one edge per signature, there are no parallel edges, and the number of edges at $b_1$ equals the number of its neighbours. Combining Proposition~\ref{prop:sum}, Lemma~\ref{lem:length} and Lemma~\ref{lem:criterion}, we obtain \[ \Pfail\le\sum_{L\ge d}\kappa\,\Sigma(b_1)\,\lambda^{L-1}=\kappa\,\Sigma(b_1)\frac{\lambda^{d-1}}{1-\lambda}. \] Let $a_{\max}=2\sqrt{c_{\max}p/(1-c_{\max}p)}$. By Lemma~\ref{lem:graphlike}(e), $\kappa\le\lambda+a_{\max}$ and each term of $\Sigma(b_1)$ is at most $a_{\max}/(\lambda+a_{\max})$, so $\kappa\,\Sigma(b_1)\le\tfrac{(T+1)(d+1)}{2}\,a_{\max}$. This is the first bound of the theorem. For $p\le\pst$ we have $1-c_{\max}p\ge0.98932$ and $a_{\max}\le6.4429\sqrt p$, so \begin{align*} \Pfail&\le\frac{(T+1)(d+1)}{2}\cdot6.4429\sqrt p\cdot\frac{\lambda^{d-1}}{1-\lambda}\\ &=\frac{6.4429}{62}\,(T+1)(d+1)\frac{\lambda^{d}}{1-\lambda}\le0.104\,(T+1)(d+1)\frac{\lambda^d}{1-\lambda}.\qquad\qed \end{align*} \section{Proof of Theorem~\ref{thm:refined}}\label{sec:refined} In the proof of Theorem~\ref{thm:main} we sum over all ways of labelling the edges of a path as errors or corrections, although most of these labellings cannot occur. Indeed, the correction edges on a stretch of the failure path belong to a minimum-weight correction. Their weight is therefore at most that of the error edges on the stretch plus any detour between its ends, and at most that of any set of edges with the same boundary. We turn these two inequalities into local exclusion rules (Definition~\ref{def:excluded}) and count only the labelled paths that obey them. For profile weights a third rule uses the freedom in the choice of the minimizer: among the minimizers for which the decoder fails we take one that minimizes a fixed linear functional, and such a minimizer cannot turn a corner around which an equally heavy route of smaller value exists. These rules are the main new ingredient of the proof. For part (a) we fix $p_{\ast\ast}=1/625$ and the tilt $s=21/50$, and for part (b) $p_{\ast\ast}=1/500$ and $s=9/25$. \subsection{Windows} For a path or walk $P$ we write $c(P)=\prod_{e\in P}c_e$, with multiplicity, and $G/B$ for the graph obtained from $G$ by identifying $b_1$ and $b_2$ to a single vertex $B$. Let $C$ be a minimizer and $\gamma\subseteq E\triangle C$ the path of Lemma~\ref{lem:path}. A \emph{window} is a sub-path $\sigma$ of $\gamma$. We write $\sigma_C=\sigma\cap C$ and $\sigma_E=\sigma\cap E$, so that $\sigma$ is the disjoint union of $\sigma_C$ and $\sigma_E$. \begin{lemma}\label{lem:window} \begin{enumerate}[label=\textup{(\alph*)}] \item For every window $\sigma$ and every set $P'$ of edges of $G/B$ with the same detector boundary as $\sigma$, $w(\sigma_C)-w(\sigma_E)\le w(P')$. \item For every $X\subseteq C$ and every set $P'$ of edges of $G/B$ with the same detector boundary as $X$, $w(X)\le w(P')$. \end{enumerate} \end{lemma} \begin{proof} (a) The set $C'=C\triangle\sigma\triangle P'$ satisfies $\partial C'=\partial C$. Since $C\triangle\sigma=(C\setminus\sigma_C)\cup\sigma_E$, we have $w(C')\le w(C)-w(\sigma_C)+w(\sigma_E)+w(P')$, and $w(C)\le w(C')$. (b) Similarly, the set $C'=C\triangle X\triangle P'$ satisfies $\partial C'=\partial C$ and $w(C')\le w(C)-w(X)+w(P')$, and $w(C)\le w(C')$. \end{proof} For a detector $D_{m,r}$ with $m=(x,y)$ put $\phi(D_{m,r})=x+9y+81r$, and for a set $C$ of edges let $\Phi(C)$ be the sum of $\phi(u)+\phi(v)$ over the edges $\{u,v\}$ of $C$ with $u,v\in V$. A \emph{labelled window} is a path $\sigma=(v_0,\dots,v_m)$ in $G$ with $2\le m\le4$ and a label $\mathsf E$ or $\mathsf C$ on each edge. We write $n_C$ and $n_E$ for the numbers of its $\mathsf C$- and $\mathsf E$-edges, $\sigma_C$ and $\sigma_E$ for the sets of these edges, and $T(\sigma)$ for the set of detectors of odd degree in $\sigma_C$. The \emph{head} of $\sigma$ is $v_{m-1}$. The \emph{ball} of a detector $v$ is the set of detectors joined to $v$ by a chain of at most four edges between detectors. Since the detectors of $\sigma$ lie within three such edges of its head, they belong to the ball of the head. An \emph{admissible walk} for $\sigma$ is a walk in $G/B$, with $b_1$ and $b_2$ read as $B$, that visits $B$ at most once and whose detectors all lie in the ball of the head. \begin{definition}\label{def:excluded} A labelled window $\sigma$ is \emph{excluded} if it satisfies one of the following conditions. \begin{enumerate}[leftmargin=2.8em] \item[\textup{(M)}] There is an admissible walk $P'$ from $v_0$ to $v_m$ with $h'$ edges, empty if $v_0,v_m\in\{b_1,b_2\}$, such that $k=n_C-n_E-h'\ge0$ and \begin{equation}\label{eq:excluded} \Bigl(\frac{1}{p_{\ast\ast}}\Bigr)^{k}\frac{c(\sigma_E)\,c(P')}{c(\sigma_C)}>\prod_{e\in\sigma}\frac{1}{1-c_e\,p_{\ast\ast}}\cdot\Bigl(\frac{1}{1-c_{\max}\,p_{\ast\ast}}\Bigr)^{h'}. \end{equation} \item[\textup{(J)}] There are admissible walks, each from a vertex of $T(\sigma)$ to another vertex of $T(\sigma)$ or to $B$, such that each vertex of $T(\sigma)$ is an end of exactly one of them, their union $P'$ has $h'$ edges counted with multiplicity, $k=n_C-h'\ge0$ and \begin{equation}\label{eq:excludedJ} \Bigl(\frac{1}{p_{\ast\ast}}\Bigr)^{k}\frac{c(P')}{c(\sigma_C)}>\prod_{e\in\sigma_C}\frac{1}{1-c_e\,p_{\ast\ast}}\cdot\Bigl(\frac{1}{1-c_{\max}\,p_{\ast\ast}}\Bigr)^{h'}. \end{equation} If $T(\sigma)$ is empty, $P'$ is empty. \item[\textup{(S)}] (Only for Theorems~\ref{thm:refined}(b) and~\ref{thm:lean}(c).) The window has $m=2$, its vertices $u=v_0$, $b=v_1$ and $w=v_2$ are detectors, both of its edges carry the label $\mathsf C$, and some detector $x\notin\{u,b,w\}$ is adjacent to $u$ and to $w$, with $\phi(x)<\phi(b)$, such that the profiles of $ux$ and $xw$ are those of $ub$ and $bw$, in some order. \end{enumerate} \end{definition} Rule (M) compares the window with an alternative route between its ends. Rule (J) compares its correction edges with a re-pairing of their endpoints. Rule (S) compares the corner $u,b,w$ with the opposite corner $u,x,w$ of a square. Restricting the walks to the ball of the head keeps (M) and (J) local, and the detector $x$ of (S) lies within two edges of the head $b$ (Lemma~\ref{lem:locality2}). Because dropping walks only drops exclusions, any restriction of this kind would do. \begin{lemma}\label{lem:excluded} \begin{enumerate}[label=\textup{(\alph*)}] \item Let $p\le p_{\ast\ast}$, let the weights be as in Section~\ref{sec:decoder}, and let $C$ be a minimizer. Label the edges of $\gamma\cap E$ by $\mathsf E$ and those of $\gamma\cap C$ by $\mathsf C$. Then no window of $\gamma$, with these labels, is excluded by (M) or (J). \item Let $p\le p_{\ast\ast}$, let the weights be profile weights and suppose that the decoder fails. Let $C^\ast$ be a minimizer for which the decoder fails, with the smallest value of $\Phi$ among these minimizers, and label the path $\gamma\subseteq E\triangle C^\ast$ as in (a). Then no window of $\gamma$ is excluded by (S). \end{enumerate} \end{lemma} \begin{proof} (a) Suppose that a window $\sigma$ of $\gamma$ is excluded, and let $P'$ be the walk or the union of walks of Definition~\ref{def:excluded}. Let $P''$ be the set of edges that $P'$ uses an odd number of times, so that $w(P'')\le w(P')$. Put $\varepsilon_e=-\ln(1-q_e)$. Since $q_e(1-q_e)\le r_e\le q_e$, each weight satisfies $|w_e+\ln q_e|\le\varepsilon_e$, and each $\varepsilon_e$ with $e\in P'$ is at most $-\ln(1-c_{\max}p)$. Under (M), $P''$ has the same detector boundary as $\sigma$, because $b_1$, $b_2$ and $B$ are not detectors, and we have \[ w(\sigma_C)-w(\sigma_E)-w(P')\ge k\ln\frac1p+\ln\frac{c(\sigma_E)\,c(P')}{c(\sigma_C)}-\sum_{e\in\sigma}\varepsilon_e-\sum_{e\in P'}\varepsilon_e . \] At $p=p_{\ast\ast}$ the right side is positive by \eqref{eq:excluded}. As $p$ decreases, the first term does not decrease, because $k\ge0$, and each $\varepsilon_e$ decreases, so the right side stays positive. Hence $w(\sigma_C)-w(\sigma_E)>w(P'')$, which contradicts Lemma~\ref{lem:window}(a). Under (J), each vertex of $T(\sigma)$ is an end of exactly one walk, so $P''$ has the detector boundary $T(\sigma)$ of $\sigma_C$. The same estimate without the terms of $\sigma_E$, and with \eqref{eq:excludedJ} in place of \eqref{eq:excluded}, shows that $w(\sigma_C)>w(P'')$, which contradicts Lemma~\ref{lem:window}(b) for $X=\sigma_C$. (b) Suppose that the window $(u,b,w)$ of $\gamma$ is excluded by (S), with the detector $x$, and let $Q$ be the cycle with the edges $ub$, $bw$, $wx$ and $xu$. The edges $ub$ and $bw$ belong to $C^\ast$. The set $C'=C^\ast\triangle Q$ satisfies $\partial C'=\partial C^\ast$, and since $Q$ has no edge at $b_1$, the decoder predicts the same logical flip with $C'$ as with $C^\ast$. Since profile weights agree on edges with the same profile, $w(ux)+w(xw)=w(ub)+w(bw)$. If neither $ux$ nor $xw$ belongs to $C^\ast$, then $w(C')=w(C^\ast)$, so $C'$ is a minimizer for which the decoder fails, and $\Phi(C')-\Phi(C^\ast)=2\bigl(\phi(x)-\phi(b)\bigr)<0$, which contradicts the choice of $C^\ast$. If exactly one of them, say $xw$, belongs to $C^\ast$, then $w(C')=w(C^\ast)-w(ub)-w(bw)-w(xw)+w(ux)=w(C^\ast)-2w(xw)$, and if both do, then $w(C')=w(C^\ast)-w(Q)$. In both cases $w(C')0$, and let $H$ assign a positive number to every state. Suppose that every state $\sigma=(v_0,v_1,v_2,v_3;l_1l_2l_3)$ satisfies \begin{equation}\label{eq:row} \sum_{\text{successors}}\omega(v_3v_4,l_4)\,H(v_1,v_2,v_3,v_4;l_2l_3l_4)+\sum_{\text{terminal moves}}\omega(v_3b_2,l_4)\le\lambda\,H(\sigma). \end{equation} Then for every $L\ge4$ the labelled paths with $L$ edges have total weight at most \[ \lambda^{L-3}\sum\omega(b_1v_1,l_1)\,\omega(v_1v_2,l_2)\,\omega(v_2v_3,l_3)\,H(b_1,v_1,v_2,v_3;l_1l_2l_3), \] where the sum runs over the states with $v_0=b_1$. \end{lemma} \begin{proof} For a state $\sigma$ and $m\ge1$ let $W_m(\sigma)$ be the total weight of the sequences of $m$ edges that continue $\sigma$ by successors and end with a terminal move, the weight being the product of the factors of the new edges. Then $W_1(\sigma)$ is the terminal sum in \eqref{eq:row}, so $W_1(\sigma)\le\lambda H(\sigma)$, and for $m\ge2$, by induction, \[ W_m(\sigma)=\sum_{\text{successors}}\omega(v_3v_4,l_4)\,W_{m-1}(v_1,v_2,v_3,v_4;l_2l_3l_4)\le\lambda^{m}H(\sigma). \] A labelled path $b_1,v_1,\dots,v_L$ begins with the state $(b_1,v_1,v_2,v_3;l_1l_2l_3)$, and each quadruple of consecutive vertices is a successor of the previous one. Indeed $v_{i+1}\notin\{v_{i-2},v_{i-1},v_i\}$ because the path is simple, and the windows ending at $v_{i+1}$ are not excluded because the path is labelled. Hence the labelled paths with $L$ edges have total weight at most $\sum\omega(b_1v_1,l_1)\,\omega(v_1v_2,l_2)\,\omega(v_2v_3,l_3)\,W_{L-3}(b_1,v_1,v_2,v_3;l_1l_2l_3)$. \end{proof} \subsection{Classes and locality} The certificate assigns the same potential to states with the same \emph{class} and the same labels. Here the class of $(v_0,v_1,v_2,v_3;l_1l_2l_3)$ records the types of $v_0$ (or the label $b_1$), $v_1$, $v_2$ and $v_3$ and the offsets $v_1-v_0$, $v_2-v_1$ and $v_3-v_2$. We call the inequality \eqref{eq:row}, written in terms of classes, labels and edge coefficients, the \emph{row} of the state. The \emph{growth rate} of a set of rows is the infimum of the $\lambda$ for which some positive potential satisfies all of them. The \emph{typed ball} of a detector $v$ is the set of pairs (offset $u-v$, type of $u$) over the detectors $u$ in the ball of $v$. \begin{lemma}\label{lem:locality2} The rows of the states $(v_0,v_1,v_2,v_3;l_1l_2l_3)$ with a given last vertex $v_3$ are determined by the typed ball of $v_3$. The sum of $\omega(b_1v_1,l_1)\,\omega(v_1v_2,l_2)\,\omega(v_2v_3,l_3)\,H(b_1,v_1,v_2,v_3;l_1l_2l_3)$ over the states with a given neighbour $v_1$ of $b_1$ is determined by the typed ball of $v_1$. Every typed ball of every graph $G_{d,T}$ occurs in some $G_{d',T'}$ with $d'\le25$ and $T'\le13$. \end{lemma} \begin{proof} The vertices of a state ending at $v_3$ and of its successors lie within three edges of $v_3$, and their classes and the coefficients of the edges involved are read from types and offsets. Since the windows tested in these rows have the head $v_3$, the exclusion tests use only walks whose detectors lie in the ball of $v_3$, the edges among these detectors and their boundary edges, all of which the types record. Rule (S) uses a detector within two edges of the head and the profiles of four edges between detectors of the ball. The profiles of the edges at a detector $v$ are determined by the same local data as its type in Lemma~\ref{lem:locality}(b), because the outcomes with $v$ in their signature and their locations are, and they are in fact determined by the type of $v$${}^\dagger$. So the types record these profiles as well. The start sums involve $v_2\sim v_1$, $v_3\sim v_2$ and no exclusions. A chain of at most four edges between detectors changes each coordinate by at most $16$ and the layer by at most $4$. By Lemma~\ref{lem:locality}(b), the typed ball of $v_3$ is therefore determined by the positions of the qubits within $\ell^\infty$-distance $22$ of $v_3$ and the X or Z types of the measure qubits among them, by $\min(r,6)$ and by $\min(T-r,6)$, where $r$ is the layer of $v_3$. The last statement follows as in Lemma~\ref{lem:locality}(c), with $6$ replaced by $22$ and $2$ by $6$. Indeed, the even coordinates of $G_{25}$ at distance at least $23$ from both opposite sides are $24$ and $26$, one of each residue modulo $4$, and the layer data of every layer occur for $T'=13$. \end{proof} \subsection{Proof of Theorem~\ref{thm:refined}} Put $\lambda_0=997/1000$ for part (a) and $\lambda_0=999/1000$ for part (b). The instances with $d\le25$ and $T\le13$ have $2{,}546{,}882$ distinct rows for part (a) and $2{,}545{,}552$ for part (b)${}^\dagger$, and by Lemma~\ref{lem:locality2} these are all the rows of all graphs $G_{d,T}$. Each of the two certificates assigns a positive integer $h$ to each of the $953{,}120$ pairs of a class and a label sequence $l_1l_2l_3$ that occur, and we put $H=h/10^{15}$. All rows hold in exact integer arithmetic at $p=p_{\ast\ast}$ with $\lambda=\lambda_0$, when each factor $\omega(e,l)$ is replaced by a rational upper bound computed with integer roots of order $50$ for part (a) and $25$ for part (b)${}^\dagger$ (Table~\ref{tab:verify2}). Let $p\le p_{\ast\ast}$ and $\rho=(p/p_{\ast\ast})^{s}$. Then each factor satisfies $\omega(e,l)(p)\le\rho\,\omega(e,l)(p_{\ast\ast})$, because $(p/p_{\ast\ast})^{1-s}\le\rho$ and $(1-q_e)^{-1}$ decreases as $p$ decreases. Windows excluded by (M) or (J) stay excluded by Lemma~\ref{lem:excluded}(a), and rule (S) does not depend on $p$. Hence all rows hold at $p$ with $\lambda_p=\lambda_0\rho$. Let $K$ be an upper bound, computed with the same rational bounds of the factors, for the start sums of Lemma~\ref{lem:locality2} at $p_{\ast\ast}$ over all neighbours $v_1$ of $b_1$${}^\dagger$. Let $K_3$ be an upper bound of the same kind for the sums of $\omega(b_1v_1,l_1)\,\omega(v_1v_2,l_2)\,\omega(v_2b_2,l_3)$ over the paths $b_1,v_1,v_2,b_2$ with a given $v_1$ and all labels${}^\dagger$; such paths exist only for $d=3$. For part (a) $K=0.031062\ldots$ and $K_3=0.032106\ldots$, and for part (b) $K=0.056229\ldots$ and $K_3=0.064013\ldots$. From Proposition~\ref{prop:labelled}, Lemma~\ref{lem:memory} and Lemma~\ref{lem:length} we obtain \[ \Pfail\le|N(b_1)|\Bigl(\rho^{3}K_3\,[d=3]+\sum_{L\ge\max(d,4)}\lambda_p^{L-3}\rho^{3}K\Bigr)\le\rho^{3}\,|N(b_1)|\,(K+K_3)\,\frac{\lambda_p^{d-3}}{1-\lambda_p}. \] Recall that $|N(b_1)|=(T+1)(d+1)/2$ by Lemma~\ref{lem:graphlike}(e). With $\rho=\lambda_p/\lambda_0$ the right side equals $(K+K_3)(T+1)(d+1)\lambda_p^{d}/(2\lambda_0^3(1-\lambda_p))$, and $(K+K_3)/(2\lambda_0^3)$ is at most $0.032$ for part (a) and $0.061$ for part (b). \qed \section{The lean schedule}\label{sec:lean} In the lean schedule all measure qubits and data qubits are prepared in a first step, the Z-type measure qubits in $|0\rangle$ and the X-type ones in $|+\rangle$. Each round then consists of the steps (S3)--(S6) of Section~\ref{sec:circuit} and one more step. In it each Z-type measure qubit is measured in the $Z$ basis and reset to $|0\rangle$, each X-type measure qubit is measured in the $X$ basis and reset to $|+\rangle$, and the data qubits are idle. The noise model of Section~\ref{sec:noise} applies to these locations, the measurement and the reset in this step failing independently, each with probability $p$. The detectors, the logical outcomes and the decoder are as before. Section~\ref{sec:graph} carries over with the following changes${}^\dagger$. Each fault outcome again flips at most two detectors, and Lemma~\ref{lem:graphlike} holds with $c_{\max}=94/15$. In the bulk of basis $Z$, the coefficients $15c_e$ of the edges with offsets $\pm(0,0,1)$, $\pm(2,-2,0)$, $\pm(2,2,0)$, $\pm(2,2,-1)$, $\pm(2,-2,-1)$ and $\pm(4,0,-1)$ are $46$, $42$, $18$, $16$, $8$ and $8$, against $66$, $72$, $48$, $16$, $8$ and $8$ in Lemma~\ref{lem:bulk}. The difference comes from the three idle steps per round of the data qubits and the two of the Z-type measure qubits that the lean schedule does not have. There are again $29$ node types per basis. We count the reset in the measure-and-reset step, and the first step, as the start of the next round. With this convention a measure qubit is again reset at the start of each round, and the proofs of Lemmas~\ref{lem:locality} and~\ref{lem:locality2}, which use only the layout, the CX orders and this structure of the rounds, apply verbatim. All edges again change each coordinate by at most $4$ and the layer by at most $1$. \begin{proof}[Proof of Theorem~\ref{thm:lean}] (a) As in Section~\ref{sec:proof}, with $\lambda=25.55\sqrt p$. At $p=1.53\times10^{-3}$ we have $25.55\sqrt p\ge0.9993$, and the criterion \eqref{eq:check}, with $0.9997$ replaced by $0.9993$, holds for all types, with largest left side $0.99794$ at the bulk type and $0.95318$ for the others${}^\dagger$. With $c_{\max}=94/15$, the assembly of Section~\ref{sec:proof} then leads to the prefactor $\sqrt{c_{\max}/(1-c_{\max}p)}/25.55\le0.0985$. (b) As in Section~\ref{sec:refined}, with $p_{\ast\ast}=3/1250$, $s=21/50$ and $c_{\max}=94/15$ in Definition~\ref{def:excluded}. The instances with $d\le25$ and $T\le13$ have $2{,}548{,}765$ distinct rows, all of which already occur for $d\le15$ and $T\le7$. A certificate with positive integers on the $953{,}120$ pairs of a class and a label sequence satisfies all rows in exact arithmetic with $\lambda=997/1000$, and the start constants are $K=0.026464\ldots$ and $K_3=0.028384\ldots$, with $(K+K_3)/(2\cdot0.997^3)\le0.028$${}^\dagger$. (c) As in part (b) of Theorem~\ref{thm:refined}, with $p_{\ast\ast}=3/1000$, $s=9/25$, $\lambda_0=997/1000$ and $c_{\max}=94/15$. The instances with $d\le25$ and $T\le13$ have $2{,}547{,}432$ distinct rows. Again, a certificate on the same $953{,}120$ pairs satisfies all rows in exact arithmetic with $\lambda=997/1000$, and the start constants are $K=0.045261\ldots$ and $K_3=0.057416\ldots$, with $(K+K_3)/(2\cdot0.997^3)\le0.052$${}^\dagger$. \end{proof} \section{Non-uniform error rates}\label{sec:hetero} In a real device the gates, measurements and idle steps fail at different rates. To model this, we sort the locations of the circuit of Section~\ref{sec:circuit} into seven categories: resets and preparations; measurements; $H$ gates; CX gates; qubits idle in steps (S2)--(S7); data qubits idle in step (S1); data qubits idle in step (S8). A \emph{rate vector} $\theta$ assigns a failure probability $\theta_k$ to the locations of category $k$, with the failure outcomes of Section~\ref{sec:noise}. The probability of an edge becomes \[ q_e(\theta)=\sum_k c_{e,k}\,\theta_k , \] where $c_{e,k}$ is the sum of $\pi(f)$ over the outcomes $f$ with $e(f)=e$ at locations of category $k$, so that $\sum_kc_{e,k}=c_e$. The graph, the signatures and the logical effects do not depend on $\theta$, and Sections~\ref{sec:graph} and~\ref{sec:paths} hold with $q_e(\theta)$ in place of $c_ep$. The types, which now record the coefficients $c_{e,k}$, are again $29$ per basis, and Lemma~\ref{lem:locality} holds with the same proof${}^\dagger$. \begin{theorem}\label{thm:hetero} Let $\theta$ be a rate vector with $\max_eq_e(\theta)<1/2$, and consider the memory experiment with rates $t\theta$ for some $0\prod_{e\in\sigma}\frac{1}{1-q_e(\theta)}\cdot\Bigl(\frac{1}{1-q_{\max}}\Bigr)^{h'} \end{equation} and \eqref{eq:excludedJ} by \begin{equation}\label{eq:excludedJ-theta} \frac{q(P')}{q(\sigma_C)}>\prod_{e\in\sigma_C}\frac{1}{1-q_e(\theta)}\cdot\Bigl(\frac{1}{1-q_{\max}}\Bigr)^{h'}, \end{equation} keeping the conditions $k\ge0$, and define labelled paths, states and rows as in Section~\ref{sec:refined} with the windows excluded by these two rules, with the factors $\omega(e,l)$ evaluated at $q_e(\theta)$ and with a tilt $0{\raggedright\arraybackslash}p{0.62\textwidth}l@{}} \toprule & check & range\\ \midrule V1 & noiseless circuit: all detectors and the logical outcome are deterministic, with value $0$ & $d\le13$, $T\le7$\\ V2 & fault table: each outcome, injected alone into Stim's Pauli-frame simulator, gives the signature and logical effect computed here; the set of signatures equals that of Stim's detector error model; the outcome probabilities of each location sum to $1$; the coefficients $c_e$ agree with Stim's edge probabilities at $p=10^{-7}$ to $2\times10^{-6}$ relative & $d\le13$, $T\le7$\\ V3 & Lemma~\ref{lem:graphlike}(a,b) & $d\le13$, $T\le7$\\ V4 & Lemma~\ref{lem:graphlike}(c,d,e) & $d\le13$, $T\le7$\\ V5 & exactly $29$ types per basis; all occur already for $d\le9$, $T\le5$; the set of types is the same for all $d\ge9$, $T\ge5$ in range (Lemma~\ref{lem:locality}) & $d\le13$, $T\le7$\\ V6 & criterion \eqref{eq:check} for all types at $p=\pst$, $\lambda=0.9997$, and at $p=10^{-3}$, $\lambda=0.98$; the unique maximum is the bulk type; the second largest value at $\pst$ is at most $0.9629$ & all $29+29$ types\\ \bottomrule \end{tabular} \caption{Computer verification for Theorem~\ref{thm:main}. Lemma~\ref{lem:locality}(c) needs only $d\le9$ and $T\le5$.} \label{tab:verify} \end{table} Table~\ref{tab:verify2} lists the checks behind Theorem~\ref{thm:refined}. Two further scripts, one for each part, regenerate the rows of all instances with $d\le25$ and $T\le13$ and check them against the two certificates, each of which lists $953{,}120$ integers $h$. By Lemma~\ref{lem:locality2} the rows at a detector depend only on its typed ball, so each script computes the rows at one detector for each distinct typed ball of the range, which we call the heads; balls are compared as full tuples. The rows are generated by a C++ program with exact integer arithmetic. A Python implementation of the same rules produces the same rows at all detectors of five test instances with $d\le9$ and $T\le5$, and of two instances with the rates of Section~\ref{sec:hetero}. Classes are named by $64$-bit hashes of the types and offsets they record. A collision would merge two classes, but this can only make the system of rows harder to satisfy. Three further steps are not used in the proof: the iteration on the system of rows that found the potentials, and two tests of the exclusions. For the first test, let $w^{+}_e=-\ln q_e-\ln(1-q_e)$ and $w^{-}_e=-\ln q_e+\ln(1-q_e)$ be the upper and lower bounds of the weights at $p_{\ast\ast}$. For each excluded window, Dijkstra's algorithm on $G/B$ with the weights $w^{+}$ finds an edge set with the same detector boundary as $\sigma$ that is lighter than $w^{-}(\sigma_C)-w^{+}(\sigma_E)$, or an edge set with the same detector boundary as $\sigma_C$ that is lighter than $w^{-}(\sigma_C)$. The test covers all $23.7$ million excluded windows of the instances with $d\le9$ and $T\le5$, with no failure, both at $p_{\ast\ast}=1/625$ and at $p_{\ast\ast}=1/500$. The second test recomputes every exclusion by rule (S) from the decoding graph, with the profiles read from the fault table, and checks that the two pairs of edges have the same profiles. For $d\le9$ and $T\le5$ it confirms all $18{,}720$ such windows for each schedule and finds no window that the rule misses. \begin{table}[ht] \centering\small \begin{tabular}{@{}l>{\raggedright\arraybackslash}p{0.62\textwidth}l@{}} \toprule & check & range\\ \midrule S1 & parameters of the certificate: $p_{\ast\ast}=1/625$, $\lambda=997/1000$, $s=21/50$ & \\ S2 & rows of all instances: $2{,}546{,}882$ distinct rows, all of which already occur for $d\le15$, $T\le7$; $13{,}658$ distinct typed balls; $29$ node types per basis, with injective identifiers; largest coefficient $c_{\max}=154/15$ & $d\le25$, $T\le13$\\ S3 & every class in a row, as head or successor, has a positive potential in the certificate & all rows\\ S4 & every row holds in exact integer arithmetic at $p_{\ast\ast}$ and $\lambda=997/1000$, with rational upper bounds of the factors $\omega$; largest ratio of the two sides $0.99900$ & all rows\\ S5 & start constants $K=0.031062\ldots$ and $K_3=0.032106\ldots$, with $(K+K_3)/(2\cdot0.997^3)\le0.032$ & all neighbours of $b_1$\\ S6 & part (b), as S1--S5: $p_{\ast\ast}=1/500$, $\lambda=999/1000$, $s=9/25$, rules (M), (J) and (S); the profile of each edge at a detector is determined by the type of the detector; $2{,}545{,}552$ distinct rows; positive potentials; all rows exact, largest ratio $0.99900$; $K=0.056229\ldots$, $K_3=0.064013\ldots$, $(K+K_3)/(2\cdot0.999^3)\le0.061$ & $d\le25$, $T\le13$\\ \bottomrule \end{tabular} \caption{Computer verification for Theorem~\ref{thm:refined}. Rows S1--S5 concern part (a). Lemma~\ref{lem:locality2} needs $d\le25$ and $T\le13$.} \label{tab:verify2} \end{table} The checks behind Theorem~\ref{thm:lean} (Table~\ref{tab:verify3}) are those of Tables~\ref{tab:verify} and~\ref{tab:verify2}, run on the lean schedule with its own certificates. The Dijkstra test of the exclusions finds no failure among the $23.6$ million excluded windows of the $40$ instances with $d\le9$ and $T\le5$ at $p_{\ast\ast}=3/1250$, nor among the $23.5$ million at $p_{\ast\ast}=3/1000$. \begin{table}[ht] \centering\small \begin{tabular}{@{}l>{\raggedright\arraybackslash}p{0.62\textwidth}l@{}} \toprule & check & range\\ \midrule L1 & as V1--V5: deterministic noiseless values $0$; fault table equal to Stim's outcome by outcome and in first-order coefficients; Lemma~\ref{lem:graphlike} with $c_{\max}=94/15$; $29$ types per basis, stable for $d\ge9$, $T\ge5$ & $d\le13$, $T\le7$\\ L2 & as V6: criterion at $p=1.53\times10^{-3}$, $\lambda=0.9993\le25.55\sqrt p$; largest left side $0.99794$ (bulk), second $0.95318$ & all $29+29$ types\\ L3 & as S1--S5: $p_{\ast\ast}=3/1250$, $s=21/50$; $2{,}548{,}765$ rows, all present for $d\le15$, $T\le7$; positive potentials; all rows exact at $\lambda=997/1000$, largest ratio $0.99799$; $K=0.026464\ldots$, $K_3=0.028384\ldots$, $(K+K_3)/(2\cdot0.997^3)\le0.028$ & $d\le25$, $T\le13$\\ L4 & as S6: $p_{\ast\ast}=3/1000$, $s=9/25$, rules (M), (J) and (S); $2{,}547{,}432$ rows; positive potentials; all rows exact at $\lambda=997/1000$, largest ratio $0.99900$; $K=0.045261\ldots$, $K_3=0.057416\ldots$, $(K+K_3)/(2\cdot0.997^3)\le0.052$ & $d\le25$, $T\le13$\\ \bottomrule \end{tabular} \caption{Computer verification for Theorem~\ref{thm:lean}.} \label{tab:verify3} \end{table} For Section~\ref{sec:hetero}, a further script runs the checks H1--H4 of Table~\ref{tab:verify4} on the error models of Table~\ref{tab:chips}. For H4 it runs the script of rows S1--S5 with the edge probabilities $q_e(\theta)$, written as integers over a common denominator, in place of the coefficients, and check H5 runs the script of row S6 in the same way. As a test, with uniform rates this code gives the rows of the code of Table~\ref{tab:verify2} for $(d,T)=(5,3)$, $(7,4)$ and $(9,5)$, after renaming the classes and rescaling the numerators of the edges. \begin{table}[ht] \centering\small \begin{tabular}{@{}l>{\raggedright\arraybackslash}p{0.62\textwidth}l@{}} \toprule & check & range\\ \midrule H1 & every location has one of the seven categories; with equal rates the coefficients $c_{e,k}$ add up to $c_e$ & $d\le9$, $T\le5$\\ H2 & category-resolved types: $29$ per basis, all present for $d=9$, $T=5$, and the same set for all $d\ge9$, $T\ge5$ in range & $d\le13$, $T\le7$\\ H3 & part (a) holds exactly for Helios at $\lambda=0.9325$ and for H2 at $\lambda=0.8957$; for the other four models its left side exceeds $1$ at $\lambda=1$ for some type & all $29+29$ types\\ H4 & part (b) for Helios, H2 and Heron r3, with $s=43/100$, as S1--S5: $q_{\max}$ recomputed, and every edge probability of the range at most $q_{\max}$; $2{,}546{,}246$, $2{,}546{,}404$ and $2{,}546{,}625$ distinct rows; positive potentials; all rows exact at $\lambda=3/4$, $143/200$ and $97/100$; $(K+K_3)/(2\lambda^3)\le0.033$, $0.022$ and $0.023$ & $d\le25$, $T\le13$\\ H5 & part (c) for Helios, H2 and Heron r3, with $s=19/50$, as S6, with the profiles at the model rates: $2{,}544{,}853$, $2{,}545{,}240$ and $2{,}545{,}179$ distinct rows; positive potentials; all rows exact at $\lambda=27/40$, $643/1000$ and $873/1000$; $(K+K_3)/(2\lambda^3)\le0.058$, $0.039$ and $0.039$ & $d\le25$, $T\le13$\\ \bottomrule \end{tabular} \caption{Computer verification for Theorem~\ref{thm:hetero} and the error models of Table~\ref{tab:chips}.} \label{tab:verify4} \end{table} \section{Formal verification in Lean 4}\label{sec:lean4} We prove the theorems of this paper in the proof assistant Lean~4 (version 4.35.0-rc3), using the Mathlib library (commit \texttt{c55e6e78}). A \emph{proof assistant} checks every step of a proof against a small set of logical rules; the part of Lean that performs this check is its \emph{kernel}. The formal development defines the circuit, the noise, the memory experiment and the decoder of Section~\ref{sec:setting}, and derives the bounds of the theorems from these definitions. It contains about 25{,}100 lines written by hand, together with generated data files (node types, certificates) and generated check files. Each theorem is proved in two versions: in the \emph{kernel} version every computation is checked by the kernel, and in the \emph{native} version the large computations are evaluated outside the kernel, which takes far less time. In this section we state what is proved, what has to be trusted, and how to reproduce the verification. \subsection{What is modelled} \emph{The circuit and the experiment.} The layout of the rotated surface code, the eight steps of a round, the noise locations with their outcomes and the probabilities $p\,\pi(f)$ are those of Sections~\ref{sec:circuit} and~\ref{sec:noise}. We define the effect of the faults by Pauli-frame propagation: a CX gate copies an $X$ component from its control to its target and a $Z$ component from its target to its control, an $H$ gate exchanges the two components, and a reset clears both. For any set of faults, at most one outcome per location, this determines the recorded measurement outcomes, the detectors $D_{m,r}$ of Section~\ref{sec:circuit} and the flip of the logical outcome. The formal development proves that these are the parities of the single-fault values, so they agree with the signatures $\sigma(f)$ and the logical effects $\ell(f)$ of Section~\ref{sec:decoder}. \emph{The decoder and the failure probability.} Here the decoding graph and the weights are those of Section~\ref{sec:decoder}, for any numbers $r_e$ with $q_e(1-q_e)\le r_e\le q_e$; this range contains both common choices. The failure probability $\Pfail$ is the probability, under the product distribution of the faults, that some set $C$ of minimum weight with $\partial C$ equal to the observed detectors predicts the logical flip wrongly. Hence a bound on this probability holds for every rule that selects a minimizer. \emph{Profile weights.} The profile of an edge and profile weights are those of Section~\ref{sec:decoder}: for a location $\ell$, $c_{\ell,e}$ is the sum of $\pi(f)$ over the outcomes $f$ of $\ell$ with $e(f)=e$, the \emph{profile} of $e$ is the multiset of the nonzero numbers $c_{\ell,e}$ over all locations $\ell$, and the weights are \emph{profile weights} if $r_e$ is a function of $p$ and the profile of $e$. Note that both choices of Section~\ref{sec:decoder} are profile weights. The theorems that use rule (S) are stated for profile weights. \emph{The lean schedule.} We model the lean schedule of Section~\ref{sec:lean} by its own Pauli-frame semantics: a preparation step, then per round four CX steps and a fused measure-and-reset step, in which the X-type measure qubits are measured in the $X$ basis. Its noise locations are those of Section~\ref{sec:lean}, including the reset failures after the last measurement. The development proves that every lean location changes the measurement outcomes and the final data values exactly as the corresponding location of the eight-step circuit restricted to the lean locations, and that the reset failures after the last measurement change nothing. Hence the lean experiment has the failure probability of the restricted eight-step circuit, and the formal theorems are about the lean schedule itself. \emph{Non-uniform rates.} A rate vector $\theta$ assigns to each of the seven categories of Section~\ref{sec:hetero} the failure probability $\theta_k$, and the outcomes of a failed location are uniform. The formal theorems are stated for the three certified models, whose rates are those of the accompanying files, scaled by any $0