\begin{tikzpicture}[
    level 1/.style = {sibling distance=6cm},
    level 2/.style = {sibling distance=3cm},
    level 3/.style = {sibling distance=1.5cm},
    level distance          = 1cm,
    edge from parent/.style = {draw},
    scale=1.2
    ]

    \node {$\frac{x}{x+1}$}
    child{
      node {$\frac{x}{x+2}$}
      child{
        node {$\frac{x}{x+3}$}
        child{
          node {$\frac{x}{x+4}$}
        }
        child{
          node {$\frac{x+3}{x+4}$}
        }
      }
      child{
        node {$\frac{x+2}{x+3}$}
        child{
          node {$\frac{x^2+2x}{x^2+4x+2}$}
        }
        child{
          node {$\frac{x^2+3x}{x^2+4x+2}$}
        }
      }
    }
    child{
      node {$\frac{x+1}{x+2}$}
      child{
        node {$\frac{x^2+x}{x^2+3x+1}$}
        child{
          node {$\frac{x^2+x}{x^2+4x+2}$}
        }
        child{
          node {$\frac{x^2+3x+1}{x^2+4x+2}$}
        }
      }
      child{
        node {$\frac{x^2+2x}{x^2+3x+1}$}
        child{
          node {$\frac{x^2+2x}{x^2+4x+3}$}
        }
        child{
          node {$\frac{x^2+3x+1}{x^2+4x+3}$}
        }
      }
    };
\end{tikzpicture}

        \caption{The first four levels of the Farey polynomial tree.}\label{fig:FareyPoly}
    \end{center}
\end{figure}

We label each vertex in the tree with notation inspired by continued fractions. For $a_i \in \mathbb{Z}^+$:
\begin{equation}\label{eqn: vertex labels}
[a_1,a_2,\ldots,a_k]_x = \Phi_1^{a_1-1} \circ \Phi_0 \circ \Phi_1^{a_2-1} \circ \Phi_0 \circ \cdots \circ \Phi_1^{a_{k-1}-1}\circ \Phi_0 \circ \Phi_1^{a_k-1} \left( \frac{1}{1}\right)
\end{equation}

In this way the root of our tree is the vertex $[2]_x=[1,1]_x$, and in general $[a_1,\ldots,a_{k-1},a_k+1]_x=[a_1,\ldots,a_{k-1},a_k,1]_x$. Observe also that
\begin{align*}
    \Phi_0\left( [a_1,\ldots,a_k]_x\right) &= [1,a_1,\ldots,a_k]_x\\
    \Phi_1\left( [a_1,\ldots,a_k]_x\right) &= [a_1+1,a_2,\ldots,a_k]_x\\
\end{align*}The tree we present here has some very nice properties. We highlight some of them with the following two theorems; by ``subtree at vertex $[a_1,\ldots,a_k]_x$" we mean the tree generated by $\Phi_1$ and $\Phi_0$ rooted at vertex $[a_1,\ldots,a_k]_x$.

We have the following two main theorems.

\begin{theorem}\label{th:cfs}
For a fixed value of $x$, we consider the function which maps the tree to the set of values given by evaluating every vertex at this value of $x$.
    \begin{enumerate}
        \item Setting a value $x>0$ injectively maps the tree to a dense subset of $(0,1)$.
        \item Setting a value $x>0$ bijectively maps the tree to $\mathbb{Q} \cap (0,1)$ if and only if $x \in \mathbb{Z}^+$.
    \end{enumerate}
\end{theorem}
Note that from (1) in Theorem \ref{th:cfs} it follows that the rational functions in the tree don't intersect on $(0,\infty)$.

\begin{theorem}\label{th:dense}
    For the subtree $\Omega$ rooted at any vertex $[a_1,\ldots,a_k]_x$, if we set
    \[R=\left\{ x \, | \, \textrm{there is a } p(x)/q(x) \in \Omega \textrm{ for which }q(x)=0\right\}\]
    then $R$ is dense in $(-\infty,-1]$.
\end{theorem}

We begin \Cref{sec:cfs} with a derivation of this tree. For Theorem \ref{th:cfs} we use the close relationship between the tree and a family of continued fractions explained in Section \ref{sec:cfresults}. Theorem \ref{th:dense} is proven in \Cref{sec:dense} by inductively selecting a path in the tree whose vertices have poles converging to an arbitrary $\alpha<-1$; comments are included regarding the possibility of expanding this result to $\alpha \in (-1,0)$. A similar tree derived from the theory of backwards continued fractions is presented in \Cref{sec:other trees}.
We will see a similar behaviour in view of Theorem \ref{th:cfs} and a very different one in view of Theorem \ref{th:dense} for this tree.

\section{Forward Farey Tree}\label{sec:cfs}
\subsection{Background and Definition}
The \textit{Gauss map} $T:[0,1) \mapsto [0,1)$, given by
\[T(t) = \begin{cases}
    \frac{1}{t} - \floor{\frac{1}{t}} & t\neq 0\\
    0 & t=0,
\end{cases}\]
may be used to generate the \textit{regular continued fraction} expansion of $t$:
\[ t = \cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\ddots}}},\]
where $a_i =a(T^{i-1}(t))= \floor{1/T^{i-1}(t)}$. This map is the `sped-up' version of the \textit{Farey map} $F$, given by
\[ F(t) = \begin{cases}
    F_0(t) = \frac{1-t}{t} & x \geq 1/2\\
    F_1(t) = \frac{t}{1-t} & x \leq 1/2
\end{cases}\]
with the observation that
\begin{equation}\label{eqn: RCF functional}T(t) = F_0 \circ F_1 ^{a(t)-1} (t).\end{equation}
Note that $a(t)-1=\min(n\in\mathbb{N}_0 : T^n(t)\in [\frac{1}{2},1])$ i.e. it is first hitting time of $x$ to the interval $[\frac{1}{2},1]$ (possibly zero) and $T$ can be understood as the composition of $F_0$ and the induced transformation on this interval (where a return time of zero is allowed).

A generalization of regular continued fractions, $N$-continued fractions, allow for all numerators to be some fixed $N \in \mathbb{Z}\setminus\{0\}$. These were first studied in  \cite{AW11,BGRKWY208} and later in many other papers such as \cite{CK,DO18,DKW13,JKN,KL} . Most papers study positive values of $N$ and in the remainder of this section we will also take $N>0$. For negative $N$, there is a relation with the backward continued fractions in Section \ref{sec:other trees}. One of the key differences with regular continued fractions is that there is not a unique continued fraction for every $t\in(0,1)$. For some studied algorithms generating $N$-continued fractions it is proven that there are quadratic irrationals without periodic expansion (and even rationals with aperiodic expansions), see \cite{KL}. For the greedy $N$-continued fractions, which we have here, there is strong numeric evidence that there are quadratic irrationals with an aperiodic expansion (see \cite{DKW13}), though this problem is still open. The greedy $N$-continued fractions can be generated with a similar map as the Gauss map namely by \[ T_N(t) = \begin{cases}
   \left(\frac{N}{t}-N\right) - \floor{\frac{N}{t}-N} & t \neq 0\\
     0 & t=0,
\end{cases}\]
which generates
\[ t= \cfrac{N}{N+(a_1-1)+\cfrac{N}{N+(a_2-1)+\cfrac{N}{N+(a_3-1)+\ddots}}},\]
where now $a_i=a(N,t)= \floor{N/T_N^{i-1}(t)-N}+1$. Then $T_N(x)$ is a sped-up version of the associated $N$-Farey map
\[F_N(t) = \begin{cases}
    F_{N,0}(t) = \frac{N(1-t)}{t} &  t \geq \frac{N}{N+1} \\
    F_{N,1}(t) = \frac{Nt}{N-t} & t \leq \frac{N}{N+1}
\end{cases}\]
with the observation that
\begin{equation}\label{eqn: N-CF functional}T_N(t) = F_{N,0} \circ F_{N,1}^{a(N,t)-1}(t).\end{equation}
See Figure \ref{fig:Fareymap} (right) for an example of $N=2$. It is important to point out that this definition of $a_i=a(N,t)$ is not typical: more typical, e.g. in the above references for N-continued fractions, is that $a(N,t)=\floor{N/t}$ and $T_N(t)$ is equivalent but without the `$-N$' both inside and outside the integer part function. Our definition here differs only by an integer constant for $a$, is identical for $T_N$, gives a similar presentation between \Cref{eqn: RCF functional} and (\ref{eqn: N-CF functional}), and is what we will now generalize.

Note that from a dynamical point of view, there is no necessity of taking $N\in\mathbb{Z}^+$ in the definition of the map $F_N(t)$. To this end, let us define a map $F_x:[0,1]\rightarrow[0,1]$ with $x\in(0,\infty)$\footnote{note that for other values of $x$, we have that $\frac{x}{x+1}$ is not in $[0,1]$  and the map cannot be used to generate continued fractions.} as
\begin{equation}\label{eq:F_x}
  F_x(t)=
\begin{cases}
F_{x,0}(t)=\frac{x(1-t)}{t}   & t \geq \frac{x}{x+1}\\[1ex]
F_{x,1}(t)=\frac{xt}{x-t}, & t \leq \frac{x}{x+1},
\end{cases}
\end{equation}
see Figure \ref{fig:Fareymap} (left) for $x=1/3$.
\begin{figure}[ht]
		\centering

		\subfigure{\begin{tikzpicture}[scale=5]
				\draw[white] (-0.25,0)--(1,0);
				\draw(0,0)node[below]{\small $0$}--(1,0)node[below]{\small $1$}--(1,1)--(0,1)node[left]{\small $1$}--(0,0);

				\draw[thick, blue, smooth, samples =20, domain=1/4:1] plot(\x,{1/(3*\x)-1/3});
				\draw[thick,blue, smooth, samples =20, domain=0:1/4] plot(\x,{\x/(1-3*\x)});

				\draw[dotted](1/4,0)node[below]{\small $\frac{1}{4}$}--(1/4,1);

		\end{tikzpicture}

Let us first define the tree of interest which we will call the \textit{Farey polynomial tree} (an explanation of the derivation of this tree will be given in the beginning of \Cref{sec:cfs}). On the nodes we have rational functions $v(x)=p(x)/q(x)$. The root of the tree is $\frac{x}{x+1}$ and the two offspring of each node are found using the following two functions:
\begin{equation}\label{eqn: Phi}\begin{split}
\Phi_0\left( \frac{p(x)}{q(x)}\right) &= \begin{cases}
\frac{xq(x)}{xq(x)+p(x)} & p(0)\neq 0\\
\frac{q(x)}{q(x)+p(x)/x}& p(0)=0\end{cases}\\
\\
\Phi_1\left( \frac{p(x)}{q(x)}\right) &= \begin{cases}
\frac{xp(x)}{xq(x)+p(x)} & p(0)\neq 0\\
\frac{p(x)}{q(x)+p(x)/x}& p(0)=0.\end{cases}\end{split}\end{equation}

See Figure \ref{fig:FareyPoly} for the first few levels. These two functions are the inverse branches of a generalized Farey map and the tree generalizes the classical Farey tree which is found for $x=1$. Note that we define it by using inverse images of the Farey map and not by using mediants of neighboring fractions, but the trees are intimately related (see \cite{BI09}). The Farey tree is well studied and appears in many different branches of mathematics (see for example~\cite{AK22,BBDG24,BDM21,DKS25,DS07,KO86,LRS17} and the references therein). Curiously, Farey himself (a geologist) did not publish anything significant on the matter. It was Cauchy who proved one of the basic ideas of the Farey sequence and attributed it to Farey (see \cite[Notes on Chapter~3]{HW79}).

\begin{figure}[ht]
    \begin{center}

\begin{tikzpicture}[
    level 1/.style = {sibling distance=6cm},
    level 2/.style = {sibling distance=3cm},
    level 3/.style = {sibling distance=1.5cm},
    level distance          = 1cm,
    edge from parent/.style = {draw},
    scale=1.2
    ]

    \node {$\frac{x}{x+1}$}
    child{
      node {$\frac{x}{x+2}$}
      child{
        node {$\frac{x}{x+3}$}
        child{
          node {$\frac{x}{x+4}$}
        }
        child{
          node {$\frac{x+3}{x+4}$}
        }
      }
      child{
        node {$\frac{x+2}{x+3}$}
        child{
          node {$\frac{x^2+2x}{x^2+4x+2}$}
        }
        child{
          node {$\frac{x^2+3x}{x^2+4x+2}$}
        }
      }
    }
    child{
      node {$\frac{x+1}{x+2}$}
      child{
        node {$\frac{x^2+x}{x^2+3x+1}$}
        child{
          node {$\frac{x^2+x}{x^2+4x+2}$}
        }
        child{
          node {$\frac{x^2+3x+1}{x^2+4x+2}$}
        }
      }
      child{
        node {$\frac{x^2+2x}{x^2+3x+1}$}
        child{
          node {$\frac{x^2+2x}{x^2+4x+3}$}
        }
        child{
          node {$\frac{x^2+3x+1}{x^2+4x+3}$}
        }
      }
    };
\end{tikzpicture}

        \caption{The first four levels of the Farey polynomial tree.}\label{fig:FareyPoly}
    \end{center}
\end{figure}

We label each vertex in the tree with notation inspired by continued fractions. For $a_i \in \mathbb{Z}^+$:
\begin{equation}\label{eqn: vertex labels}
[a_1,a_2,\ldots,a_k]_x = \Phi_1^{a_1-1} \circ \Phi_0 \circ \Phi_1^{a_2-1} \circ \Phi_0 \circ \cdots \circ \Phi_1^{a_{k-1}-1}\circ \Phi_0 \circ \Phi_1^{a_k-1} \left( \frac{1}{1}\right)
\end{equation}

In this way the root of our tree is the vertex $[2]_x=[1,1]_x$, and in general $[a_1,\ldots,a_{k-1},a_k+1]_x=[a_1,\ldots,a_{k-1},a_k,1]_x$. Observe also that
\begin{align*}
    \Phi_0\left( [a_1,\ldots,a_k]_x\right) &= [1,a_1,\ldots,a_k]_x\\
    \Phi_1\left( [a_1,\ldots,a_k]_x\right) &= [a_1+1,a_2,\ldots,a_k]_x\\
\end{align*}The tree we present here has some very nice properties. We highlight some of them with the following two theorems; by ``subtree at vertex $[a_1,\ldots,a_k]_x$" we mean the tree generated by $\Phi_1$ and $\Phi_0$ rooted at vertex $[a_1,\ldots,a_k]_x$.

We have the following two main theorems.

Let us first define the tree of interest which we will call the \textit{Farey polynomial tree} (an explanation of the derivation of this tree will be given in the beginning of \Cref{sec:cfs}). On the nodes we have rational functions $v(x)=p(x)/q(x)$. The root of the tree is $\frac{x}{x+1}$ and the two offspring of each node are found using the following two functions:
\begin{equation}\label{eqn: Phi}\begin{split}
\Phi_0\left( \frac{p(x)}{q(x)}\right) &= \begin{cases}
\frac{xq(x)}{xq(x)+p(x)} & p(0)\neq 0\\
\frac{q(x)}{q(x)+p(x)/x}& p(0)=0\end{cases}\\
\\
\Phi_1\left( \frac{p(x)}{q(x)}\right) &= \begin{cases}
\frac{xp(x)}{xq(x)+p(x)} & p(0)\neq 0\\
\frac{p(x)}{q(x)+p(x)/x}& p(0)=0.\end{cases}\end{split}\end{equation}

See Figure \ref{fig:FareyPoly} for the first few levels. These two functions are the inverse branches of a generalized Farey map and the tree generalizes the classical Farey tree which is found for $x=1$. Note that we define it by using inverse images of the Farey map and not by using mediants of neighboring fractions, but the trees are intimately related (see \cite{BI09}). The Farey tree is well studied and appears in many different branches of mathematics (see for example~\cite{AK22,BBDG24,BDM21,DKS25,DS07,KO86,LRS17} and the references therein). Curiously, Farey himself (a geologist) did not publish anything significant on the matter. It was Cauchy who proved one of the basic ideas of the Farey sequence and attributed it to Farey (see \cite[Notes on Chapter~3]{HW79}).

\caption{The first four levels of the Farey polynomial tree.}\label{fig:FareyPoly}
 \end{center}
\end{figure}

We label each vertex in the tree with notation inspired by continued fractions. For $a_i \in \mathbb{Z}^+$:
\begin{equation}\label{eqn: vertex labels}
[a_1,a_2,\ldots,a_k]_x = \Phi_1^{a_1-1} \circ \Phi_0 \circ \Phi_1^{a_2-1} \circ \Phi_0 \circ \cdots \circ \Phi_1^{a_{k-1}-1}\circ \Phi_0 \circ \Phi_1^{a_k-1} \left( \frac{1}{1}\right)
\end{equation}

In this way the root of our tree is the vertex $[2]_x=[1,1]_x$, and in general $[a_1,\ldots,a_{k-1},a_k+1]_x=[a_1,\ldots,a_{k-1},a_k,1]_x$. Observe also that
\begin{align*}
 \Phi_0\left( [a_1,\ldots,a_k]_x\right) &= [1,a_1,\ldots,a_k]_x\\
 \Phi_1\left( [a_1,\ldots,a_k]_x\right) &= [a_1+1,a_2,\ldots,a_k]_x\\
\end{align*}The tree we present here has some very nice properties. We highlight some of them with the following two theorems; by ``subtree at vertex $[a_1,\ldots,a_k]_x$" we mean the tree generated by $\Phi_1$ and $\Phi_0$ rooted at vertex $[a_1,\ldots,a_k]_x$.

We have the following two main theorems.

\begin{theorem}\label{th:dense}
 For the subtree $\Omega$ rooted at any vertex $[a_1,\ldots,a_k]_x$, if we set
 \[R=\left\{ x \, | \, \textrm{there is a } p(x)/q(x) \in \Omega \textrm{ for which }q(x)=0\right\}\]
 then $R$ is dense in $(-\infty,-1]$.
\end{theorem}

\section{Forward Farey Tree}\label{sec:cfs}
\subsection{Background and Definition}
The \textit{Gauss map} $T:[0,1) \mapsto [0,1)$, given by
\[T(t) = \begin{cases}
 \frac{1}{t} - \floor{\frac{1}{t}} & t\neq 0\\
 0 & t=0,
\end{cases}\]
may be used to generate the \textit{regular continued fraction} expansion of $t$:
\[ t = \cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\ddots}}},\]
where $a_i =a(T^{i-1}(t))= \floor{1/T^{i-1}(t)}$. This map is the `sped-up' version of the \textit{Farey map} $F$, given by
\[ F(t) = \begin{cases}
 F_0(t) = \frac{1-t}{t} & x \geq 1/2\\
 F_1(t) = \frac{t}{1-t} & x \leq 1/2
\end{cases}\]
with the observation that
\begin{equation}\label{eqn: RCF functional}T(t) = F_0 \circ F_1 ^{a(t)-1} (t).\end{equation}
Note that $a(t)-1=\min(n\in\mathbb{N}_0 : T^n(t)\in [\frac{1}{2},1])$ i.e. it is first hitting time of $x$ to the interval $[\frac{1}{2},1]$ (possibly zero) and $T$ can be understood as the composition of $F_0$ and the induced transformation on this interval (where a return time of zero is allowed).

A generalization of regular continued fractions, $N$-continued fractions, allow for all numerators to be some fixed $N \in \mathbb{Z}\setminus\{0\}$. These were first studied in \cite{AW11,BGRKWY208} and later in many other papers such as \cite{CK,DO18,DKW13,JKN,KL} . Most papers study positive values of $N$ and in the remainder of this section we will also take $N>0$. For negative $N$, there is a relation with the backward continued fractions in Section \ref{sec:other trees}. One of the key differences with regular continued fractions is that there is not a unique continued fraction for every $t\in(0,1)$. For some studied algorithms generating $N$-continued fractions it is proven that there are quadratic irrationals without periodic expansion (and even rationals with aperiodic expansions), see \cite{KL}. For the greedy $N$-continued fractions, which we have here, there is strong numeric evidence that there are quadratic irrationals with an aperiodic expansion (see \cite{DKW13}), though this problem is still open. The greedy $N$-continued fractions can be generated with a similar map as the Gauss map namely by \[ T_N(t) = \begin{cases}
 \left(\frac{N}{t}-N\right) - \floor{\frac{N}{t}-N} & t \neq 0\\
 0 & t=0,
\end{cases}\]
which generates
\[ t= \cfrac{N}{N+(a_1-1)+\cfrac{N}{N+(a_2-1)+\cfrac{N}{N+(a_3-1)+\ddots}}},\]
where now $a_i=a(N,t)= \floor{N/T_N^{i-1}(t)-N}+1$. Then $T_N(x)$ is a sped-up version of the associated $N$-Farey map
\[F_N(t) = \begin{cases}
 F_{N,0}(t) = \frac{N(1-t)}{t} & t \geq \frac{N}{N+1} \\
 F_{N,1}(t) = \frac{Nt}{N-t} & t \leq \frac{N}{N+1}
\end{cases}\]
with the observation that
\begin{equation}\label{eqn: N-CF functional}T_N(t) = F_{N,0} \circ F_{N,1}^{a(N,t)-1}(t).\end{equation}
See Figure \ref{fig:Fareymap} (right) for an example of $N=2$. It is important to point out that this definition of $a_i=a(N,t)$ is not typical: more typical, e.g. in the above references for N-continued fractions, is that $a(N,t)=\floor{N/t}$ and $T_N(t)$ is equivalent but without the `$-N$' both inside and outside the integer part function. Our definition here differs only by an integer constant for $a$, is identical for $T_N$, gives a similar presentation between \Cref{eqn: RCF functional} and (\ref{eqn: N-CF functional}), and is what we will now generalize.

\begin{proposition}\label{prop: elementary vertex properties without proof}
 At every vertex $[a_1,\ldots,a_k]_x=p/q$, we have:
 \begin{itemize}
 \item $p,q$ are polynomials of the same degree.
 \item All coefficients of each are positive integers, except the constant term of $p(x)$ which may be zero.
 \item Term-by-term, the coefficients of $q$ are strictly larger than those of $p$, except for the leading coefficients which are both one.
 \end{itemize}
 \begin{proof}
 All properties are preserved by both $\Phi_0$ and $\Phi_1$, and are true for the root vertex $p(x)=x$, $q(x)=x+1$.
 \end{proof}
\end{proposition}
\begin{proposition}\label{prop: increasing functions}
 For every vertex $v=[a_1,\ldots,a_k]_x$, we have both
 \begin{align}
 v'(x)&> 0 &\textrm{(wherever defined)}\\
 xv'(x) &\leq v(x) & \textrm{(with equality if and only if $x=0$ and $v(0)=0$)}
 \end{align}
 \begin{proof}
 We induct on $k$, the length of the expansion of $v$. For $k=1$ we have
 \[v=\frac{x}{x+a_1-1}\]
 (where $a_1 \geq 2$) for which both claims may be trivially verified. Now assume both properties hold for $v$, and for some $a \in \mathbb{Z}^+$ set
 \[V = [a,v]_x = \begin{cases}\frac{x}{x+a-1+v} & a \geq 2 \textrm{ or } v(0) \neq 0\\ \frac{1}{1+v/x} & a=1 \textrm{ and } v(0)=0.
 \end{cases}\]
 Note that by \Cref{prop: elementary vertex properties without proof} $x=0$ is at most a simple root of $v$, so the second case may be properly defined even for $x=0$, and if we establish $v'>0$, then $xv'$ also has at most a simple root at $x=0$.
 In the first case, we compute
 \begin{align*}
 V'&=\frac{a-1+v-xv'}{(x+a-1+v)^2}.\\
 \intertext{Since we have assumed $xv'<v$, the first claim now follows.}
 xV'-V&= \frac{x((a-1)+v-xv')-x(x+a-1+v)}{(x+a-1+v)^2}\\
 &=-x^2\frac{v'+1}{(x+a-1+v)^2}.\\
 \end{align*}
 Which is negative unless $x=0$, in which case it follows that $V(0)=0$ as well.

\section{Backward Farey Tree}\label{sec:other trees}
The results we have on the Farey polynomial tree raise the question of how general these results are: there are many other different families of continued fraction algorithms. In this section we take the backward continued fractions as a starting point and compare it with Theorem \ref{th:cfs} and Theorem \ref{th:dense}.
Just as for regular continued fractions, the backward continued fractions appears in different fields of mathematics. There are many nice papers studying backwards continued fractions, but we want to highlight \cite{MO19,MO20} where backwards (and regular) continued fractions are used to draw connections between graph theory, combinatorics, number theory, and algebra.
For backward continued fractions, a parametrised family is already studied in the form of $ 1/(u(1-x)) \mod 1$ where $u\in(0,4)$, introduced and studied in \cite{GH96a,GH96b} and more recently \cite{LS20, LS22}. In contrast to those papers, in this article we will make the branches full again by shifting the digit set in order to get a better comparison with the Farey polynomial tree. Of course, instead of having $ 1/(u(1-x)) \mod 1$, we can also put the parameter in the numerator. This leads to the fast map
\begin{equation}
 T_x(t)=\frac{x}{1-t}- x -\left\lfloor \frac{x}{1-t}-x \right\rfloor.
\end{equation}
The continued fractions are of the form
\[
t=1-\cfrac{x}{x + a_1-\cfrac{x}{x+ a_2 -\ddots}}
\]
where $a_i\in\mathbb{Z^+}$, given by
\[a(t)=1+\floor{\frac{x}{1-t}-x}.\] Note that, when taking $x\in \mathbb{Z^+}$, you essentially get $N$-continued fractions with a negative value for $N$.
The slow map is given by
\begin{equation}\label{eq:F_x backwards}
 F_x(t)=
\begin{cases}
\dfrac{xt}{1-t} & t\in [0,\frac{1}{x+1})\\[1ex]
1-\displaystyle\frac{x(t-1)}{1-t-x}, & t\in [\frac{1}{x+1},1],
\end{cases}
\end{equation}
 see Figure \ref{fig:Fareymapbackward}.

\begin{theorem}\label{th:backwardcf}
 For a fixed value of $x$, we consider the function which maps the backward tree to the set of values given by evaluating every vertex at this value of $x$.
 \begin{enumerate}
 \item Setting a value $x\geq 1$ injectively maps the backward tree to a dense subset of $(0,1)$. \\For $x\in(0,1)$, the mapping is injective and maps to a subset of $(0,1)$ but the image is not dense.
 \item Setting a value $x \geq 1$ bijectively maps the tree to $\mathbb{Q} \cap (0,1)$ if and only if $x \in \mathbb{Z}^+$.
 \end{enumerate}
\end{theorem}

For Theorem~\ref{th:cfs} the introduction says it is proved by “us[ing] the close relationship between the tree and a family of continued fractions explained in Section~\ref{sec:cfresults}.”

(No further proof structure for Theorem~\ref{th:cfs} is described here; the only other proof outline given is for Theorem~\ref{th:dense}, which is “proven … by inductively selecting a path in the tree whose vertices have poles converging to an arbitrary $\alpha<-1$.”)

To prove the main theorem, the introduction says it is proved by “us[ing] the close relationship between the tree and a family of continued fractions explained later.”

(No further proof structure for the main theorem is described here; the only other proof outline given is for \begin{theorem}\label{th:dense}
    For the subtree $\Omega$ rooted at any vertex $[a_1,\ldots,a_k]_x$, if we set
    \[R=\left\{ x \, | \, \textrm{there is a } p(x)/q(x) \in \Omega \textrm{ for which }q(x)=0\right\}\]
    then $R$ is dense in $(-\infty,-1]$.
\end{theorem}, which is “proven … by inductively selecting a path in the tree whose vertices have poles converging to an arbitrary $\alpha<-1$.”)

Question:
Consider the Farey polynomial tree whose vertices are rational functions in a variable $X$, with root $\dfrac{X}{X+1}$, and where each vertex $\dfrac{p(X)}{q(X)}$ has two children given by
\[
\Phi_0\!\left(\frac{p(X)}{q(X)}\right)=
\begin{cases}
\dfrac{Xq(X)}{Xq(X)+p(X)} & \text{if } p(0)\neq 0,\\[1ex]
\dfrac{q(X)}{q(X)+p(X)/X} & \text{if } p(0)=0,
\end{cases}
\qquad
\Phi_1\!\left(\frac{p(X)}{q(X)}\right)=
\begin{cases}
\dfrac{Xp(X)}{Xq(X)+p(X)} & \text{if } p(0)\neq 0,\\[1ex]
\dfrac{p(X)}{q(X)+p(X)/X} & \text{if } p(0)=0.
\end{cases}
\]
For a fixed real number $x$, evaluate every vertex at $X=x$, thereby obtaining a map from the vertices of the tree to real numbers. Which statement holds about this evaluation map?

For every fixed $x>0$, the evaluation map is injective and its image is a dense subset of $(0,1)$. Moreover, this map is a bijection onto $\mathbb{Q}\cap(0,1)$ if and only if $x\in\mathbb{Z}^+$.

Choices:
B. For every fixed $x\ge 1$, the evaluation map is injective and its image is a dense subset of $(0,1)$. Moreover, this map is a bijection onto $\mathbb{Q}\cap(0,1)$ if and only if $x\in\mathbb{Z}^+$.
C. For every fixed $x\in\mathbb{Z}^+$, the evaluation map is injective and its image is a dense subset of $(0,1)$, and in fact it is a bijection onto $\mathbb{Q}\cap(0,1)$.
D. For every fixed $x>0$, the evaluation map is injective and its image is all of $(0,1)$. Moreover, this map is a bijection onto $\mathbb{Q}\cap(0,1)$ if and only if $x\in\mathbb{Z}^+$.
E. For every fixed $x>0$, the evaluation map has dense image in $(0,1)$, and it is injective if and only if $x\in\mathbb{Z}^+$. Moreover, in that case the map is a bijection onto $\mathbb{Q}\cap(0,1)$.

parameter range $x>0$ replaced by $x\ge 1$

restricts the universal quantifier from all $x>0$ to integer parameters only

dense image strengthened to surjective image $(0,1)$

injectivity made dependent on integrality rather than holding for all $x>0$


\begin{corollary}\label{cor:behave}
  For the sequences defined by \eqref{eq:mexdef},
  there exist a bounded function $\lambda_\ell:\mathbb{N}\to\mathbb{Z}$ such that, for all $n$,
  \[
   a_n=\lfloor (n+\ell)\phi \rfloor +\lambda_\ell(n).
 \]
 So, in particular, \(b_n=\lfloor (n+\ell)\phi^2 \rfloor + \lambda_\ell(n) +1\).
  \end{corollary}

\begin{theorem}\label{thm:rec_car}
  Let $\ell\ge 1$ and define recursively $(a_n,b_n)_{n\ge 0}$ by
\begin{equation}\label{eq:mexdef}
  (a_0,b_0)=(\ell+1,2\ell+2) \quad\text{ and }\quad \forall n\ge 1, \left\{
    \begin{array}{l}
a_n =\mex (\{ a_i,b_i \mid i<n \}\cup\{0,1,\ldots,\ell\}),\\
b_n =a_n+n+\ell+1.\\
    \end{array}
  \right.
\end{equation}
The set of non-terminal $\mathcal{P}$-positions of $K^\ell$ is $\{(a_n,b_n)\mid n\ge 0\} \cup \{(b_n,a_n)\mid n\ge 0\} $.
\end{theorem}

\begin{array}{c|llll}
    &g_n & \mu(g_n) & \mu^2(g_n) & \mu^3(g_n) \\
    \hline
 0&1& 0& 1& 10\\
 1&0& 1& 10& 011\\
 2&1& 10& 011& 11010\\
 3&1& 01& 110& 01011\\
 4&0& 11& 010& 11011\\
 5&1& 0& 11& 010\\
  \end{array}
\]
  \caption{The different $3$-types when applying a $\varphi$-morphism to $g$.}
  \label{tab:types}
\end{table}

Now we associate each symbol $g_n$ with its $3$-type and get the infinite word
\[
  01|2|31|45|2|35|4|31|45|4|35|45|\cdots
\]
where the vertical bars indicate the factorization of the Fibonacci word $ab|a|ab|ab|a|\cdots$ with factors $\sigma(a)=ab$ and $\sigma(b)=a$, the images of the letters by the Fibonacci morphism. From this, we deduce the morphism $\mu$ given in Example~\ref{exa:mu}: the image of the $n$th letter has to be the $n$th block in the factorization. So $0\mapsto 01$, then $1\mapsto 2$ and so on. From the morphism, it is a routine to obtain the DFA in Figure~\ref{fig:automG}, see Definition~\ref{def:dfao}.

Finally, one may define a coding~$\rho$ to recover the original sequence where each type is mapped to the first element of the tuple. So, $0,2,3,5\mapsto 1$ and $1,4\mapsto 0$. This can equivalently be performed by comparing the morphic word and the original sequence
\begin{align*}
  &01231452354314543545\cdots\\
  &10110011110100101101\cdots
\end{align*}
and matching corresponding elements.
\subsection{An automatic proof for $K^2$}\label{ssec:autom_proof}

Now that $g$ has been defined by a DFA fed with Fibonacci representations (and stored as {\tt G.txt} in {\tt Word Automata Lib}), the set of $\mathcal{P}$-positions \eqref{eq:Ppos} obtained by Komak et al. can be described by the following commands:
\begin{verbatim}
def pposK2_asym "?msd_fib (a+b<=1) | En,x $phin(n,x) & a+1=x+G[n]
                                                     & b=x+n+G[n]":
def pposK2 "?msd_fib $pposK2_asym(a,b) | $pposK2_asym(b,a) ":
\end{verbatim}
The resulting automaton has $27$ states.

For the sake of presentation, let us recall some basics on combinatorial games.
\begin{definition}\label{def:stab}
A set $S$ of positions is {\em stable} if, for all $s,t\in S$, $s\neq t$, there is no move between $s$ and $t$. A set $S$ of positions is {\em absorbing}, if for all $t\not\in S$, there exists $s\in S$ such that there is a move from $t$ to $s$ (or, $t$ has an option in $S$).
\end{definition}
It is a well-known property in graph theory that every acyclic graph has a unique kernel, i.e., a stable and absorbing set of vertices. In a take-away game where tokens are removed from piles, the corresponding game graph is acyclic: it is not possible to visit twice the same position during a game.
\begin{proposition}[Folklore]\label{pro:kernel}
  The sets of $\mathcal{P}$- and $\mathcal{N}$-positions of an
  impartial acyclic game are uniquely determined by the following two
  properties:
\begin{enumerate}
\item Every move from a $\mathcal{P}$-position leads to an
  $\mathcal{N}$-position; equivalently there is no move between two $\mathcal{P}$-positions (stability property of $\mathcal{P}(G)$).
  \item From every $\mathcal{N}$-position, there exists a move leading to a $\mathcal{P}$-position (absorbing property of $\mathcal{P}(G)$).
\end{enumerate}
\end{proposition}

As observed in \cite{MRRW}, it is then a routine test to check stability and absorbing property:
\begin{verbatim}
eval stableK2 "?msd_fib Ap,q,r,s (($pposK2(p,q) & $pposK2(r,s)
     & p>=r & q>=s & p+q>2) => ((p=r & q=s) | (p>r & q>s & p+s!=q+r)))":

eval absorbingK2 "?msd_fib Ap,q (~$pposK2(p,q) => Ex,y
     (x<=p & y<=q & $pposK2(x,y) & (p+y=q+x | p=x | q=y))) ":
\end{verbatim}
These two commands return {\tt TRUE} resulting in the following result, \cite[Thm.~3]{Komak}. From Proposition~\ref{pro:kernel}, we immediately get an alternative proof of Theorem~\ref{thm:K2}.

\section{Towards an algebraic characterization for $K^\ell$}\label{sec:newGame}

In \cite{Komak}, Komak et al. chose $\{(x,y)\mid x+y\le 2\}$ as set of terminal positions. It is natural to consider a parameterized version where the set of terminal states is
\[
  \{(x,y)\in\mathbb{N}^2\mid x+y\le \ell\}
\]
for some $\ell\in\mathbb{N}$. The corresponding game is denoted by $K^\ell$. Note that the game $K^0$ is the classic Wythoff game. In this section, we obtain new results concerning the games $K^1$ and~$K^3$.

\subsection{The $K^1$-game}
Up to our knowledge, the game $K^1$ does not seem to have been studied in the literature. Computing the first $\mathcal{P}$-positions of $K^1$ and writing their Fibonacci expansions permitted us to state a conjecture that can be tested with {\tt Walnut}. This result is quite similar to the famous characterization of the $\mathcal{P}$-positions of Wythoff game obtained by Fraenkel \cite{Fraenkel3}.
\begin{table}[h!t]
  \[
    \begin{array}{c|r|c|r}
      a_n & \rep_F(a_n) & b_n & \rep_F(b_n) \\
      \hline
 0&\varepsilon  & 1 &1 \\
 2&10 & 4 &101 \\
 3&100 & 6 & 1001 \\
 5&1000 & 9 & 10001 \\
 7&1010 & 12 & 10101 \\
 8&10000 & 14 & 100001 \\
 10&10010 & 17 &100101 \\
 11&10100 & 19 & 101001 \\
 13&100000 & 22 & 1000001 \\
 15&100010 & 25 & 1000101 \\
  \end{array}

\begin{theorem}\label{thm:carK1}
  A position $(a,b)$, with $a\le b$, is a $\mathcal{P}$-position of the game $K^1$, with a set of terminal positions being $\{(x,y)\mid x+y\le 1\}$ and Wythoff's moves, if and only if $\rep_F(a)$ ends with $0$ and $\rep_F(b)=\rep_F(a)1$.
\end{theorem}

\begin{array}{c|ccccccccccccccccccccc}
      & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10  & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 &  19 & 20 \\
      \hline
      h& 0 & 1 & 1 & 2 & 3 & 3 & 4 & 4 & 5 & 6 & 6 &  7 & 8 & 8 & 9 & 9 & 10 & 11 & 11 & 12 &  12 \\
      g&1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 &  1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 1 \\
    \end{array}
  \]
  \caption{First values of the sequence $g$ and Hofstadter sequence $h$.}
  \label{tab:gh}
\end{table}

The main result of Komak {\em et al.} provides an algebraic description of set of $\mathcal{P}$-positions of $K^2$:
\begin{theorem}\label{thm:K2}
  The set of $\mathcal{P}$-positions of the variant of Wythoff game where the set of terminal positions is $\{(x,y)\mid x+y\le 2\}$,  is exactly \begin{equation}\label{eq:Ppos}
  \left\{ (\lfloor n\phi\rfloor +g(n)-1, \lfloor n \phi^2\rfloor +g(n))\mid n\ge 0\right\} \cup
  \left\{ (\lfloor n \phi^2\rfloor +g(n), (\lfloor n\phi\rfloor +g(n)-1)\mid n\ge 0\right\}
\end{equation}
where $g:\mathbb{N}\to\mathbb{N}$ is the function given in Definition~\ref{def:fg}.
\end{theorem}

The authors provide a classical proof of their result by showing that the set of $\mathcal{P}$-positions described by \eqref{eq:Ppos} is both stable and absorbing (see Definition~\ref{def:stab}). The proof is quite long and requires a detailed case analysis. Without diminishing their achievement, once the set \eqref{eq:Ppos} has been conjectured, if the set can be handled by {\tt Walnut}, then it becomes straightforward to produce an automated proof in just a few lines. Our approach therefore complements the work carried out in \cite{Komak}.

In \cite{block}, other variants of Wythoff game are studied, in which some blocking maneuvers are added. Let $k\ge 1$. In the game denoted by $W^k$, for each move, before the next player (i.e., the player who is about to play) moves, the previous player (i.e., the one who has just played) may declare at most $k-1$ of the options as forbidden. When the next player has moved, any blocking maneuver is forgotten and has no further incidence on the game. This terminology of previous and next player explains why we speak of $\mathcal{N}$- and $\mathcal{P}$-positions, respectively. For $k=1$, this is the classical game of Wythoff. When $k=2,3$, we reconsider Larsson's result and obtain an automated proof, replacing a 2-page-long analysis by some easy-to-describe first-order formulas.

As Shallit has already noted on several occasions, the two approaches are complementary. A classical, purely combinatorial proof usually provides structural insights, whereas the use of automated provers helps avoid lengthy case analyses and enables the exploration of directions that are difficult to access through traditional techniques. In particular, in this article, we easily obtain a variety of results that would otherwise require significantly more effort using ``classical'' methods. Moreover, these results lead us to formulate general theorems.
\smallskip

This article is organized as follows. Section~\ref{sec:2} --- which was the starting point of this article --- aims to give an automatic proof of the algebraic characterization \eqref{eq:Ppos} of the $\mathcal{P}$-positions of $K^2$. We begin with preliminary results about Fibonacci-automatic sequences. We define a notion of $\varphi$-morphism and describe a heuristic that we extensively use throughout the paper to construct such $\varphi$-morphisms. Given a sufficiently long prefix of an infinite word, we obtain morphisms that can be used in our automatic proofs (and we can therefore prove the correctness of the procedure). Basic results from combinatorial game theory are given in Section~\ref{ssec:autom_proof}.

In Section~\ref{sec:newGame}, we obtain results about new games: a parameterized version of a variant of Wythoff game denoted by $K^\ell$, where the set of terminal states is
\[
  \{(x,y)\in\mathbb{N}^2\mid x+y\le \ell\}
\]
for some $\ell\in\mathbb{N}$. We study the games $K^1$, $K^3$ and $K^4$ and obtain algebraic characterizations of the $\mathcal{P}$-positions similar to \cite{Komak}. In particular, as for the classical Wythoff game $K^0$, the game $K^1$ has a nice set of $\mathcal{P}$-positions: a pair $(a,b)$ of integers such that $a\le b$ is a $\mathcal{P}$-position of $K^1$ if and only if its Fibonacci representation $\rep_F(a)$ ends with zero and $\rep_F(b)$ is of the form $\rep_F(a)1$, see Theorem~\ref{thm:carK1}.

In Section~\ref{sec:6}, we go further in the analysis of the games $K^\ell$ for an arbitrary $\ell\ge 1$. We provide a recursive characterization of the set of $\mathcal{P}$-positions. The non-terminal $\mathcal{P}$-positions $(a_n,b_n)_{n\ge 0}$ of $K^\ell$ are given, in Theorem~\ref{thm:rec_car}, by
\[
  (a_0,b_0)=(\ell+1,2\ell+2) \quad\text{ and }\quad \forall n\ge 1, \left\{
    \begin{array}{l}
a_n =\mex (\{ a_i,b_i \mid i<n \}\cup\{0,1,\ldots,\ell\}) \\
b_n =a_n+n+\ell+1.\\
    \end{array}

In combinatorial game theory, proofs of many results are obtained by using a suitable numeration system \cite{Duchene,Fraenkel1,Fraenkel2,RigoLNM}. As a typical example, the Zeckendorf numeration based on the Fibonacci sequence is used to characterize the $\mathcal{P}$-positions (i.e., losing positions) of the Wythoff game \cite{Fraenkel3}. Fraenkel showed that a pair $(a,b)$ of integers such that $a\le b$ is a $\mathcal{P}$-position of Wythoff game if and only if $\rep_F(a)$ ends with an even number of zeroes and $\rep_F(b)$ is the left-shift of $\rep_F(a)$, i.e., $\rep_F(b)=\rep_F(a)0$.

When the numeration system has good properties (i.e., it is an {\em addable} system as discussed in \cite{ShallitBook}), the formalism of first-order logic can be used to express certain properties of combinatorial games. We have recently exploited this approach and used {\tt Walnut} to reprove classical results in combinatorial games theory, as well as to obtain new ones \cite{MRRW}. {\tt Walnut} is a free, open-source prover for first-order statements dealing with automatic sequences \cite{Mousavi,ShallitBook}.

We assume that the reader is sufficiently familiar with the use of {\tt Walnut}. For references on combinatorial game theory, we refer to \cite{RigoLNM} and \cite{MRRW}.

The Wythoff game is a {\em take-away} game: two players alternately remove tokens from two piles. One can remove a positive number of token from one pile or, remove the same positive number of token from both piles. The Wythoff game is {\em impartial}: the set of options (i.e., positions reachable in one legal move) of a given position does not depend on which player is in turn to move. Wythoff game can be seen as a queen on an infinite chessboard $\mathbb{N}^2$: in a position $(x,y)\neq(0,0)$ the queen can move horizontally to $(x-n,y)$ with $0<n\le x$, vertically to $(x,y-n)$ with $0<n\le y$ or diagonally to $(x-n,y-n)$ with $0<n\le \min\{x,y\}$. According to the {\em normal convention}, a player who is unable to move loses the game; passing is not allowed. Otherwise stated, the player who takes the last token wins or, in an equivalent way, when the queen reaches $(0,0)$.

In this article, we are mainly interested in two kinds of variations of the Wythoff game.

In \cite{Komak}, a variant of Wythoff game has been introduced: the set $\{(x,y)\mid x+y\le 2\}$ is declared to be the set of {\em terminal} positions. If a player moves the queen into this terminal set with the usual Wythoff moves, that player wins the game. Let us call this game $K^2$. We chose this notation because we will later introduce a generalization of the game obtained by varying the set of terminal positions. Let $\phi$ be the golden ratio~$(1+\sqrt{5})/2$. We first define a sequence~$(g(n))_{n\ge 0}$ as follows.
\begin{definition}\label{def:fg}
  We let $g(0)=1$, $g(1)=0$ and
  \[
    g(n)=\left\{
      \begin{array}{ll}
        1-g(m),& \text{ if }\lfloor n\phi\rfloor= \lfloor m(\phi+1)\rfloor+1 \text{ for some }m\ge 0;\\
        1,& \text{ otherwise}.
      \end{array}\right.
  \]

\end{definition}
The first values of the sequence~$g$ are given in Table~\ref{tab:gh}.
\begin{table}[h!tb]
  \centering
  \[
    \begin{array}{c|ccccccccccccccccccccc}
      & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10  & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 &  19 & 20 \\
      \hline
      h& 0 & 1 & 1 & 2 & 3 & 3 & 4 & 4 & 5 & 6 & 6 &  7 & 8 & 8 & 9 & 9 & 10 & 11 & 11 & 12 &  12 \\
      g&1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 &  1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 1 \\
    \end{array}
  \]
  \caption{First values of the sequence $g$ and Hofstadter sequence $h$.}
  \label{tab:gh}
\end{table}

The main result of Komak {\em et al.} provides an algebraic description of set of $\mathcal{P}$-positions of $K^2$:

In combinatorial game theory, proofs of many results are obtained by using a suitable numeration system \cite{Duchene,Fraenkel1,Fraenkel2,RigoLNM}. As a typical example, the Zeckendorf numeration based on the Fibonacci sequence is used to characterize the $\mathcal{P}$-positions (i.e., losing positions) of the Wythoff game \cite{Fraenkel3}. Fraenkel showed that a pair $(a,b)$ of integers such that $a\le b$ is a $\mathcal{P}$-position of Wythoff game if and only if $\rep_F(a)$ ends with an even number of zeroes and $\rep_F(b)$ is the left-shift of $\rep_F(a)$, i.e., $\rep_F(b)=\rep_F(a)0$.

The Wythoff game is a {\em take-away} game: two players alternately remove tokens from two piles. One can remove a positive number of token from one pile or, remove the same positive number of token from both piles. The Wythoff game is {\em impartial}: the set of options (i.e., positions reachable in one legal move) of a given position does not depend on which player is in turn to move. Wythoff game can be seen as a queen on an infinite chessboard $\mathbb{N}^2$: in a position $(x,y)\neq(0,0)$ the queen can move horizontally to $(x-n,y)$ with $0<n\le x$, vertically to $(x,y-n)$ with $0<n\le y$ or diagonally to $(x-n,y-n)$ with $0<n\le \min\{x,y\}$. According to the {\em normal convention}, a player who is unable to move loses the game; passing is not allowed. Otherwise stated, the player who takes the last token wins or, in an equivalent way, when the queen reaches $(0,0)$.

In this article, we are mainly interested in two kinds of variations of the Wythoff game.

In \cite{Komak}, a variant of Wythoff game has been introduced: the set $\{(x,y)\mid x+y\le 2\}$ is declared to be the set of {\em terminal} positions. If a player moves the queen into this terminal set with the usual Wythoff moves, that player wins the game. Let us call this game $K^2$. We chose this notation because we will later introduce a generalization of the game obtained by varying the set of terminal positions. Let $\phi$ be the golden ratio~$(1+\sqrt{5})/2$. We first define a sequence~$(g(n))_{n\ge 0}$ as follows.
\begin{definition}\label{def:fg}
 We let $g(0)=1$, $g(1)=0$ and
 \[
 g(n)=\left\{
 \begin{array}{ll}
 1-g(m),& \text{ if }\lfloor n\phi\rfloor= \lfloor m(\phi+1)\rfloor+1 \text{ for some }m\ge 0;\\
 1,& \text{ otherwise}.
 \end{array}\right.
 \]

\end{definition}
The first values of the sequence~$g$ are given in Table~\ref{tab:gh}.
\begin{table}[h!tb]
 \centering
 \[
 \begin{array}{c|ccccccccccccccccccccc}
 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 \\
 \hline
 h& 0 & 1 & 1 & 2 & 3 & 3 & 4 & 4 & 5 & 6 & 6 & 7 & 8 & 8 & 9 & 9 & 10 & 11 & 11 & 12 & 12 \\
 g&1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 1 \\
 \end{array}
 \]
 \caption{First values of the sequence $g$ and Hofstadter sequence $h$.}
 \label{tab:gh}
\end{table}

The main result of Komak {\em et al.} provides an algebraic description of set of $\mathcal{P}$-positions of $K^2$:

\end{definition}
The first values of the sequence~$g$ are given in Table~\ref{tab:gh}.
\begin{table}[h!tb]
 \centering
 \[
 \begin{array}{c|ccccccccccccccccccccc}
 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 \\
 \hline
 h& 0 & 1 & 1 & 2 & 3 & 3 & 4 & 4 & 5 & 6 & 6 & 7 & 8 & 8 & 9 & 9 & 10 & 11 & 11 & 12 & 12 \\
 g&1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 1 \\
 \end{array}
 \]
 \caption{First values of the sequence $g$ and Hofstadter sequence $h$.}
 \label{tab:gh}
\end{table}

The authors provide a classical proof of their result by showing that the set of $\mathcal{P}$-positions described by \eqref{eq:Ppos} is both stable and absorbing (see Definition~\ref{def:stab}). The proof is quite long and requires a detailed case analysis. Without diminishing their achievement, once the set \eqref{eq:Ppos} has been conjectured, if the set can be handled by {\tt Walnut}, then it becomes straightforward to produce an automated proof in just a few lines. Our approach therefore complements the work carried out in \cite{Komak}.

In Section~\ref{sec:6}, we go further in the analysis of the games $K^\ell$ for an arbitrary $\ell\ge 1$. We provide a recursive characterization of the set of $\mathcal{P}$-positions. The non-terminal $\mathcal{P}$-positions $(a_n,b_n)_{n\ge 0}$ of $K^\ell$ are given, in Theorem~\ref{thm:rec_car}, by
\[
 (a_0,b_0)=(\ell+1,2\ell+2) \quad\text{ and }\quad \forall n\ge 1, \left\{
 \begin{array}{l}
a_n =\mex (\{ a_i,b_i \mid i<n \}\cup\{0,1,\ldots,\ell\}) \\
b_n =a_n+n+\ell+1.\\
 \end{array}
 \right.
\]
We prove this result in an automatic way for $\ell=1,2$, then extend it for all values of the parameter using classical arguments. With Corollary~\ref{cor:behave}, we generalize Theorem~\ref{thm:K2} and obtain that $(a_n,b_n)_{n\ge 0}$ are of the form
\[ a_n=\lfloor (n+\ell)\phi\rfloor + \lambda_\ell(n) \quad\text{ and }\quad
 b_n=\lfloor (n+\ell)\phi^2\rfloor + \lambda_\ell(n)+1\]
for some bounded integer-valued function $\lambda_\ell$. Our result can be related to the recent paper \cite{Letouzey} where discrepancy of generalized Hofstadter functions is studied (and formalized in {\tt Coq}). Our methods are inspired by \cite{Fraenkel5,Kimberling2,Larsson}.

The first non-terminal $\mathcal{P}$-positions $(a_n,b_n)_{n\ge 0}$ are given in Table~\ref{tab:k3}. From now on, we take this convention: in the indexing of the $P$-positions, we do not take terminal positions into account. Thus, $(a_0,b_0)$ represents the first non-terminal $\mathcal{P}$-position. Due to the symmetry of the game, we only consider sequences where $a_n<b_n$.
\begin{table}[h!t]
\[
 \begin{array}{c|cccccccccccccccccccccccccccccc}
 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 \\
 \hline
 a_n& 4 & 5 & 6 & 7 & 9 & 11 & 13 & 15 & 16 & 18 & 19 & 21 & 22 & 24 & 25 & 27 &
 29 & 30 \\
 b_n & 8 & 10 & 12 & 14 & 17 & 20 & 23 & 26 & 28 & 31 & 33 & 36 & 38 & 41 & 43 & 46
 & 49 & 51 & \\
 \end{array}
 \]
 \caption{First (non-terminal) $\mathcal{P}$-positions of $K^3$, $(n\ge 0)$.}
 \label{tab:k3}
\end{table}
\begin{theorem}\label{thm:fibaut2}
There exists a Fibonacci-automatic function $g_3:\mathbb{N}\to\{0,1,2\}$ such that, for all $n\ge 0$, the $n$th non-terminal $\mathcal{P}$-position $(a_n,b_n)$ of $K^3$ is given by
\begin{equation}\label{eq:K3}
 a_n=\lfloor (n+2)\phi \rfloor+g_3(n+1)-1 \quad \text{ and }\quad
 b_n=\lfloor (n+2)\phi^2 \rfloor+g_3(n+1)+1.
\end{equation}
\end{theorem}
The first few values of $g_3(n)$ are
\[
 1221011221211111111121121121211211112111121111111211112\cdots
\]
Using the heuristic described in Section~\ref{ssec:heuristic}, assuming that the above infinite word is generated by a $\varphi$-morphism, we obtain the morphism
\begin{align*}
 \mu_3:\;&
0 \mapsto 01,
1 \mapsto 2,
2 \mapsto 34,
3 \mapsto 56,
4 \mapsto 7,
5 \mapsto 78,\\
& 6 \mapsto 9,
7 \mapsto ab,
8 \mapsto a,
9 \mapsto 56,
a \mapsto ab,
b \mapsto 7
\end{align*}
and the coding
\[\rho_3:0,3,5,6,8,a,b\mapsto 1,\quad 1,2,7,9\mapsto 2,\quad 4\mapsto 0.\]
We thus define $g_3(n)$ as the $n$th symbol in $\rho_3(\mu_3^\omega(1))$. Note that to produce enough value of $g_3(n)$, we have to compute sufficiently many $\mathcal{P}$-positions of $W^3$.

\subsection{Even further}
For the game~$K^4$, we have applied the same procedure. The first non-terminal $\mathcal{P}$-positions $(a_n,b_n)_{n\ge 0}$ are given in Table~\ref{tab:k4}.
\begin{table}[h!t]
\[
\begin{array}{c|cccccccccccccccccc}
 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 \\
 \hline
 a_n &5 & 6 & 7 & 8 & 9 & 11 & 13 & 15 & 17 & 19 & 20 & 22 & 23 & 25 & 26 & 28 & 29 & 31 \\
 b_n & 10 & 12 & 14 & 16 & 18 & 21 & 24 & 27 & 30 & 33 & 35 & 38 & 40 & 43 & 45 & 48 & 50 & 53 \\
\end{array}
 \]
 \caption{First (non-terminal) $\mathcal{P}$-positions of $K^4$, $(n\ge 0)$.}
 \label{tab:k4}
\end{table}
To get a long enough prefix, we have computed the first $600$ $\mathcal{P}$-positions $(a_n,b_n)$ with $a_n\le b_n$ (up to $a_n$ close to $1000$). From this, we conjectured that
\begin{equation}\label{eq:K4}
 a_n=\lfloor (n+2)\phi \rfloor+g_4(n+1) \quad \text{ and }\quad
 b_n=\lfloor (n+2)\phi^2 \rfloor+g_4(n+1)+3,
\end{equation}
where the first few values of $g_4(n)$ are
\[
 12210001112111111010110110111111111111111111\cdots.
\]
Having the first $600$ values of $g_4(n)$, we apply the heuristic of Section~\ref{ssec:heuristic}. Note that here, to be able to discern types correctly, we have to consider $4$-types (there are distinct $4$-types whose restrictions to $3$-types are equal). Since we have to take fourth iterations, this explains why we need a longer prefix. We obtain $18$ different $4$-types and the heuristic gives the following morphisms:
\begin{align*}
 \mu_4:\;&0 \mapsto 01,\ 1 \mapsto 2,\ 2 \mapsto 34,\ 3 \mapsto 56,\ 4 \mapsto 7,\ 5 \mapsto 89,\ 6 \mapsto a,\ 7 \mapsto bc,\ 8 \mapsto dc,\\
 &9 \mapsto d,\ a \mapsto ef,\ b \mapsto ef,\ c \mapsto e,\ d \mapsto 7g,\ e \mapsto eh,\ f \mapsto b,\ g \mapsto d,\ h \mapsto b
\end{align*}
\[
 \rho_4: 0,3,7,8,9,b,c,d,e,h \mapsto 1,\ 1,2,a \mapsto 2,\ 4,5,6,f,g \mapsto 0
\]
With $g_4(n)$ being the $n$th symbol of $\rho_4(\mu_4^\omega(1))$, we have a $18$-state DFAO. Formulas \eqref{eq:K4} translates in {\tt Walnut} into
\begin{verbatim}
def pposK4_asym "?msd_fib (a+b<=4) | (En,x $phin(n+2,x) & (a=x+K4[n+1])
 & (b=x+K4[n+1]+n+5))":
\end{verbatim}
and we then follow exactly the same proof to get the result.

Let us begin with some classical and well-known results on Wythoff game before moving on to the games discussed in this article. We recall the {\em recursive definition} of the $\mathcal{P}$-positions of Wythoff game~$K^0$, with our convention:
\[
 (a_0,b_0)=(1,2) \quad\text{ and }\quad \forall n\ge 1, \left\{
 \begin{array}{l}
a_n =\mex (\{ a_i,b_i \mid i<n \}\cup\{0\}),\\
b_n =a_n+n+1,\\
 \end{array}
 \right.
\]
where $\mex$ stands for {\em minimum excluded value}, i.e. the least non-negative integer not in the set. In other words, $\mex S=\min(\mathbb{N}\setminus S)$. So $a_1=\mex\{0,1,2\}=3$ and $b_1=a_1+2=5$, then $a_2=\mex\{0,1,2,3,5\}=4$ and $b_2=a_2+3=7$ and so on.

Larsson characterized \cite[Thm.~1.1]{block} the set of $\mathcal{P}$-positions of $W^2$, a variant of Wythoff game where one option may be blocked, see Figure~\ref{fig:w2w3}. We provide an automatic proof of this result.
\begin{theorem}
The set of $\mathcal{P}$-positions of $W^2$ is given by
\[
 \mathcal{R}_2=\{(0,0)\}\cup \{ \{n,2n+1\}\mid n\ge 0\}\cup \{\{2\lfloor n\phi\rfloor+2,2\lfloor n\phi^2\rfloor+2\}\mid n\ge 0\}.
\]
\end{theorem}

The authors provide a classical proof of their result by showing that the set of $\mathcal{P}$-positions described by \eqref{eq:Ppos} is both stable and absorbing (see Definition~\ref{def:stab}). The proof is quite long and requires a detailed case analysis. Without diminishing their achievement, once the set \eqref{eq:Ppos} has been conjectured, if the set can be handled by {\tt Walnut}, then it becomes straightforward to produce an automated proof in just a few lines. Our approach therefore complements the work carried out in \cite{Komak}.

In \cite{block}, other variants of Wythoff game are studied, in which some blocking maneuvers are added. Let $k\ge 1$. In the game denoted by $W^k$, for each move, before the next player (i.e., the player who is about to play) moves, the previous player (i.e., the one who has just played) may declare at most $k-1$ of the options as forbidden. When the next player has moved, any blocking maneuver is forgotten and has no further incidence on the game. This terminology of previous and next player explains why we speak of $\mathcal{N}$- and $\mathcal{P}$-positions, respectively. For $k=1$, this is the classical game of Wythoff. When $k=2,3$, we reconsider Larsson's result and obtain an automated proof, replacing a 2-page-long analysis by some easy-to-describe first-order formulas.

As Shallit has already noted on several occasions, the two approaches are complementary. A classical, purely combinatorial proof usually provides structural insights, whereas the use of automated provers helps avoid lengthy case analyses and enables the exploration of directions that are difficult to access through traditional techniques. In particular, in this article, we easily obtain a variety of results that would otherwise require significantly more effort using ``classical'' methods. Moreover, these results lead us to formulate general theorems.
\smallskip

This article is organized as follows. Section~\ref{sec:2} --- which was the starting point of this article --- aims to give an automatic proof of the algebraic characterization \eqref{eq:Ppos} of the $\mathcal{P}$-positions of $K^2$. We begin with preliminary results about Fibonacci-automatic sequences. We define a notion of $\varphi$-morphism and describe a heuristic that we extensively use throughout the paper to construct such $\varphi$-morphisms. Given a sufficiently long prefix of an infinite word, we obtain morphisms that can be used in our automatic proofs (and we can therefore prove the correctness of the procedure). Basic results from combinatorial game theory are given in Section~\ref{ssec:autom_proof}.

In Section~\ref{sec:newGame}, we obtain results about new games: a parameterized version of a variant of Wythoff game denoted by $K^\ell$, where the set of terminal states is
\[
  \{(x,y)\in\mathbb{N}^2\mid x+y\le \ell\}
\]
for some $\ell\in\mathbb{N}$. We study the games $K^1$, $K^3$ and $K^4$ and obtain algebraic characterizations of the $\mathcal{P}$-positions similar to \cite{Komak}. In particular, as for the classical Wythoff game $K^0$, the game $K^1$ has a nice set of $\mathcal{P}$-positions: a pair $(a,b)$ of integers such that $a\le b$ is a $\mathcal{P}$-position of $K^1$ if and only if its Fibonacci representation $\rep_F(a)$ ends with zero and $\rep_F(b)$ is of the form $\rep_F(a)1$, see Theorem~\ref{thm:carK1}.

In Section~\ref{sec:6}, we go further in the analysis of the games $K^\ell$ for an arbitrary $\ell\ge 1$. We provide a recursive characterization of the set of $\mathcal{P}$-positions. The non-terminal $\mathcal{P}$-positions $(a_n,b_n)_{n\ge 0}$ of $K^\ell$ are given, in Theorem~\ref{thm:rec_car}, by
\[
  (a_0,b_0)=(\ell+1,2\ell+2) \quad\text{ and }\quad \forall n\ge 1, \left\{
    \begin{array}{l}
a_n =\mex (\{ a_i,b_i \mid i<n \}\cup\{0,1,\ldots,\ell\}) \\
b_n =a_n+n+\ell+1.\\
    \end{array}
  \right.
\]
We prove this result in an automatic way for $\ell=1,2$, then extend it for all values of the parameter using classical arguments. With Corollary~\ref{cor:behave}, we generalize Theorem~\ref{thm:K2} and obtain that $(a_n,b_n)_{n\ge 0}$ are of the form
\[ a_n=\lfloor (n+\ell)\phi\rfloor + \lambda_\ell(n) \quad\text{ and }\quad
  b_n=\lfloor (n+\ell)\phi^2\rfloor + \lambda_\ell(n)+1\]
for some bounded integer-valued function $\lambda_\ell$. Our result can be related to the recent paper \cite{Letouzey} where discrepancy of generalized Hofstadter functions is studied (and formalized in {\tt Coq}). Our methods are inspired by   \cite{Fraenkel5,Kimberling2,Larsson}.

It is well-known that the set of $\mathcal{P}$-positions of the Wythoff game are coded by the Fibonacci word~$\mathbf{f}=abaababa\cdots$, see \cite{Vision,Duchene}. If we start indexing letters of~$\mathbf{f}$ with $1$, the indices of the letters $a$ (resp. $b$) in~$\mathbf{f}$ correspond to the sequence $(a_n)_{n\ge 0}$ (resp. $(b_n)_{n\ge 0}$). Using the recursive definition from the previous section, we obtain  similar results with $K^1,K^2,K^3$: their $\mathcal{P}$-positions are encoded by morphic words obtained by $\varphi$-morphisms and codings.

In Section~\ref{sec:3}, we obtain automatic proofs of Larsson's result about $W^2$ and $W^3$. Interestingly, the automata arising in the computations are much larger than those for $K^2$.

In Section~\ref{sec:redundant}, we are concerned with redundant moves of the games discussed so far. A move is considered {\em redundant} if, upon its removal from the rule-set, then the set of $\mathcal{P}$-positions remains unchanged. It is a classical question in combinatorial game theory: do distinct rule-sets yield the same set of $\mathcal{P}$-positions? In particular, can certain moves be added or removed without altering the $\mathcal{P}$-positions?

\begin{remark}
  A {\tt Jupyter} notebook recording all the {\tt Walnut} computations is available (it has been produced using Ollinger's {\tt Walnut-Kernel}.
  The {\tt Mathematica} code and the various {\tt Walnut} files are also available online\footnote{at {\tt https://hdl.handle.net/2268/338482}, you may also download a standalone Wolfram Player.}. In particular, the package permits us to compute $\mathcal{P}$-positions and $\varphi$-morphisms.
\end{remark}

To prove Theorem~\ref{thm:K2}, the authors “provide a classical proof … by showing that the set of $\mathcal{P}$-positions described by \eqref{eq:Ppos} is both stable and absorbing (see Definition~\ref{def:stab}).” They note that “the proof is quite long and requires a detailed case analysis.” They also indicate that, “once the set \eqref{eq:Ppos} has been conjectured,” an alternative route is to “produce an automated proof” (e.g., “if the set can be handled by {\tt Walnut}”).

To prove the main theorem, the authors “provide a classical proof … by showing that the set of $\mathcal{P}$-positions described by \begin{equation}\label{eq:Ppos}
  \left\{ (\lfloor n\phi\rfloor +g(n)-1, \lfloor n \phi^2\rfloor +g(n))\mid n\ge 0\right\} \cup
  \left\{ (\lfloor n \phi^2\rfloor +g(n), (\lfloor n\phi\rfloor +g(n)-1)\mid n\ge 0\right\}
\end{equation}
 is both stable and absorbing (see \begin{definition}\label{def:stab}
A set $S$ of positions is {\em stable} if, for all $s,t\in S$, $s\neq t$, there is no move between $s$ and $t$. A set $S$ of positions is {\em absorbing}, if for all $t\not\in S$, there exists $s\in S$ such that there is a move from $t$ to $s$ (or, $t$ has an option in $S$).
\end{definition}).” They note that “the proof is quite long and requires a detailed case analysis.” They also indicate that, “once the set in the equation above has been conjectured,” an alternative route is to “produce an automated proof” (e.g., “if the set can be handled by {\tt Walnut}”).

\label{thm:K2}
  The set of $\mathcal{P}$-positions of the variant of Wythoff game where the set of terminal positions is $\{(x,y)\mid x+y\le 2\}$,  is exactly \begin{equation}\label{eq:Ppos}
  \left\{ (\lfloor n\phi\rfloor +g(n)-1, \lfloor n \phi^2\rfloor +g(n))\mid n\ge 0\right\} \cup
  \left\{ (\lfloor n \phi^2\rfloor +g(n), (\lfloor n\phi\rfloor +g(n)-1)\mid n\ge 0\right\}
\end{equation}
where $g:\mathbb{N}\to\mathbb{N}$ is defined as follows: \begin{definition}\label{def:fg}
  We let $g(0)=1$, $g(1)=0$ and
  \[
    g(n)=\left\{
      \begin{array}{ll}
        1-g(m),& \text{ if }\lfloor n\phi\rfloor= \lfloor m(\phi+1)\rfloor+1 \text{ for some }m\ge 0;\\
        1,& \text{ otherwise}.
      \end{array}\right.
  \]

\end{definition}

Question:
Consider the Wythoff-type game on positions (x,y) ∈ ℕ² in which a move from (x,y) consists of replacing it by (x-n,y), (x,y-n), or (x-n,y-n), where n is any positive integer allowed by the coordinates. The terminal positions are exactly those with x+y ≤ 2, and under normal play a P-position means a losing position. Let φ=(1+√5)/2, and define g:ℕ→ℕ by g(0)=1, g(1)=0, and for n≥0,

 g(n)=1-g(m) if floor(nφ)=floor(m(φ+1))+1 for some m≥0, and g(n)=1 otherwise.

Which statement gives exactly the set of P-positions of this game?

The set of P-positions is exactly

{ (⌊nφ⌋+g(n)-1, ⌊nφ²⌋+g(n)) : n≥0 } ∪ { (⌊nφ²⌋+g(n), ⌊nφ⌋+g(n)-1) : n≥0 }.

Choices:
B.
The set of P-positions is exactly

{ (⌊nφ⌋+g(n), ⌊nφ²⌋+g(n)) : n≥0 } ∪ { (⌊nφ²⌋+g(n), ⌊nφ⌋+g(n)) : n≥0 }.
C.
Every position of the form

(⌊nφ⌋+g(n)-1, ⌊nφ²⌋+g(n))

with n≥0 is a P-position.
D.
The set of P-positions is exactly

{ (⌊nφ⌋+g(n)-1, ⌊nφ²⌋+g(n)) : n≥1 } ∪ { (⌊nφ²⌋+g(n), ⌊nφ⌋+g(n)-1) : n≥1 }.
E.
The set of P-positions is exactly

{ (⌊nφ⌋+g(n)-1, ⌊nφ²⌋+g(n)) : n≥0 }.

offset-by-1 needed for stability against terminal region and moves within the candidate set

dropped the converse exactness/union description, keeping only one included family of P-positions

symmetry of coordinates required for absorbing all non-candidate positions


Question:
Consider the variant of Wythoff game played on positions \((x,y)\in\mathbb N^2\) (with \(\mathbb N=\{0,1,2,\dots\}\)), where a move from \((x,y)\neq(0,0)\) consists of replacing it by \((x-n,y)\), \((x,y-n)\), or \((x-n,y-n)\) for some positive integer \(n\) with the coordinates remaining nonnegative. In this variant, every position with \(x+y\le 2\) is terminal, and moving into that terminal set wins. Which set is exactly the set of \(\mathcal P\)-positions (losing positions for the player to move)? Here \(\phi=(1+\sqrt5)/2\), and \(g:\mathbb N\to\mathbb N\) is defined by \(g(0)=1\), \(g(1)=0\), and for \(n\ge 2\),
\[
 g(n)=\begin{cases}
 1-g(m), & \text{if } \lfloor n\phi\rfloor=\lfloor m(\phi+1)\rfloor+1 \text{ for some } m\ge 0,\\
 1, & \text{otherwise.}
 \end{cases}
\]
Which explicit description gives all such \(\mathcal P\)-positions?

\[
\left\{\bigl(\lfloor n\phi\rfloor+g(n)-1,\ \lfloor n\phi^2\rfloor+g(n)\bigr)\mid n\ge 0\right\}
\ \cup\
\left\{\bigl(\lfloor n\phi^2\rfloor+g(n),\ \lfloor n\phi\rfloor+g(n)-1\bigr)\mid n\ge 0\right\}.
\]

Choices:
B.
\[
\left\{\bigl(\lfloor n\phi\rfloor+g(n),\ \lfloor n\phi^2\rfloor+g(n)\bigr)\mid n\ge 0\right\}
\ \cup\
\left\{\bigl(\lfloor n\phi^2\rfloor+g(n),\ \lfloor n\phi\rfloor+g(n)\bigr)\mid n\ge 0\right\}.
\]
C.
\[
\left\{\bigl(\lfloor n\phi\rfloor+g(n)-1,\ \lfloor n\phi^2\rfloor+g(n)\bigr)\mid n\ge 0\right\}.
\]
D.
\[
\left\{\bigl(\lfloor n\phi\rfloor+g(n)-1,\ \lfloor n\phi^2\rfloor+g(n)\bigr)\mid n\ge 1\right\}
\ \cup\
\left\{\bigl(\lfloor n\phi^2\rfloor+g(n),\ \lfloor n\phi\rfloor+g(n)-1\bigr)\mid n\ge 1\right\}.
\]
E.
\[
\left\{\bigl(\lfloor n\phi\rfloor+g(n)-1,\ \lfloor n\phi^2\rfloor+g(n)\bigr)\mid n\ge 0\right\}
\ \cap\
\left\{\bigl(\lfloor n\phi^2\rfloor+g(n),\ \lfloor n\phi\rfloor+g(n)-1\bigr)\mid n\ge 0\right\}.
\]


\begin{thm}[Kleiner--Leeb] \label{thm-klsph}
Let $B$ be a spherical building, let $C\subset B$ be a closed, convex, spherical subset. Then there exists an apartment $A\subset B$ which contains $C$.
\end{thm}

Euclidean buildings were introduced by Jacques Tits in \cite{Tits} and play an important role in different areas of mathematics. Their metric structure played a central role in super-rigidity results starting with \cite{KleinerLeeb1}, \cite{GS}. We refer to \cite{Linus},
 \cite{KLM} for further investigations of their metric properties and to \cite{BM} and the literature therein for super-rigidity questions related to Euclidean buildings.

The following result, possibly known to Bruce Kleiner and Bernhard Leeb, and verified in \cite{KleinerLeeb1} in a special case, has been discussed in other special cases in several independent works. In this note we provide a proof of this result:

The following result, possibly known to Bruce Kleiner and Bernhard Leeb, and verified in \cite{KleinerLeeb1} in a special case, has been discussed in other special cases in several independent works. In this note we provide a proof of this result:

All Euclidean buildings in this note, in particular, in Theorem \ref{thm-main}, are assumed to be complete, cf. Remark \ref{rem: non-complete} below for a comment about possible generalizations.

\begin{rem} \label{rem: non-complete}
 Here is the only place in this paper, where we discuss non-complete buildings, we refer to \cite{Parreau}, \cite{Str} for their discussion.
 In any non-complete Euclidean building, Theorem \ref{thm-main} cannot hold as stated. Indeed, any such building $X$ contains a (half-open) geodesic $\gamma:[0,1) \to X$, whose image $C$ is closed as a subset of $X$. Such $C$ cannot be contained in an apartment. However, an extension of Theorem \ref{thm-main} to non-complete Euclidean buildings and to
 $\Lambda$-buildings (cf. \cite{Schwer}) seems possible, we hope to discuss it in a forthcoming work.
\end{rem}

\begin{cor}
Let $C\subset B$ be a closed, convex, spherical subset in a spherical building $B$. Let $x\in C$ be arbitrary and let $A_x\subset \Sigma _x B$ be an apartment in the space of directions such that $\Sigma _xC\subset A_x$. Then there exists an apartment $A\subset B$ which contains $C$ and such that $\Sigma _xA=A_x$.
\end{cor}

\begin{cor} \label{cor: cone}
Let $C$ be a flat, closed, convex subset in a Euclidean building $X$. Assume that $C$ is a Euclidean cone with its tip at the point $x$. Let $A_x$ be an apartment in the tangent cone $T_xX$, which contains $T_xC$. Then $C$ is contained in an apartment $A$, such that $T_xA=A_x$.
\end{cor}

\begin{cor}
Let $F\subset X$ be a convex subset isometric to a Euclidean space in a Euclidean building $X$. Then for every $x\in F$ the tangent space $T_x(P(F))$ at $x$ to the parallel set $P(F)$ of $F$ coincides with the parallel set $P(T_xF)$ of the flat $T_xF$ in the building $T_xX$.
\end{cor}

\begin{lem} \label{lem: final}
 Let $X$ be a CAT(0) space. Let $Y_1,Y_2 $ be closed, convex subsets of $X$ isometric to convex subsets of some Euclidean spaces. Let $x\in Y_1\cap Y_2$ be a point and assume that
 \begin{enumerate}
 \item $T:={\operatorname{Log}}_x (Y_1) \cup {\operatorname{Log}}_x (Y_2) \subset T_xX \,$ is a convex subset of $T_xX$,
 \item ${\operatorname{Log}}_x (Y_1) \cap {\operatorname{Log}}_x (Y_2) ={\operatorname{Log}}_x (Y_1\cap Y_2)\,.$
 \end{enumerate}
 Then $Y:=Y_1\cup Y_2$ is a convex subset of $X$ isometric to $T$.
\end{lem}

Choose an arbitrary interior point $x$ of the facet $\mathcal F$. Then $T_x \mathcal P$ is a $k$-dimensional, flat halfspace in the tangent space $T_xX$. By Corollary \ref{cor: cone}, we find an apartment $A^x$ in the (infinitesimal) Euclidean building $T_xX$ with $T_x \mathcal P \subset A^x$.

\begin{rem} \label{rem: non-complete}
	Here is the only place in this paper, where we discuss non-complete buildings, we refer to  \cite{Parreau}, \cite{Str} for their discussion.
	In any non-complete Euclidean building, Theorem \ref{thm-main} cannot hold as stated. Indeed, any such building $X$ contains a (half-open) geodesic $\gamma:[0,1) \to X$, whose image $C$ is closed as a subset of $X$.  Such $C$ cannot be contained in an apartment. 	However, an extension  of Theorem \ref{thm-main} to non-complete Euclidean buildings and to
	 $\Lambda$-buildings (cf. \cite{Schwer})  seems possible, we hope to discuss it in a forthcoming work.
\end{rem}

\begin{thm} \label{thm-main}
	Let $X$ be a Euclidean  building.  Let $C\subset X$ be a convex subset of $X$
	which is isometric to a convex subset of some Euclidean space.  Then $C$ is contained in an apartment $A$  of $X$.

	Moreover, if for some $x\in C$ we choose an apartment  $A^x$  in the infinitesimal Euclidean building  $T_xX$ with $T_xC\subset A^x$ then $A$ can be chosen so that $T _xA=A^x$.
\end{thm}

All Euclidean buildings in this note, in particular, in Theorem \ref{thm-main}, are assumed to be complete, cf. Remark \ref{rem: non-complete} below for a comment about possible generalizations.

The analogue of the first part of this result  for spherical buildings is contained in   \cite{KleinerLeeb1}, see Theorem \ref{thm-klsph} below.
In some special cases,  Theorem \ref{thm-main} is contained in \cite{KleinerLeeb1} as well.

A different proof of the spherical theorem  was obtained later in \cite[Proposition 1.3]{BL} in a slightly more general setting.  Moreover, this approach also covered the case of Theorem \ref{thm-main} for discrete Euclidean buildings, \cite[Remark 1.4]{BL}.

For some convex subsets in discrete Euclidean buildings,  Theorem \ref{thm-main} is presented in \cite[Theorem 11.53]{Abram}. The case of convex triangles $C$ in Bruhat--Tits buildings appears in \cite[Exercise 2.3.10.3]{Rousseau}.  Several  special cases of  Theorem \ref{thm-main} have been obtained and used in \cite{BM}.

 \begin{rem} \label{rem: non-complete}
	Here is the only place in this paper, where we discuss non-complete buildings, we refer to  \cite{Parreau}, \cite{Str} for their discussion.
	In any non-complete Euclidean building, Theorem \ref{thm-main} cannot hold as stated. Indeed, any such building $X$ contains a (half-open) geodesic $\gamma:[0,1) \to X$, whose image $C$ is closed as a subset of $X$.  Such $C$ cannot be contained in an apartment. 	However, an extension  of Theorem \ref{thm-main} to non-complete Euclidean buildings and to
	 $\Lambda$-buildings (cf. \cite{Schwer})  seems possible, we hope to discuss it in a forthcoming work.
\end{rem}

  In Section \ref{sec: sph} we follow \cite{KleinerLeeb1}, in order to  reprove and  to extend the spherical version of our main theorem.   One major difference between the spherical and the Euclidean case is  the  finiteness of the simplicial decomposition of spherical apartments, which allows for a choice of a potential enlargement $A$  of the convex subset $C$.  In Section 4,  we prove Theorem \ref{thm-main} by enlarging the convex set step by step.  In order to make this enlargement procedure  successful, we deal with the case of convex polyhedra $C$ first,
  and then deduce the result for  general convex subsets  by an appropriate approximation.

{\bf Acknowledgments.} Alexander Lytchak is grateful to the authors of \cite{BM} for their interest in this topic, especially  to Christine Breiner, for several related questions, which gave rise to this project.    Raphael Appenzeller would like to thank Isobel Davies for discussions. Raphael Appenzeller and Auguste H\'ebert acknowledge support from the Procope project
"Buildings, galleries and beyond" and would like to thank its members, St\'ephane Gaussent, Zijun Li, Bianca Marchionna, Paul Philippe and Petra Schwer for helpful discussions.

In Section 4, the authors "prove Theorem \ref{thm-main} by enlarging the convex set step by step." To make this enlargement procedure work, they "deal with the case of convex polyhedra $C$ first, and then deduce the result for general convex subsets by an appropriate approximation." They also note (contrasting with the spherical case) that in the Euclidean case one cannot rely on "the finiteness of the simplicial decomposition of spherical apartments," which in the spherical setting "allows for a choice of a potential enlargement $A$ of the convex subset $C$."

Next, the authors prove the main theorem by enlarging the convex set step by step. To make this enlargement procedure work, they deal with the case of convex polyhedra $C$ first, and then deduce the result for general convex subsets by an appropriate approximation. They also note (contrasting with the spherical case) that in the Euclidean case one cannot rely on the finiteness of the simplicial decomposition of spherical apartments, which in the spherical setting allows for a choice of a potential enlargement $A$ of the convex subset $C$.

Question: Let $X$ be a complete Euclidean building, and let $C\subset X$ be a convex subset that is isometric to a convex subset of some Euclidean space. For a point $x\in C$, let $T_xX$ denote the tangent cone at $x$ (the infinitesimal Euclidean building at $x$), and let $T_xC\subset T_xX$ denote the tangent cone of $C$ at $x$. Suppose that, for some chosen $x\in C$, an apartment $A^x\subset T_xX$ satisfies $T_xC\subset A^x$. Which conclusion holds under these hypotheses?

There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, if $x\in C$ and an apartment $A^x\subset T_xX$ is chosen with $T_xC\subset A^x$, then $A$ can be chosen so that $T_xA=A^x$.

Choices:
B. There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, for every $x\in C$ and every apartment $A^x\subset T_xX$ with $T_xC\subset A^x$, the same apartment $A$ can be chosen so that $T_xA=A^x$.
C. There exists an apartment $A\subset X$ such that $C\subset A$.
D. There exists an apartment $A\subset X$ such that $C\subset A$ provided that $C$ is a convex polyhedron. Moreover, if $x\in C$ and an apartment $A^x\subset T_xX$ is chosen with $T_xC\subset A^x$, then $A$ can be chosen so that $T_xA=A^x$ in this polyhedral case.
E. There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, if $x\in C$ and an apartment $A^x\subset T_xX$ is chosen with $T_xC\subset A^x$, then every apartment $A\subset X$ containing $C$ satisfies $T_xA=A^x$.

dependence of the global apartment on the chosen tangent apartment and point

dropped the prescribed tangent-space matching condition $T_xA=A^x$

approximation step from convex polyhedra to arbitrary convex Euclidean subsets

existential choice of apartment containing $C$ replaced by a uniqueness-type condition on all such apartments


Question: Let $X$ be a complete Euclidean building, and let $C\subset X$ be a convex subset that is isometric to a convex subset of some Euclidean space. An apartment in a Euclidean building is one of its Euclidean-flat charts. For a point $x\in C$, let $T_xX$ denote the tangent cone of $X$ at $x$ (the infinitesimal Euclidean building at $x$), and let $T_xC$ denote the tangent cone of $C$ at $x$. Which existence statement holds under these assumptions?

There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, if $x\in C$ and $A^x$ is an apartment of $T_xX$ with $T_xC\subset A^x$, then $A$ can be chosen so that $T_xA=A^x$.

Choices:
B. There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, if $x\in C$ and $A^x$ is an apartment of $T_xX$ with $T_xC\subset A^x$, then every apartment $A\subset X$ containing $C$ automatically satisfies $T_xA=A^x$.
C. There exists an apartment $A\subset X$ such that $C\subset A$.
D. There exists an apartment $A\subset X$ such that $C\subset A$. Moreover, for every $x\in C$ there is an apartment $A^x$ of $T_xX$ with $T_xC\subset A^x$ such that one can choose a single apartment $A$ satisfying $T_xA=A^x$ simultaneously for all $x\in C$.
E. If $x\in C$ and $A^x$ is an apartment of $T_xX$ with $T_xC\subset A^x$, then there exists an apartment $A\subset X$ such that $C\cap U\subset A$ for some neighborhood $U$ of $x$, and $T_xA=A^x$.

existential choice of ambient apartment upgraded to uniqueness for all containing apartments

dropped the prescribed tangent-apartment conclusion

single global apartment forced to realize tangent data simultaneously at every point

global containment of the whole convex set weakened to merely local containment near the chosen point


\begin{theorem}\label{thm:square}
We have $|\cS_2(n)|=(\frac{1}{2}-o(n^{-1/15})) 2^{2n}$.
\end{theorem}

Let $[k]^{*}$ be the collection of words of finite length over the finite alphabet $[k] = \{1,\ldots, k\}$, and say $s'\in [k]^*$ is a \textit{subword} of $s \in [k]^*$ if $s'$ is a (not necessarily contiguous) subsequence of $s$. A \textit{shuffle square} is a word $s\in [k]^*$ that can be partitioned into two disjoint, identical subwords. Shuffle squares were first studied by Henshall, Rampersad, and Shallit~\cite{henshall}, in the theory of formal languages. In this area, Boulteau and Vialette~\cite{binarynphard} proved that recognizing binary shuffle squares is NP-complete, building on work of Rizzi and Vialette~\cite{unshufflelargek} and Buss and Soltys~\cite{unshuffle7buss} on larger alphabets.

As shuffle squares must have even length, it is convenient to say that a word of length $2n$ has \textit{semi-length} $n$. Let $\cS_k(n)$ be the set of shuffle squares of semi-length $n$ over the alphabet $[k]$. Henshall, Rampersad, and Shallit asked for the asymptotics of $|\cS_k(n)|$, and gave conjectural asymptotic formulas for $n$ fixed and $k\rightarrow\infty$. These formulas were verified by the first author, Huang, Nam, and Thaper~\cite{HHNT}, who also posed the following surprising conjecture in the opposite regime, where $k=2$ is fixed and $n\rightarrow \infty$, supported by numerical evidence from the OEIS~\cite{oeis}.

\begin{conjecture}[\cite{HHNT}]
Asymptotically half of all even-length binary words are shuffle squares, that is, $|\cS_2(n)| = (\frac{1}{2}-o(1)) 2^{2n}$.
\end{conjecture}

Note that shuffle squares must have an even count of each letter, so this conjecture states that almost all words satisfying this obvious parity constraint are actually shuffle squares. Towards this, they proved using a greedy algorithm that $|\cS_2(n)| \ge \binom{2n}{n} = \Theta(n^{-1/2}2^{2n})$. Our main theorem resolves this conjecture in the affirmative with an explicit polynomial error term.

\begin{conjecture}[\cite{HHNT}]
Asymptotically half of all even-length binary words are shuffle squares, that is, $|\cS_2(n)| = (\frac{1}{2}-o(1)) 2^{2n}$.
\end{conjecture}

Note that shuffle squares must have an even count of each letter, so this conjecture states that almost all words satisfying this obvious parity constraint are actually shuffle squares. Towards this, they proved using a greedy algorithm that $|\cS_2(n)| \ge \binom{2n}{n} = \Theta(n^{-1/2}2^{2n})$. Our main theorem resolves this conjecture in the affirmative with an explicit polynomial error term.

The exponent $-1/15$ is not optimized, but within a modest factor of the best possible using our arguments. It would be interesting to decide if the error term is actually polynomial or exponential.

While previous work dealt with the worst-case behavior of $\rm{LT}(s)$, \cref{thm:square} implies the best possible bound for its average-case behavior.
\begin{corollary}\label{corollary:lt} For almost all $s\in\{0,1\}^{n}$, $\rm{LT}(s)\geq \sceil{\frac{n}{2}}-1$.
\end{corollary}

\begin{lemma}\label{lem:pt_decomposition} Let $s\in\{0,1\}^\omega$ be uniformly random. Let $\cev q_t(w;v)=q_t(\rev(w);\rev(v))$.
Then for all $v\in\{0,1\}^*$,
\begin{equation}\label{eq:pt_as_qt}
\PP[v\in B_n(s)]=\cev q_n(\emptyword;v)+\frac 12\sum_{t=0}^{n-1}\sum_{w\in \{0,1\}^*}\Big(\delta_t(1w1,w)\cev q_{n-t-1}(w1;v)+\delta_t(0w0,w)\cev q_{n-t-1}(w0;v)\Big).
\end{equation}
In particular, we have
\begin{equation}\label{eq:pt_as_qt_beta}
\PP[\emptyword\in B_n(s)]=q_n(\emptyword)+\sum_{t=0}^{n-1}\sum_{w1\in \Sigma_2^{(01)}}\delta_t(1w1,w) q_{n-t-1}(\rev(w1)).
\end{equation}
\end{lemma}
Roughly speaking, \eqref{eq:pt_as_qt_beta} captures the fact that any successful buffer thread $(w_j)_j$ has a critical first time $n-t-1$ at word $w_{n-t-1}=1w$ where it diverges from the greedy algorithm.
\begin{proof}
We prove \eqref{eq:pt_as_qt} by induction on $n$. By construction, $\PP[v\in B_0]=\bbone_{v=\emptyword}=q_0(\emptyword;\rev(v))$. Observe that for any word $v1$ ending in $1$, we have
\begin{align*}
\PP[v1\in B_{n+1}]&=\PP[s(n+1)=1]\PP[(v\in B_n)\cup (1v1\in B_n)]+\PP[s(n+1)=0]\PP[0v1\in B_n]\\
&=\frac 12\Big(\PP[v\in B_n]+\delta_n(1v1,v)+\PP[0v1\in B_n]\Big).
\end{align*}
Observe that $q_n$ satisfies a similar recurrence: for each initializiation of the form $1v'$, we can condition on the first bit of $s$ to get
\begin{align*}
q_n(w;1v')&=\PP[s(1)=1]\PP[\greedy(s[2,n],v')=w]+\PP[s(1)=0]\PP[\greedy(s[2,n],1v'0)=w]\\
&=\frac 12(q_{n-1}(w;v')+q_{n-1}(w;1v'0)).
\end{align*}
Reversing the words, we obtain
\[
\cev q_n(w;v1)=\frac 12(\cev q_{n-1}(w;v)+\cev q_{n-1}(w;0v1)).
\]
Denote the RHS of~\eqref{eq:pt_as_qt} by $Q_n(v)$. Since the above is a linear recurrence relation, $Q_n$ obeys the same equation, plus the added terms at time $n+1$:
\[
Q_{n+1}(v1)=\frac 12(Q_n(v)+Q_n(0v1))+\frac 12\sum_{w\in \{0,1\}^*}\Big(\delta_n(1w1,w)\cev q_{0}(w1;v1)+\delta_n(0w0,w)\cev q_{0}(w0;v1)\Big)
\]
Recall that $\cev q_0(w;v)=\bbone_{w=v}$, so the summation evaluates to $\frac 12\delta_n(1v1,v)$. Thus by induction, $\PP[v1\in B_{n+1}]=Q_{n+1}(v1)$. By symmetry, $\PP[v0\in B_{n+1}]=Q_{n+1}(v0)$, showing \eqref{eq:pt_as_qt} holds for all nonempty words $v$ at time $n+1$.

We prove that $X^*_1$ has the desired statistics and $X^*_2$ is a negligible perturbation. First, consider $X^*_1$. Since $X,Z$ are independent, we immediately have $\Ex[(X-1)\bbone_{Z=0}]=\frac12 (k-1)$, and $\Ex[(X-1-k)^2\bbone_{Z=0}]=\frac 12(2k+1)$. Next we control the second term in $X_1^*$; both technical claims below are proven in Section~\ref{section:numericalclaims}.
\begin{claim}\label{claim:Ybounds} (Proved in~\cref{section:numericalclaims}.) With $X,Y,Z$ as defined above, $\Ex[(Y-Z)\bbone_{Z>0}]=\frac 12(k-3+2^{-k})$ and $\Ex[(Y-Z-k)^2\bbone_{Z>0}]<4k+9$.
\end{claim}
Together, we have
\begin{align*}
\Ex[X^*_1-k]&=\frac 12(k-1)+\frac 12(k-3+2^{-k})-k=-2+2^{-k-1},\quad\text{and}\\
\Ex[(X^*_1-k)^2]&=\Ex[(X^*_1-k)^2\bbone_{Z=0}]+\Ex[(X^*_1-k)^2\bbone_{Z>0}]<\frac 12(2k+1)+\frac 12(4k+9)=3k+5.
\end{align*}
Next, we control $X^*_2$. Because $\PP[X=0]
=2^{-k}$, it is simple to check that $\Ex[\max(Z,1)\bbone_{X=0}]=\frac 32\cdot 2^{-k}$ and $\Ex[\max(Z,1)^2\bbone_{X=0}]=\frac 72\cdot 2^{-k}$, which are very small. The next claim bounds the $2C'$ term.
\begin{claim}\label{claim:C'bounds}(Proved in~\cref{section:numericalclaims}.) With $M,Z,C'$ as defined above, $\Ex[C']\leq 2(7/8)^{k'}$ and $\Ex[(C')^2]\leq 6(7/8)^{k'}$.
\end{claim}
We conclude that $\Ex[X^*_2],\Ex[(X^*_2)^2]=O((7/8)^k)$. Therefore,
\[
\Ex[X^*-k]=\Ex[X^*_1-k]+\Ex[X^*_2]=-2+O((7/8)^k),
\]
and similarly by the Minkowski inequality,
\[
\Ex[(X^*-k)^2]\leq \Big(\sqrt{\Ex[(X^*_1-k)^2]}+\sqrt{\Ex[(X^*_2)^2]}\Big)^2=3k+5+o(1)
\]
This proves~\eqref{eq:algorithmstep2}. To obtain tail bounds~\eqref{eq:algorithmstep3} and~\eqref{eq:algorithmstep4}, first note that
\begin{equation}\label{eq:T*expection}
T^*\leq T_3= (k+X)+(Z+1)+(X-1+Y),
\end{equation}
and thus $\Ex[T^*]\leq 4k$. By considering cases, we have
\[\PP[T^* \geq (4+5\eps)k]\leq \PP[X\geq (1+\eps)k]+\PP[Y\geq (1+2\eps)k\mid X<(1+\eps)k]+\PP[Z\geq \eps k]\]
By the definition of $Z$, we have $\PP[Z\geq \eps k]=2^{-\eps k}$. For the other two terms, recall that $X\sim \rm{NB}(k)$, and the conditional distribution $\big(Y\mid X< (1+\eps)k\big)$ is stochastically dominated by $\rm{NB}((1+\eps)k)$. Both terms can be bounded by Proposition \ref{prop:nbchernoff}, so
\[
\PP[T^*\geq (4+5\eps)k]\leq 3e^{-\Omega(\eps^2k/(1+\eps))},
\]
which gives~\eqref{eq:algorithmstep3}. We obtain tail bounds on $X^*$ similarly. Using~\eqref{eq:X*expression}, we concentrate $X^*$ by bounding $X,Y$, and $Z$, noting that $|2C'-Z|\leq |Z|$:
\begin{multline*}
\PP[|X^*-k|\geq 3\eps k]\leq \PP[Z\geq \eps k]+\PP[|X-k-1|\geq \eps k]+
\PP\big[|Y-k|\geq 2\eps k\ \big|\ |X-k-1|<\eps k\big].
\end{multline*}
Verifying that each of these is bounded by $e^{-\Omega(\eps^2k/(1+\eps))}$, we conclude~\eqref{eq:algorithmstep4}.
\end{proof}

\begin{problem}\label{prob:ternary} Is it true that $|\cS_3(n)|=(9-o(1))^n$?
\end{problem}
\noindent This problem is closely related to the extremal problem of determining whether $\rm{LT}(3,n)=(\frac 12-o(1))n$. The following one directional implication follows from work of Bukh and Zhou.
\begin{theorem}[{\cite[Theorem 4]{bukhzhou}}]\label{prop:alphatwins} If $\cS_k(n)\leq (b_k)^{2n+o(n)}$ and there exists $\alpha_k\in (2/k,1)$ such that
\[
\alpha_k\log\Big(\frac{b_k}{\alpha_kk}\Big)+(1-\alpha_k)\log \Big(\frac{k-1}{k(1-\alpha_k)}\Big)<0,
\]
then $\rm{LT}(k,n)< \frac 12\alpha_kn$ for sufficiently large $n$. In particular, if $b_k<k$, then we can take $\alpha_k<1$.
\end{theorem}
\noindent This can be obtained by a union bound over all ``leftmost" embeddings of shuffle squares in a random word $s$. Though we do not offer a conjecture on Problem~\ref{prob:ternary}, numerical evidence suggests that $|\cS_3(n)|=o(9^n)$.

The exponent $-1/15$ is not optimized, but within a modest factor of the best possible using our arguments. It would be interesting to decide if the error term is actually polynomial or exponential.

Closely related to the shuffle square problem is the ``twins'' problem introduced by Axenovich, Person, and Puzynina~\cite{Axenovich}. For a word $s\in [k]^*$, let $\rm{LT}(s)$ be the maximum semi-length of a subword of $s$ that is a shuffle square, so $s\in \cS_k(n)$ if and only if $\rm{LT}(s)=n$. Equivalently, $\rm{LT}(s)$ is the largest $m$ such that $s$ contains ``twins'' of length $m$, i.e. disjoint identical subwords of length $m$. Axenovich, Person, and Puzynina proved that for any $s\in \{0,1\}^{2n}$, we have $\rm{LT}(s)=(1-o(1))n$. More progress has been made on twins for various alphabets~\cite{basu,bukhzhou}, and the twins problem is related to regularity lemmas for words, the longest common subsequence problem \cite{bukhhogenson,bukhma,ChvatalSankoff,He-Li}, and codes for correcting deletion errors \cite{Guruswami-He-Li}.

While previous work dealt with the worst-case behavior of $\rm{LT}(s)$, \cref{thm:square} implies the best possible bound for its average-case behavior.
\begin{corollary}\label{corollary:lt} For almost all $s\in\{0,1\}^{n}$, $\rm{LT}(s)\geq \sceil{\frac{n}{2}}-1$.
\end{corollary}

\begin{proof} Let $s\in \{0,1\}^{2n}$ be uniformly random among words with an even number of $0$'s and $1$'s. If $\rm{LT}(s)=n$, then by deleting one or two bits, we immediately have $\rm{LT}(s[1,2n-1])=n-1$ and $\rm{LT}(s[1,2n-2])\geq n-2$. Thus by \cref{thm:square},
\[
\PP[\rm{LT}(s[1,2n-2])\geq n-2]\geq \PP[\rm{LT}(s[1,2n-1])=n-1]\geq \PP[s\in \cS_2(n)]=1-o(1).
\]
Moreover, $s[1,2n-1]$ is uniformly random in $\{0,1\}^{2n-1}$ and $s[1,2n-2]$ is uniformly random in $\{0,1\}^{2n-2}$, implying the corollary.
\end{proof}

In \cite{HHNT}, it was conjectured that almost every binary word can be made into a shuffle square by deleting at most three bits - \cref{corollary:lt} shows that it actually suffices to delete two (which is best possible).

\par{\bf Organization.} In Section~\ref{section:preliminaries}, we introduce the notion of a \textit{buffer} for a binary word, thereby reformulating the problem as a discrete stochastic process on subsets of $\{0,1\}^*$. We define and analyze the greedy algorithm using buffers and obtain asymptotic results on its behavior. In Section~\ref{section:buffersetanalysis}, we analyze the evolution of the set of all buffers to show that a random word $s$ can ``absorb" small defects in an almost-perfect partition. In Section~\ref{section:boostedgreedy}, we give an improved algorithm which produces a shuffle square with constant probability. This boosted greedy algorithm stores local information about the word and occasionally backtracks for an improvement. Together with the buffer set analysis, this proves~\cref{thm:square}. In Section~\ref{section:conclusion}, we discuss the shuffle square problem on larger alphabets, and we provide a boosted greedy algorithm for $k$-ary words which gives a new lower bound for $|\cS_k(n)|$.

In the ".\par{\bf Organization.}" paragraph, the authors outline how they prove Theorem~\ref{thm:square}: (1) they "introduce the notion of a \textit{buffer} for a binary word, thereby reformulating the problem as a discrete stochastic process on subsets of $\{0,1\}^*$"; (2) they "define and analyze the greedy algorithm using buffers and obtain asymptotic results on its behavior"; (3) they "analyze the evolution of the set of all buffers to show that a random word $s$ can \`\`absorb\" small defects in an almost-perfect partition"; (4) they "give an improved algorithm which produces a shuffle square with constant probability"—a "boosted greedy algorithm" that "stores local information about the word and occasionally backtracks for an improvement"; (5) "[t]ogether with the buffer set analysis, this proves~\cref{thm:square}."

In the ".\par{\bf Organization.}" paragraph, the authors outline how they prove the main theorem: (1) they "introduce the notion of a \textit{buffer} for a binary word, thereby reformulating the problem as a discrete stochastic process on subsets of $\{0,1\}^*$"; (2) they "define and analyze the greedy algorithm using buffers and obtain asymptotic results on its behavior"; (3) they "analyze the evolution of the set of all buffers to show that a random word $s$ can \`\`absorb\" small defects in an almost-perfect partition"; (4) they "give an improved algorithm which produces a shuffle square with constant probability"—a "boosted greedy algorithm" that "stores local information about the word and occasionally backtracks for an improvement"; (5) "[t]ogether with the buffer set analysis, this proves the main theorem."

Question: Let $[2]^*$ be the set of all finite binary words over $\{0,1\}$. A word $s'\in[2]^*$ is a subword of $s\in[2]^*$ if $s'$ is a subsequence of $s$ (not necessarily contiguous). A binary word $s$ of length $2n$ is called a shuffle square if its positions can be partitioned into two disjoint subwords that are identical as words. Let $\mathcal S_2(n)$ denote the set of shuffle squares of semi-length $n$, i.e. binary shuffle squares of length $2n$. Which asymptotic estimate holds for $|\mathcal S_2(n)|$ as $n\to\infty$?

$|\mathcal S_2(n)|=\left(\frac{1}{2}-o\!ig(n^{-1/15}\big)\right)2^{2n}$.

Choices:
B. $|\mathcal S_2(n)|=\left(\frac{1}{2}+o\!\big(n^{-1/15}\big)\right)2^{2n}$.
C. $|\mathcal S_2(n)|=\left(\frac{1}{2}-o(1)\right)2^{2n}$.
D. $|\mathcal S_2(n)|=\left(\frac{1}{2}-O\!\big(n^{-1/15}\big)\right)2^{2n}$.
E. $|\mathcal S_2(n)|\geq \left(\frac{1}{2}-o\!\big(n^{-1/15}\big)\right)2^{2n}$.

defect-absorption yields a deficit from $1/2$, not an excess

explicit polynomial error term $o(n^{-1/15})$

non-effective little-o error replaced by stronger big-O control

exact asymptotic equality replaced by one-sided lower bound at the same scale