SlowGuess/NeurIPS_2023_OCR huggingface dataset:
1. Find the unique vertex  $\hat{u} \in \mathcal{J} \setminus \{r(\mathcal{J})\}$  such that  $u_t$  is in the maximal subtree of  $\mathcal{Z}_t$  with  $\hat{u}$  and  $\uparrow_{\mathcal{J}}(\hat{u})$  as leaves.
2. Find  $u^{*} \coloneqq \Gamma_{\mathcal{Z}_{t}}(u_{t}, \hat{u})$ .
To perform these tasks in polylogarithmic time we will utilise TSTs  $\mathcal{E}$  and  $\mathcal{D}$  of  $\mathcal{Z}_t$  and  $\mathcal{J}$  respectively. Both the searching tasks utilise a function  $\nu : \mathcal{Z}_t^2 \to \{\triangleleft, \triangleleft, \triangleright\}$  defined, for all  $u, u' \in \mathcal{Z}_t$  as follows. If  $u' \in \Downarrow_{\mathcal{Z}_t} (\triangleleft(u))$  or  $u' \in \Downarrow_{\mathcal{Z}_t} (\triangleright(u))$  then  $\nu(u, u') := \triangleleft$  or  $\nu(u, u') := \triangleright$  respectively. Otherwise  $\nu(u, u') := \triangleleft$ . This can be computed as follows. If  $u = u'$  then  $\nu(u, u') := \triangleleft$ . Otherwise let  $\tilde{s}$  and  $\tilde{s}'$  be the unique leaves of  $\mathcal{E}$  such that  $\mu(\tilde{s}) = u$  and  $\mu(\tilde{s}') = u'$ . Let  $s^* := \Gamma_{\mathcal{E}}(\tilde{s}, \tilde{s}')$  and let  $\hat{s}$  and  $\hat{s}'$  be the children of  $s^*$  which are ancestors of  $\tilde{s}$  and  $\tilde{s}'$  respectively. If  $\hat{s} \neq \nabla(s^*)$  then we have  $\nu(u, u') = \triangleleft$ . If  $\xi(s^*) = u$  then we have  $\nu(u, u') = \triangleleft$  or  $\nu(u, u') = \triangleright$  if  $\hat{s}' = \triangleleft(s^*)$  or  $\hat{s}' = \triangleright(s^*)$  respectively. If  $\hat{s} = \nabla(s^*)$  and  $\xi(s^*) \neq u$  then we perform the following process. Start with  $s$  equal to  $\hat{s}$ . At any point in the process we do as follows. If  $s \in \mathcal{E}^\circ$  then the process terminates with  $\nu(u, u') := \triangleleft$ . If  $s \in \mathcal{E}^\bullet$  and  $u = \xi(s)$  then the process terminates with  $\nu(u, u') = \triangleleft$  or  $\nu(u, u') = \triangleright$  if  $\triangleleft(s) \in \mathcal{E}^\bullet$  or  $\triangleright(s) \in \mathcal{E}^\bullet$  respectively. If  $s \in \mathcal{E}^\bullet$  and  $u \neq \xi(s)$  then we reset  $s$  as equal to the child of  $s$  which is an ancestor of  $\tilde{s}$  and continue the process.
The vertex  $\hat{u}$  can be found as follows. We construct a root-to-leaf path in  $\mathcal{D}$  such that, given a vertex  $s$  in the path, the next vertex in the path is  $\triangleleft(s),\triangleright (s)$  or  $\nabla (s)$  if  $\nu (\xi (s),u_t)$  is equal to  $\triangleleft ,\triangleright$  or  $\triangleleft$  respectively. Given that  $s^\prime$  is the leaf of  $\mathcal{D}$  that is in this path we have  $\hat{u} = \mu (s^{\prime})$
The vertex  $u^{*}$  can then be found as follows. We construct a root-to-leaf path in  $\mathcal{E}$  such that, given a vertex  $s$  in the path, the next vertex in the path is found as follows. If  $\nu(\xi(s), u_{t}) = \nu(\xi(s), \hat{u})$  then given  $\nu(\xi(s), u_{t})$  is equal to  $\triangleleft$ ,  $\triangleright$  or  $\triangleleft$ , the next vertex is equal to  $\triangleleft(s)$ ,  $\triangleright(s)$  or  $\nabla(s)$  respectively. Otherwise, the next vertex is  $\nabla(s)$ . Given that  $s'$  is the leaf of  $\mathcal{E}$  that is in this path we have  $u^{*} = \mu(s')$ .
The fact that these algorithms find the correct vertices is given in the following theorem:
Theorem D.1. The above algorithms are correct.
D.3 Belief Propagation
Here we utilise the methodology of [7] in order to efficiently compute the function  $\tilde{\Lambda}$  that appears in the CANPROP implementation. i.e. given a contraction  $\mathcal{J}$ , a function  $\lambda: \mathcal{J}^{\star} \to \mathbb{R}_{+}$  and some leaf  $\hat{u} \in \mathcal{J}^{\star}$  we need to compute  $\tilde{\Lambda}(\mathcal{J}, \lambda, \hat{u})$ . For brevity let us define, for all  $i, i' \in \{0,1\}$ , and all vertices  $u \in \mathcal{J} \setminus \{r(\mathcal{J})\}$ , the quantities:
$$
\hat {\tau} _ {i, i ^ {\prime}} (u) := \tau_ {i, i ^ {\prime}} (\mathcal {J}, u) \quad ; \quad \hat {\kappa} _ {i} (u) := \tilde {\kappa} _ {i} (\mathcal {J}, \lambda , u).
$$
For simplicity of presentation we will utilise a tree  $\mathcal{J}'$  which is defined as identical to  $\mathcal{J}$  except with a single vertex added as the parent of  $r(\mathcal{J})$ . For all  $i, i' \in \{0, 1\}$  we define  $\hat{\kappa}_i(r(\mathcal{J}')) := 1$  and  $\hat{\tau}_{i,i'}(r(\mathcal{J})) = \llbracket i = i'\rrbracket$ . For all  $u \in \mathcal{J}$  we will define  $\uparrow(u) := \uparrow_{\mathcal{J}'}(u)$
We will utilise a TST  $\mathcal{D}$  of  $\mathcal{J}$  by maintaining potentials on the vertices of  $\mathcal{D}$  defined as follows. First, as in Section D.1, for any vertex  $s\in \mathcal{D}$  we define the subtree  $\hat{\mathcal{J}} (s)$  of  $\mathcal{J}$  to be equal to  $\Downarrow_{\mathcal{J}}(\mu (s))$  if  $s\in \mathcal{D}^{\circ}$  and equal to the subtree in  $\mathcal{J}$  of all descendants of  $\mu (s)$  which are not proper descendants of  $\mu '(s)$  if  $s\in \mathcal{D}^{\bullet}$ . For all  $s\in \mathcal{D}^{\circ}$  and  $i\in \{0,1\}$  we define:
$$
\Psi_ {i} (s) := \sum_ {f \in \{0, 1 \} ^ {\hat {\mathcal {J}} (s) \cup \{\uparrow (\mu (s)) \}}} [   [ f (\uparrow (\mu (s))) = i ]   ] \prod_ {u \in \hat {\mathcal {J}} (s)} \hat {\tau} _ {f (\uparrow (u)), f (u)} (u) \hat {\kappa} _ {f (u)} (u)
$$
and for all  $s\in \mathcal{D}^{\bullet}$  and  $i,i^{\prime}\in \{0,1\}$  we define:
$$
\Omega_ {i, i ^ {\prime}} (s) := \sum_ {f \in \{0, 1 \} ^ {\hat {\mathcal {J}} (s) \cup \{\uparrow (\mu (s)) \}}} [   [ f (\uparrow (\mu (s))) = i ]   ] [   [ f (\mu^ {\prime} (s)) = i ^ {\prime} ]   ] \prod_ {u \in \hat {\mathcal {J}} (s)} \hat {\tau} _ {f (\uparrow (u)), f (u)} (u) \hat {\kappa} _ {f (u)} (u).
$$
We have the following recurrence relations for these potentials. Suppose we have an internal vertex  $s \in \mathcal{D}^{\dagger}$  and  $i, i' \in \{0,1\}$ . If  $s \in \mathcal{D}^{\circ}$  we have:
$$
\Psi_ {i} (s) = \sum_ {i ^ {\prime \prime} \in \{0, 1 \}} \Omega_ {i, i ^ {\prime \prime}} (\nabla (s)) \Psi_ {i ^ {\prime \prime}} (\triangleleft (s)) \Psi_ {i ^ {\prime \prime}} (\triangleright (s)).
$$
If, instead,  $s \in \mathcal{D}^{\bullet}$  then, by letting  $s' := \triangleleft(s)$ ,  $s'' := \triangleright(s)$  if  $\triangleleft(s) \in \mathcal{D}^{\bullet}$  and  $s' := \triangleright(s)$ ,  $s'' := \triangleleft(s)$  otherwise, we have:
$$
\Omega_ {i, i ^ {\prime}} (s) = \sum_ {i ^ {\prime \prime} \in \{0, 1 \}} \Omega_ {i, i ^ {\prime \prime}} (\nabla (s)) \Omega_ {i ^ {\prime \prime}, i ^ {\prime}} (s ^ {\prime}) \Psi_ {i ^ {\prime \prime}} (s ^ {\prime \prime}).
$$
If, on a trial  $t$ , we perform the operation  $\mathrm{INSERT}_t(\mathcal{I})$  or change the value of  $\lambda(u_t)$  these recurrence relations can be used (in conjunction with the tree rotations) to update the potentials in logarithmic time.
Now that we have defined our potentials we will show how to use them to compute  $\tilde{\Lambda} (\mathcal{I},\lambda ,\hat{u})$  in logarithmic time. To do this we recursively define the following quantities for  $i\in \{0,1\}$ . Let  $\omega_{i}(r(\mathcal{D}))\coloneqq 1$ . Given an internal vertex  $s\in \mathcal{D}^{\circ}$  we define:
$$
\omega_ {i} (\nabla (s)) := \omega_ {i} (s) ; \quad \omega_ {i} ^ {\prime} (\nabla (s)) := \Psi_ {i} (\triangleleft (s)) \Psi_ {i} (\triangleright (s))
$$
$$
\omega_ {i} (\triangleleft (s)) := \Psi_ {i} (\triangleright (s)) \sum_ {i ^ {\prime} \in \{0, 1 \}} \omega_ {i ^ {\prime}} (s) \Omega_ {i ^ {\prime}, i} (\nabla (s)); \omega_ {i} (\triangleright (s)) := \Psi_ {i} (\triangleleft (s)) \sum_ {i ^ {\prime} \in \{0, 1 \}} \omega_ {i ^ {\prime}} (s) \Omega_ {i ^ {\prime}, i} (\nabla (s)).
$$
Given an internal vertex  $s \in \mathcal{D}^{\bullet}$  define  $s' := \triangleleft(s)$ ,  $s'' := \triangleright(s)$  if  $\triangleleft(s) \in \mathcal{D}^{\bullet}$  and  $s' := \triangleright(s)$ ,  $s'' := \triangleleft(s)$  otherwise. Then:
$$
\omega_ {i} (\nabla (s)) := \omega_ {i} (s) \quad ; \quad \omega_ {i} ^ {\prime} (\nabla (s)) := \Psi_ {i} (s ^ {\prime \prime}) \sum_ {i ^ {\prime} \in \{0, 1 \}} \Omega_ {i, i ^ {\prime}} (s ^ {\prime}) \omega_ {i ^ {\prime}} ^ {\prime} (s)
$$
$$
\omega_ {i} (s ^ {\prime}) := \sum_ {i ^ {\prime} \in \{0, 1 \}} \omega_ {i ^ {\prime}} (s) \Omega_ {i ^ {\prime}, i} (s) \Psi_ {i} (s ^ {\prime \prime}); \quad \omega_ {i} ^ {\prime} (s ^ {\prime}) := \omega_ {i} ^ {\prime} (s)
$$
$$
\omega_ {i} (s ^ {\prime \prime}) := \sum_ {i ^ {\prime}, i ^ {\prime \prime} \in \{0, 1 \}} \omega_ {i ^ {\prime}} (s) \Omega_ {i ^ {\prime}, i} (\nabla (s)) \omega_ {i ^ {\prime \prime}} ^ {\prime} (s) \Omega_ {i, i ^ {\prime \prime}} (s ^ {\prime}).
$$
For  $s \in \mathcal{D}^{\circ}$ ,  $\omega_{i}'(s)$  is not required and hence is arbitrary. We inductively compute the values  $\{\omega_{i}(s), \omega_{i}'(s) \mid i \in \{0,1\}\}$  for all  $s$  in the path from  $r(\mathcal{D})$  to the unique leaf  $\hat{s} \in \mathcal{D}^{\star}$  in which  $\mu(\hat{s}) = \hat{u}$ . We then have  $\tilde{\Lambda}(\mathcal{J}, \lambda, \hat{u}) = \omega_{1}(\hat{s})$ .
Since this is known methodology we do not include a proof in this paper and direct the reader to [7].
E.1 Theorem 3.3
This theorem is proved in appendices B to D and the theorems therein.
E.2 Theorem 3.6
For all  $x\in \mathcal{C}$  define  $\hat{\gamma} (x)\coloneqq \gamma (x,\hat{y},\mathcal{X})$
Choose a set  $S \subseteq \mathcal{C}$  in which for all  $t \in [T]$  there exists  $x \in S$  with  $\Delta(x, x_t) < \hat{\gamma}(x)/3c$ . For all trials  $t$  let  $S_t$  be the set of all contexts  $x \in S$  in which there exists  $s \in [t]$  with  $\Delta(x, x_s) < \hat{\gamma}(x)/3c$ .
Now consider a trial  $t \in [T] \setminus \{1\}$  in which  $\hat{y}(x_t) \neq \hat{y}(x_{n(t)})$  and choose  $x \in S$  with  $\Delta(x, x_t) < \hat{\gamma}(x)/3c$ .
Assume, for contradiction, that  $x \in S_{t-1}$ . Then there exists  $s \in [t-1]$  with  $\Delta(x, x_s) < \hat{\gamma}(x)/3c$  so that by the triangle inequality we have:
$$
\Delta \left(x _ {t}, x _ {s}\right) \leq \Delta \left(x, x _ {s}\right) + \Delta \left(x, x _ {t}\right) <   2 \hat {\gamma} (x) / 3 c
$$
which implies that  $\Delta (x_{t},x_{n(t)}) < 2\hat{\gamma} (x) / 3$  . By the triangle inequality we then have that:
$$
\Delta (x, x _ {n (t)}) \leq \Delta (x _ {t}, x _ {n (t)}) + \Delta (x, x _ {t}) <   2 \hat {\gamma} (x) / 3 + \hat {\gamma} (x) / 3 c \leq 3 \hat {\gamma} (x) / 3 = \hat {\gamma} (x)
$$
Since  $\Delta (x,x_{t}) < \hat{\gamma} (x)$  we have  $y(x) = y(x_{t})$  and hence that  $y(x)\neq y(x_{n(t)})$ . But this contradicts the fact that  $\Delta (x,x_{n(t)}) < \hat{\gamma} (x)$ .
We have hence shown that  $x \notin S_{t-1}$ . Since  $x \in S_t$  we then have that  $|\mathcal{S}_t| \geq |\mathcal{S}_{t-1}|$ . Since  $|\mathcal{S}_1| \geq 1$  this implies that:
$$
\Phi (\boldsymbol {y}) = 1 + \sum_ {t \in [ T ] \backslash \{1 \}} \llbracket \hat {y} (x _ {t}) \neq \hat {y} (x _ {n (t)}) \rrbracket \leq | \mathcal {S} _ {T} | \leq | \mathcal {S} |
$$
E.3 Theorem 3.9
Let  $\epsilon$  be such that:
$$
\lim  _ {\delta \rightarrow 0} \frac {1}{\delta} \int_ {x \in \mathcal {M} (\hat {y}, \mu , 2 \epsilon , \delta)} 1 \leq 2 \alpha (\hat {y}, \mu) \quad ; \quad \lim  _ {\delta \rightarrow 0} \frac {1}{\delta} \int_ {x \in \mathcal {M} (\hat {y}, \mu , 2 \epsilon , \delta)} \mu (x) \leq 2 \tilde {\alpha} (\hat {y}, \mu) \tag {5}
$$
Since we are only interested in the behaviour as  $q \to \infty$  assume, without loss of generality, that  $\sqrt{d} / q < \epsilon / 3$ . Choose  $\lambda > 0$  and  $\lambda' > 0$  sufficiently small for this proof to work. For all  $x \in \mathcal{G}_q^d$  let  $\mathcal{H}(x)$  be the set of points  $x' \in [0,1]^d$  such that  $x$  is the nearest neighbour (or one of them if the nearest neighbour is not unique) of  $x'$  in  $\mathcal{G}_q^d$ . Let  $\mathcal{L}$  be the set of all  $x \in \mathcal{G}_q^d$  for which there exists  $x', x'' \in \mathcal{H}(x) \cap \mathcal{E}(\mu, \epsilon)$  with  $\hat{y}(x') \neq \hat{y}(x'')$ . Note that for all  $x' \in \mathcal{L}$  we have  $\mathcal{H}(x') \subseteq \mathcal{M}(\hat{y}, \mu, 2\epsilon, \sqrt{d} / q)$  so:
$$
\frac {q}{\sqrt {d}} \int_ {x \in \mathcal {M} (\hat {y}, \mu , 2 \epsilon , \sqrt {d} / q)} 1 \geq \frac {q}{\sqrt {d}} \sum_ {x ^ {\prime} \in \mathcal {L}} \int_ {x \in \mathcal {H} (x ^ {\prime})} 1 = \frac {q}{\sqrt {d}} | \mathcal {L} | q ^ {- d} = \frac {1}{q ^ {d - 1} \sqrt {d}} | \mathcal {L} |
$$
By considering the limit of this inequality as  $q \to \infty$ , and noting that  $d$  is being treated as a constant, we then have, by Equation (5), that:
$$
\left| \mathcal {L} \right| \in \mathcal {O} \left(\alpha (\hat {y}, \mu) q ^ {d - 1}\right) \tag {6}
$$
$$
p := \sum_ {x ^ {\prime} \in \mathcal {L}} \int_ {x \in \mathcal {H} (x ^ {\prime})} \mu (x)
$$
Since  $\mathcal{H}(x') \subseteq \mathcal{M}(\hat{y}, \mu, 2\epsilon, \sqrt{d}/q)$  for all  $x' \in \mathcal{L}$ , we have:
$$
\frac {q}{\sqrt {d}} p \leq \frac {q}{\sqrt {d}} \int_ {x \in \mathcal {M} (\hat {y}, \mu , 2 \epsilon , \sqrt {d} / q)} \mu (x)
$$
$$
p \in \mathcal {O} (\tilde {\alpha} (\hat {y}, \mu) / q) \tag {7}
$$
Let  $\mathcal{D}$  be the set of all  $x\in \mathcal{G}_q^d$  such that there exists  $x^{\prime}\in \mathcal{H}(x)$  with  $\mu (x)\neq 0$ . Now define  $\hat{y}':[0,1]^d\to [K]$  such that for all  $x\in [0,1]^d$  we have:
- If  $x \in \mathcal{D} \setminus \mathcal{L}$  then  $\hat{y}'(x)$  is the unique  $a \in [K]$  such that there exists  $x' \in \mathcal{H}(x)$  with  $\mu(x') \neq 0$  and  $a = \hat{y}(x')$ . Note that if there existed more than one such  $a$  then we would have  $x \in \mathcal{L}$  which is a contradiction.
- If  $x \notin \mathcal{D} \setminus \mathcal{L}$  then  $\hat{y}'(x) = \hat{y}'(\hat{x})$  where  $\hat{x}$  is the nearest neighbour of  $x$  in  $\mathcal{D} \setminus \mathcal{L}$ .
Let  $\mathcal{A}$  be a finite set of points in  $\mathbb{R}^d$  such that for all  $x\in \mathbb{R}^d$  with  $\Delta (x,0)\leq 1$  there exists  $x^{\prime}\in \mathcal{A}$  with  $\Delta (x,x^{\prime}) < \lambda$ . Define:
$$
\mathcal{A}^{\prime}:= \bigcup_{i\in [\lceil \log (qd)\rceil ]}\left\{2^{i}x / q  |  x\in \mathcal{A}\right\}
$$
Note that:
$$
\left| \mathcal {A} ^ {\prime} \right| \in \mathcal {O} (\ln (q)) \tag {8}
$$
We now show that for all  $x\in \mathbb{R}^d$  with  $1 / q\leq \Delta (x,0)\leq d$  there exists  $x''\in \mathcal{A}'$  with:
$$
\Delta (x, x ^ {\prime \prime}) <   2 \Delta (x, 0) \lambda \tag {9}
$$
To show this choose any such  $x$  and let  $i \in \mathbb{N}$  be such that  $2^{i - 1} / q \leq \Delta(x,0) < 2^i / q$ . By the assumption on  $x$  we have that  $i \in [\lceil \log(qd) \rceil]$ . Since  $\Delta(xq2^{-i},0) < 1$  choose  $x' \in \mathcal{A}$  such that  $\Delta(xq2^{-i},x') < \lambda$ . Then we have:
$$
\Delta (x, 2 ^ {i} x ^ {\prime} / q) = (2 ^ {i} / q) \Delta (x q 2 ^ {- i}, x ^ {\prime}) <   (2 ^ {i} / q) \lambda \leq 2 \Delta (x, 0) \lambda
$$
so, since  $2^{i}x^{\prime} / q\in \mathcal{A}^{\prime}$  , we have proved that Equation (9) is true.
We now let  $S'$  be a finite set of points in  $\mathbb{R}^d$  such that for all  $x \in [0,1]^d$  there exists some  $x' \in S'$  with  $\Delta(x,x') < \lambda' \epsilon$ . Now define:
$$
\mathcal {S} := \mathcal {L} \cup \mathcal {S} ^ {\prime} \cup \bigcup_ {x \in \mathcal {L}} \left\{x ^ {\prime} + x \mid x ^ {\prime} \in \mathcal {A} ^ {\prime} \right\}
$$
Let  $\mathcal{X} \coloneqq \{x_t \mid t \in [T]\}$ . Take any  $x \in \mathcal{X}$ . We now show that there exists  $x^{\dagger} \in S$  with  $\Delta(x, x^{\dagger}) < \gamma(x^{\dagger}, \hat{y}', \mathcal{X}) / 3c$ . We have three cases:
- First consider the case that  $\Delta(x, x') > \epsilon/3$ . Let  $x'$  be the nearest neighbour of  $x$  in  $[0,1]^d$  with  $\hat{y}'(x) \neq \hat{y}'(x')$ . Choose  $x^\dagger \in S'$  such that  $\Delta(x, x^\dagger) < \lambda' \epsilon$ . Since  $\Delta(x, x^\dagger) < \epsilon/3$  we must have  $\hat{y}'(x^\dagger) = \hat{y}'(x)$ . Let  $x''$  be the nearest neighbour of  $x^\dagger$  in  $\mathcal{X}$  with  $\hat{y}'(x'') \neq \hat{y}'(x^\dagger)$ . Since  $\hat{y}'(x^\dagger) = \hat{y}'(x)$  we must have that  $\hat{y}'(x'') \neq \hat{y}'(x)$  so that  $\Delta(x, x'') > \epsilon/3$ . By the triangle inequality we then have:
$$
\epsilon / 3 <   \Delta (x, x ^ {\prime \prime}) \leq \Delta (x, x ^ {\dagger}) + \Delta (x ^ {\dagger}, x ^ {\prime \prime}) <   \lambda^ {\prime} \epsilon + \Delta (x ^ {\dagger}, x ^ {\prime \prime}) = \lambda^ {\prime} \epsilon + \gamma (x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X})
$$
Hence  $\gamma (x^{\dagger},\hat{y}^{\prime},\mathcal{X}) > (1 / 3 - \lambda^{\prime})\epsilon$  so that:
$$
\Delta (x, x ^ {\dagger}) <   \lambda^ {\prime} \epsilon <   \frac {\lambda^ {\prime}}{1 / 3 - \lambda^ {\prime}} \gamma \left(x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X}\right) <   \gamma \left(x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X}\right) / 3 c
$$
- Now consider the case that  $x \in \mathcal{L}$ . In this case we trivially have the result with  $x^{\dagger} \coloneqq x$ .
- Finally consider the case that  $x \notin \mathcal{L}$  and  $\Delta(x, x') \leq \epsilon / 3$ . Let  $x'$  be the nearest neighbour of  $x$  in  $[0,1]^d$  with  $\hat{y}'(x) \neq \hat{y}'(x')$ . Let  $\hat{x}$  and  $\hat{x}'$  be the nearest neighbours of  $x$  and  $x'$  in  $\mathcal{D} \setminus \mathcal{L}$  respectively. Note that by definition of  $\hat{y}'$  we have  $\hat{y}'(\hat{x}) = \hat{y}'(x)$  and  $\hat{y}'(\hat{x}') = \hat{y}'(x')$ . By definition of  $\mathcal{D}$  we must have  $x \in \mathcal{D}$ , so since  $x \notin \mathcal{L}$  we have  $\hat{x} = x$ . Noting that  $\Delta(x', \hat{x}') \leq \Delta(x', \hat{x})$  we must then have that  $\Delta(x', \hat{x}') \leq \Delta(x', x)$  which means, by the triangle inequality, that  $\Delta(x, \hat{x}') \leq 2\Delta(x, x')$ . Since  $x, \hat{x}' \in \mathcal{D}$  choose  $z \in \mathcal{H}(x)$  and  $z' \in \mathcal{H}(\hat{x}')$  such that  $\mu(z), \mu(z') \neq 0$ . Since  $x, \hat{x}' \in \mathcal{D} \setminus \mathcal{L}$  we have:
$$
\hat {y} (z) = \hat {y} ^ {\prime} (z) = \hat {y} ^ {\prime} (x) \neq \hat {y} ^ {\prime} (\hat {x} ^ {\prime}) = \hat {y} ^ {\prime} (z ^ {\prime}) = \hat {y} (z ^ {\prime})
$$
By the triangle inequality and above we have:
$$
\Delta (z, z ^ {\prime}) \leq \Delta (z, x) + \Delta (x, \hat {x} ^ {\prime}) + \Delta (\hat {x} ^ {\prime}, z ^ {\prime}) \leq 2 \Delta (x, x ^ {\prime}) + \sqrt {d} / q \leq \epsilon \tag {10}
$$
so since  $\mu (z),\mu (z^{\prime})\neq 0$  we must have that the straight line from  $z$  to  $z^{\prime}$  is entirely contained in  $\mathcal{E}(\mu ,\epsilon /2)$ . Since  $\hat{y} (z)\neq \hat{y} (z^{\prime})$  we can then choose some  $z^{\dagger}$  in the line from  $z$  to  $z^{\prime}$  that is on the decision boundary of  $\hat{y}$  (i.e. any open set around  $z^{\dagger}$  contains some  $\tilde{z}$  with  $\hat{y} (\tilde{z})\neq \hat{y} (z^{\dagger}))$ ). Since there exists an open set around  $z^{\dagger}$  that is entirely contained in  $\mathcal{E}(\mu ,\epsilon)$
we must now have, by definition of  $\mathcal{L}$ , that there exists  $\hat{z} \in \mathcal{L}$  such that  $z^{\dagger} \in \mathcal{H}(\hat{z})$ . By the triangle inequality and Equation (10) we have:
$$
\begin{array}{l} \Delta (x, \hat {z}) \leq \Delta (x, z) + \Delta (z, z ^ {\dagger}) + \Delta (z ^ {\dagger}, \hat {z}) \leq \Delta (z, z ^ {\dagger}) + \sqrt {d} / q \leq \Delta (z, z ^ {\prime}) + \sqrt {d} / q \\ \leq 2 \Delta \left(x, x ^ {\prime}\right) + 2 \sqrt {d} / q \tag {11} \\ \end{array}
$$
Since  $x \in \mathcal{D} \backslash \mathcal{L}$  we have  $\hat{y}'(\tilde{z}) = \hat{y}'(x)$  for all  $\tilde{z} \in \mathcal{H}(x)$  and hence we must have  $x' \notin \mathcal{H}(x)$  so that  $\Delta(x, x') \geq \sqrt{d} / (2q)$ . By Equation (11) this means that:
$$
\Delta \left(x, x ^ {\prime}\right) \geq \Delta \left(x, \hat {z}\right) / 6 \tag {12}
$$
By Equation (9) choose  $z'' \in \mathcal{A}'$  such that:
$$
\Delta (x - \hat {z}, z ^ {\prime \prime}) <   2 \Delta (x - \hat {z}, 0) \lambda \tag {13}
$$
and define  $x^{\dagger} = \hat{z} + z''$ . Since  $\hat{z} \in \mathcal{L}$  we have  $x^{\dagger} \in \mathcal{S}$  as required. Note that by equations (12) and (13) we have:
$$
\Delta (x, x ^ {\dagger}) = \Delta (x - \hat {z}, z ^ {\prime \prime}) <   2 \Delta (x, \hat {z}) \lambda \leq 1 2 \Delta (x, x ^ {\prime}) \lambda \tag {14}
$$
Since  $2\lambda < 1/6$  we now have, from equations (12) and (14), that  $\Delta(x,x^{\dagger}) < \Delta(x,x')$  so that  $\hat{y}'(x) = \hat{y}'(x^{\dagger})$ . Let  $x''$  be the nearest neighbour of  $x^{\dagger}$  in  $\mathcal{X}$  with  $\hat{y}'(x'') \neq \hat{y}'(x^{\dagger})$ . Since  $\hat{y}'(x^{\dagger}) = \hat{y}'(x)$  we must have that  $\hat{y}'(x'') \neq \hat{y}'(x)$  so that  $\Delta(x,x'') \geq \Delta(x,x')$ . By the triangle inequality and Equation (14) we then have:
$$
\begin{array}{l} \Delta (x, x ^ {\prime}) \leq \Delta (x, x ^ {\prime \prime}) \leq \Delta (x, x ^ {\dagger}) + \Delta (x ^ {\dagger}, x ^ {\prime \prime}) <   1 2 \Delta (x, x ^ {\prime}) \lambda + \Delta (x ^ {\dagger}, x ^ {\prime \prime}) \\ = 1 2 \Delta (x, x ^ {\prime}) \lambda + \gamma (x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X}) \\ \end{array}
$$
Hence  $\gamma (x^{\dagger},\hat{y}^{\prime},\mathcal{X}) > (1 - 12\lambda)\Delta (x,x^{\prime})$  so that by Equation (14) we have:
$$
\Delta (x, x ^ {\dagger}) <   1 2 \Delta (x, x ^ {\prime}) \lambda <   \frac {1 2 \lambda}{1 - 1 2 \lambda} \gamma (x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X}) <   \gamma (x ^ {\dagger}, \hat {y} ^ {\prime}, \mathcal {X}) / 3 c
$$
Let  $\pmb{y}^{\prime} \in [K]^{T}$  be such that  $y_{t}^{\prime} \coloneqq \hat{y}^{\prime}(x_{t})$  for all  $t \in [T]$ . We have shown that for all  $x \in \mathcal{X}$  there exists  $x^{\dagger} \in S$  with  $\Delta(x, x^{\dagger}) < \gamma(x^{\dagger}, \hat{y}^{\prime}, \mathcal{X}) / 3c$ . By equations (6) and (8) we have that:
$$
| \mathcal {S} | \in \mathcal {O} (| \mathcal {L} | \ln (q)) \subseteq \mathcal {O} (\alpha (\hat {y}, \mu) q ^ {d - 1} \ln (q)) \subseteq \tilde {\mathcal {O}} (\alpha (\hat {y}, \mu) q ^ {d - 1})
$$
Invoking Theorem 3.6 then gives us:
$$
\Phi (\boldsymbol {y} ^ {\prime}) \in \mathcal {O} (\alpha (\hat {y}, \mu) q ^ {d - 1})
$$
so by Theorem 3.3 we have:
$$
\mathbb {E} \left[ R \left(\boldsymbol {y} ^ {\prime}\right) \right] \in \tilde {\mathcal {O}} \left(\left(\rho + \frac {\Phi \left(\boldsymbol {y} ^ {\prime}\right)}{\rho}\right) \sqrt {K T}\right) \subseteq \tilde {\mathcal {O}} \left((1 + \alpha (\hat {y}, \mu)) q ^ {\frac {d - 1}{2}} \sqrt {K T}\right) \tag {15}
$$
$$
R (\boldsymbol {y}) - R (\boldsymbol {y} ^ {\prime}) = \sum_ {t \in [ T ]} \left(\ell_ {t, y _ {t}} - \ell_ {t, y _ {t} ^ {\prime}}\right) = \sum_ {t \in [ T ]} \left(\ell_ {t, \hat {y} \left(z _ {t}\right)} - \ell_ {t, \hat {y} ^ {\prime} \left(x _ {t}\right)}\right) \leq \sum_ {t \in [ T ]} \llbracket \hat {y} (z _ {t}) \neq \hat {y} ^ {\prime} (x _ {t}) \rrbracket
$$
But  $\hat{y}(z_t) \neq \hat{y}'(x_t)$  implies that  $x_t \notin \mathcal{D} \setminus \mathcal{L}$  so since  $x_t \in \mathcal{D}$  we must have  $x_t \in \mathcal{L}$  which happens with probability  $p$  and hence, by Equation (7), we have:
$$
\mathbb {E} \left[ R (\boldsymbol {y}) - R \left(\boldsymbol {y} ^ {\prime}\right) \right] \leq p T \in \mathcal {O} \left(T \tilde {\alpha} (\hat {y}, \mu) / q\right) \tag {16}
$$
Combining equations (15) and (16) gives us:
$$
\mathbb {E} [ R (\boldsymbol {y}) ] \in \tilde {\mathcal {O}} ((1 + \alpha (\hat {y}, \mu)) q ^ {\frac {d - 1}{2}} \sqrt {K T} + T \tilde {\alpha} (\hat {y}, \mu) / q)
$$
Since  $q \coloneqq \left\lceil (T / K)^{1 / (d + 1)}\right\rceil$  we have now shown that:
$$
\mathbb {E} [ R (\boldsymbol {y}) ] \in \tilde {\mathcal {O}} \left(\left(1 + \alpha (\hat {y}, \mu) + \tilde {\alpha} (\hat {y}, \mu)\right) T ^ {\frac {d}{d + 1}} K ^ {\frac {1}{d + 1}}\right)
$$
E.4 Theorem B.1
For every trial  $t\in [T]$  define: