Words in Random Binary Sequences I

Abstract: When flipping a fair coin, let $W = L_1L_2...L_N$ with $L_i\in\{H,T\}$ be a binary word of length $N=2$ or $N=3$. In this paper, we establish second- and third-order linear recurrence relations and their generating functions to discuss the probabilities $p_{W}(n)$ that binary words $W$ appear for the first time after $n$ coin tosses.

\section{Introduction}

\noindent
Consider a game in which one flips a balanced (fair) coin until one gets a given word like $HH$ (two heads in a row) or $HT$ (a head followed by a tail). The less flips it takes, the more one will win. Which word would be better to bet on: $HH$ or $HT$?

\smallskip
\noindent
 More generally, let $W=L_1L_2...L_N$ with $L_i\in\{H,T\}$ be a binary word of length $N$.  In this paper we determine the number of ways $a_{W}(n)$ that binary words $W$ of lengths $N=2$ or $N=3$ can appear {\it for the first time} after $n$ coin tosses, where $n \in \mathbb{N} = \{1,2,3,...\}$. The essential two-letter words are $HH$ and $HT$; by replacing all $H$'s with $T$'s and vice versa, one obtains the words $TT$ and $TH$.

\smallskip \noindent
As a first example, consider the word $W=HT$. When flipping a coin once, there are $2$ possible outcomes: $H$ and $T$. Therefore, $a_{HT}(1)=0$. When flipping a coin twice, there are $2^2$ possible outcomes: $HH,HT,TH,TT$. Therefore, $a_{HT}(2)=1$. Finally, when flipping a coin three times, there are $2^3$ possible outcomes: $HHH$, $HHT$, $HTH$, $HTT$, $TTT$, $TTH$, $THT$, $THH$. Therefore, $a_{HT}(3)=2$.

\begin{figure}[htp]
    \centering
    \includegraphics[width=12cm]{TreeDiagramHT.png}
    \caption{$a_{HT}(n)$ for $1\le n \le 6$ are given by $0,1,2,3,4,5$}

\end{figure}
\noindent
As we will prove in Theorem 2.1, $a_{HT}(n)=n-1$ for all  $n\in\mathbb{N}$. As a consequence, we will prove that one can expect to flip a coin four times until one gets---for the first time---the word $HT$.

\newpage

\noindent
As a second example, consider the word $W=HH$.

\begin{figure}[htp]
    \centering
    \includegraphics[width=12cm]{TreeDiagram.png}
    \caption{$a_{HH}(n)$ for $1\le n \le 6$ are given by $0,1,1,2,3,5$}
    \label{fig:galaxy}
\end{figure}
\noindent As we will prove, the sequence $a_{HH}(n)$ is indeed the Fibonacci sequence; i.e., $a_{HH}(n+2) = a_{HH}(n+1) + a_{HH}(n)$ for all $ n\ge 1$, with $a_{HH}(1) = 0$ and $a_{HH}(2) = 1$.  We use this to show that one can expect to flip a coin six times until one gets---for the first time---the word $HH$ (see also \cite{HH}). Thus, in the aforementioned game, it is better to bet on $HT$ than on  $HH$. Also, the gambler should know that in about $10\%$  of trials it takes $7$ or more coin flips until one receives a head followed by a tail and  $12$ or more coin flips until one receives a head followed by a head (see Corollaries 2.2 and 2.3).

\smallskip\noindent
In Section 3 of this paper, we will prove recursion formulas of the type
$$a_{W}(n+3) = Aa_{W}(n+2) + Ba_{W}(n+1)+ C a_{W}(n)$$ for all three-letter words. The numbers $A,B,C$ as well as the first 15 terms of the sequences $a_W(n)$ are summarized in the following table.

\smallskip

\begin{center}
\begin{tabular}{ |c|c|c|c|c| }
 \hline
  W & A, B, C & Sequence $a_W(n)$ for $1\le n\le 15$  \\
  \hline
 HHH & 1, ${}$ 1, ${}$ 1    & 0, 0, 1, 1, 2, 4, ${}$ 7, 13, 24, 44, 81, 149, 274, 504, 927\\
 HTT & 2, ${}$ 0, -1 & 0, 0, 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609 \\
 HHT & 2, ${}$ 0, -1 & 0, 0, 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609 \\
 HTH & 2, -1, ${}$ 1 & 0, 0, 1, 2, 3, 5, ${}$ 9, 16, 28, 49, 86, 151, 265, 465, 816 \\

 \hline
\end{tabular}
\end{center}

\smallskip\noindent
Observe that the formulas for $TTT$, $THH$, $TTH$, and $THT$ are identical to the ones in the table above by replacing all $H$'s with $T$'s and vice versa.

\smallskip\noindent
Part II of this paper (\cite{EHMN}) contains recursive formulas for $a_W(n)$ for binary words $W$  of arbitrary length $N$. That is, for words with $N$ letters, there are constants $A_i$ ($1\le i \le N$) such that
$$a_{W}(n+N) = \sum_{i=1}^N A_i a_W(n+N-i)$$
with $a_W(k) = 0$ for all $1\le k\le N-1$ and $a_W(N) = 1$.

\bigskip \noindent\noindent
The probabilities  $p_{W}(n)$ that binary words $W$ appear {\it for the first time} after $n$ coin tosses are given by
\begin{equation} \label{prob}
p_W(n) = a_W(n)\left(\frac{1}{2}\right)^n.
\end{equation}
Then,
$$ p_W(\le m) := \sum_{n=1}^m p_W(n) =  \sum_{n=1}^m a_W(n) \left(\frac{1}{2}\right)^n
$$
is the probability that  a binary word $W$ appears {\it for the first time} during the first $m$ coin tosses and
\begin{equation*}
p_W(\ge m+1) = 1-p_W(\le m)
\end{equation*}
is the probability that it takes {\bf at least} $m+1$ coin tosses for the binary word $W$ to appear {\it for the first time}.
To study the probabilities $p_W$ and to determine the expected value
$\mu_W = \hbox{Exp}_W = \sum_{n=1}^\infty n\, p_W(n)$
as well as the variance
$\hbox{Var}_W = \sum_{n=1}^\infty n^2\, p_W(n) - \mu_W^2$
and standard deviation
$\sigma_W = \sqrt{\hbox{Var}_W}$
of coin flips needed so that a binary word $W$ appears {\it for the first time}, we consider the generating functions
\begin{equation} \label{gf} f_W(x) = \sum_{n=1}^\infty a_W(n) \, x^n
\hbox{ and }f_{W,m}(x) = \sum_{n=1}^m a_W(n) x^n.
\end{equation}
Since $1\le a_W(n)\le 2^n$ for $n\ge 1$, it follows that the radius of convergence $R(f_W)$ of the power series $f_W$ satisfies $\frac{1}{2} \le R(f_W) \le 1$.
\begin{proposition} \label{Prop1} Let $p_W(n)$, $f_{W}(x)$, and $f_{W,m}(x)$ be defined as in (\ref{prob}) and (\ref{gf}). Then $p_W(\le m) = f_{W,m}(1/2)$. Moreover, if $R(f_W) > \frac{1}{2}$, then
\smallskip
\begin{itemize}
    \item[(a)] $\mu_w = \frac{1}{2}f'_W(\frac{1}{2})$,
    \item[(b)] $\sigma_W = \sqrt{\hbox{Var}_W}$, where $\hbox{Var}_W = \frac{1}{4}f''_W(\frac{1}{2}) + \mu_W -  \mu_W^2.$
\end{itemize}
\end{proposition}
\begin{proof}
Clearly,
$p_W(\le m) = \sum_{n=1}^m p_W(n) =  \sum_{n=1}^m a_W(n) (\frac{1}{2})^n = f_{W,m}(1/2).$
Because
$xf'_W(x) = \sum\limits_{n=1}^\infty n \, a_W(n) \, x^n, $ it follows that
$$ \mu_w = \hbox{Exp}_W = \sum_{n=1}^\infty n\, p_W(n) =   \sum_{n=1}^\infty n\, a_W(n) (\frac{1}{2})^n = \frac{1}{2}f'_W(\frac{1}{2}).$$
This shows (a). To prove (b), observe that
$$xf'_W(x) + x^2 f''_W(x) = x(xf'_W(x))' = \sum_{n=1}^\infty n^2 \, a_W(n) \, x^n.$$  This shows that
\begin{align*}
 \hbox{Var}_W  &=  \sum_{n=1}^\infty n^2\, p_W(n) - \mu_W^2  = \sum_{n=1}^\infty n^2\, a_W(n)(\frac{1}{2})^n - \mu_W^2   \\
 &= \frac{1}{2}f'_W(\frac{1}{2}) + \frac{1}{4}f''_W(\frac{1}{2}) -  \mu_W^2
 = \frac{1}{4}f''_W(\frac{1}{2}) + \mu_W -  \mu_W^2.
\end{align*}
\end{proof}
\goodbreak

\section{Two-Letter Words}

\begin{theorem}
When flipping a fair coin,  let $a_{W}(n)$ be the number of ways that the word $W = HT$ or $W = HH$ can appear for the first time at the $n$-th coin toss. Then,
\begin{equation}  \label{HT} a_{HT}(n+1) = a_{HT}(n) +1 \quad \hbox{ and}
\end{equation}
\begin{equation} \label{HH}
    a_{HH}(n+2) = a_{HH}(n+1) + a_{HH}(n)
\end{equation}
for all $ n\ge 1$, with $a_{W}(1) = 0$ and $a_{W}(2) = 1$.
{\footnote{ For (\ref{HT}), the sequence $a_{HT}$ is given by $\{0,1,2,3,4,\dots\}$ or A001477 in \cite{OEIS}. There, the connection of A001477 to $a_{HT}$ is not  yet stated.  An alternative way to describe the sequence $a_{HT}(n)$ is given by the recursive formula $a_{HT}(n+1) = 2a_{HT}(n) - a_{HT}(n-1)$. This follows directly from  (\ref{HT}) since $2a_{HT}(n) - a_{HT}(n-1) = 2(a_{HT}(n-1)+1) - a_{HT}(n-1) = a_{HT}(n-1)+2 = a_{HT}(n)+1 = a_{HT}(n+1)$.  The fact that the sequence $a_{HH}$ is given by the Fibonacci numbers $\{0,1,1,2,3,5,\dots\}$ was established by Matthew Leingang \cite{HH}; see also A000045 in \cite{OEIS}. There, it is noted that $a_{HH}(n)$ is the ``number of binary sequences of length n-2 that have no consecutive 0's."}}
\end{theorem}

\begin{proof}
(\ref{HT}): The statements $a_{HT}(1)=0$ and $a_{HT}(2)=1$ are obvious. To examine $a_{HT}(n+1)$, let $\mathcal{M}_{n+1}$ denote the set of sequences of $H$'s and $T$'s of length $n+1$ that contain the word $HT$ only at the end. Then, $a_{HT}(n+1) = |\mathcal{M}_{n+1}|$. We denote the  sequences in $\mathcal{M}_{n+1}$ that start with a $T$ by $\mathcal{M}^{T}_{n+1}$ and those that start with an $H$ by $\mathcal{M}^{H}_{n+1}$. Then,  $\mathcal{M}_{n+1}$ is the disjoint union of $\mathcal{M}^{H}_{n+1}$ and $ \mathcal{M}^{T}_{n+1}$.  Thus, $$a_{HT}(n+1) = |\mathcal{M}_{n+1}| = |\mathcal{M}^{T}_{n+1}| + |\mathcal{M}^{H}_{n+1}|.$$
If $x\in \mathcal{M}^{H}_{n+1}$, then $x$ must be the sequence $HHHH{\ldots}HT$. Thus, $|\mathcal{M}^{H}_{n+1}| = 1$.  If $x\in \mathcal{M}^{T}_{n+1}$, then there exists a unique $y\in \mathcal{M}_{n}$ such that $x=Ty$.  Define a map $\Phi : \mathcal{M}^{T}_{n+1} \to \mathcal{M}_{n}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Thus, $ |\mathcal{M}^{T}_{n+1}| = |\mathcal{M}_{n}|= a_{HT}(n)$, or
$$a_{HT}(n+1) = |\mathcal{M}^{T}_{n+1}| + |\mathcal{M}^{H}_{n+1}|= a_{HT}(n) +1.$$

\medskip
\noindent
(\ref{HH}): The statements $a_{HH}(1)=0$ and $a_{HH}(2)=1$ are obvious. To examine $a_{HH}(n)$, let $\mathcal{M}_n$ denote the set of sequences of $H$'s and $T$'s of length $n$ that contain the word $HH$ only at the end. Then, $a_{HH}(n) = |\mathcal{M}_n|$. Let $\mathcal{N}_n$ the set of sequences of length $n$ that end with an $T$ and do not contain the word $HH$. Now, if $x\in\mathcal{M}_{n+2}$, then there exists a unique $y\in\mathcal{N}_n$ such that $x = yHH$. Define $\Phi: \mathcal{M}_{n+2} \to \mathcal{N}_n$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$ a_{HH}(n+2) = |\mathcal{M}_{n+2}| = |\mathcal{N}_n|.$$
Let $\mathcal{N}_n^{TT}, \mathcal{N}_n^{HT}$ be the sets of sequences in $\mathcal{N}_n$ that end with $TT$ or $HT$, respectively. Then, $\mathcal{N}_n$ is the disjoint union of  $\mathcal{N}_n^{TT}$ and $\mathcal{N}_n^{HT}$. Thus,
$$|\mathcal{N}_n| = |\mathcal{N}_n^{TT}| + |\mathcal{N}_n^{HT}|.$$
If $x\in \mathcal{N}_n^{TT}$, then there exists a unique $y\in \mathcal{N}_{n-1}$ such that $x=yT$. Define $\Phi: \mathcal{N}_n^{TT} \to \mathcal{N}_{n-1}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$|\mathcal{N}_n^{TT}|= |\mathcal{N}_{n-1}| = |\mathcal{M}_{n+1}| = a_{HH}(n+1) .$$
If $x\in \mathcal{N}_n^{HT}$, then $x$ must end with the word $THT$ since $x$ cannot contain the word $HH$ before the last $T$. That is, for every  $x\in \mathcal{N}_n^{HT}$, there exists a unique $y\in\mathcal{N}_{n-2}$ such that $x=yHT$.  Define $\Phi: \mathcal{N}_n^{HT} \to \mathcal{N}_{n-2}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$|\mathcal{N}_n^{HT}|= |\mathcal{N}_{n-2}| = |\mathcal{M}_{n}| = a_{HH}(n) .$$
The equalities above imply that
$a_{HH}(n+2) = a_{HH}(n+1) + a_{HH}(n)$ for all $n\ge 1$ with $a_{HH}(1) = 0$ and  $a_{HH}(2) = 1$.

\end{proof}

\begin{corollary} If one flips a fair coin,  then $a_{HT}(n) = n-1$  for all $n\ge 1$. The expected value of flips it takes for the word $HT$ to appear for the first time is
$\mu_{HT} = 4$ with standard deviation $\sigma_{HT} = 2$.\footnote{Observe that this is different from \cite{HT} where the expected number of flips required to observe at least one head and one tail is discussed.} Moreover, $$p_{HT}(\ge N) = \frac{a_{HT}(N+1)}{2^{N-1}} = \frac{N}{2^{N-1}} .$$ In particular, $p_{HT}(\ge 7) = 7/64 \approx 0.11$.
\end{corollary}

\begin{proof}
Since $a_{HT}(n) = a_{HT}(n-1) +1$ and $a_{HT}(1)=0$, it follows that $a_{HT}(n)=n-1$ for all $n\ge 1$.
Let $$h(x) := \sum_{n=1}^m x^n = \frac{1-x^{m+1}}{1-x} -1.$$
Then, $xh'(x) = \sum_{n=1}^m n\, x^n$. Therefore, for $|x|<1$ and $m\to\infty$, the generating functions $f_{HT,m}(x)$ and $f_{HT}(x)$ are given by
\begin{align*} f_{HT,m}(x) &= \sum_{n=1}^m (n-1) x^n = \sum_{n=1}^m n\, x^n - \sum_{n=1}^m x^n = xh'(x) - h(x) \\ &= \frac{x^2}{(1-x)^2}\left[ 1 - x^{m-1}(m(1-x)+x)\right] \\ & \to f_{HT}(x) = \sum_{n=1}^\infty (n-1) x^n = \frac{x^2}{(1-x)^2}.
\end{align*}
It follows that
 $f'_{HT}(x) = \frac{2x}{(1-x)^3}$ and   $f''_{HT}(x) = \frac{4x+2}{(1-x)^4}$.
Since $R(f_{HT}) =1$, Proposition \ref{Prop1} yields $\mu_w = \frac{1}{2}f'_{HT}(\frac{1}{2}) = 4$, $\hbox{Var}_W = \frac{1}{4}f''_W(\frac{1}{2}) + \mu_W -  \mu_W^2 = 4$, and $p_{HT}(> m) = 1-p_W(\le m) = 1- f_{HT,m}(\frac{1}{2}) = (m+1)/2^m.$

\end{proof}

\begin{corollary} If one flips a fair coin,  then, for $n\ge 1$,
\begin{align} \label{fib}
a_{HH}(n) = \hbox{\rm Round}\left[ \frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^{n-1} \right]
\end{align}
is the Fibonacci sequence $a_{HH} = \{0,1,1,2,3,5,8,13,21,\dots\}$.  The  expected value of flips it takes for the word $HH$ to appear for the first time is
$\mu_{HH} = 6$
with standard deviation  $\sigma_{HH} = \sqrt{22} \approx 4.7$. Moreover,
$$p_{HH}(\ge N) = \frac{a_{HH}(N+2)}{2^{N-1}}.$$
In particular, $p_{HH}(\ge 12) \approx 0.1$.
\end{corollary}

\begin{proof} To simplify writing, define $a_n:= a_{HH}(n)$ and $$f_m(x) := f_{HH,m}(x)= \sum_{n=1}^m a_{HH}(n) x^n = \sum_{n=1}^m a_nx^n.$$    Then,   $f_{HH}(x) = \sum_{n=1}^\infty a_{HH}(n) x^n = \lim_{m\to\infty} f_m(x)$ exists for $|x|<\frac{1}{2}$. By (\ref{HH}) and  $a_1=a_{HH}(1)=0$, it follows that
\begin{align*}
    f_m(x) &= x^2 + \left( a_2+ a_1\right) x^3 + \left( a_3+ a_2\right) x^4 + \dots + (a_{m-1}+a_{m-2})x^m \\ &= x^2 + \left( a_2x^3 +  a_3x^4 + \cdots  +a_{m-1}x^m\right)\\
    & \qquad \qquad  + \left( a_2x^4 +  a_3x^5 + \cdots + +a_{m-2}x^m\right)\\
    &= x^2 + x\left(f_m(x)- a_mx^m\right) + x^2\left(f_m(x) - a_{m-1}x^{m-1} - a_mx^m\right)\\
    &= xf_m(x)+ x^2f_m(x) +x^2\left(1-a_mx^{m-1} - a_{m-1}x^{m-1}-a_mx^m \right)\\
    &= xf_m(x)+ x^2f_m(x) +x^2\left(1-a_{m+1}x^{m-1}-a_mx^m \right).
    \end{align*}
 This implies that
 \begin{align*} f_{HH,m}(x) = f_m(x) = \frac{-x^2}{x^2+x-1}\left[ 1 -a_{HH}(m+1)x^{m-1} - a_{HH}(m)x^{m}\right].
\end{align*}
Taking the limit as $m\to\infty$ yields
\begin{align*} f_{HH}(x) = \frac{-x^2}{x^2+x-1} = -1 + \frac{x-1}{x^2+x-1} = -1 + \frac{x-1}{(x_1-x)(x_2-x)}
\end{align*}
for
$x_1 = (-1+\sqrt{5})/{2}$ and $x_2 = (-1-\sqrt{5})/{2}$.
Using partial fractions, the geometric series representation of
$$\frac{1}{x_i-x} = \frac{1}{x_i}\left(\frac{1}{1-\frac{x}{x_i}}\right) = \sum_{n=0}^\infty \left(\frac{1}{x_i}\right)^{n+1} x^n,$$
and a substantial amount of straightforward algebra, one obtains Binet's Formula (see also \cite{Binet}); namely,
$$ f_{HH}(x) = \sum_{n=1}^\infty \frac{1}{\sqrt{5}}\left[ \left(\frac{1+\sqrt{5}}{2}\right)^{n-1}- \left(\frac{1-
\sqrt{5}}{2}\right)^{n-1}\right] x^n =
\sum_{n=1}^\infty a_{HH}(n) x^n.$$ Now, (\ref{fib}) follows from the fact that $a_{HH}(n)\in \mathrm{N}$ and $\left| \frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^{n-1}  \right| < \frac{1}{2}$ for all $n\ge 1$. Since $f_{HH}(x) = \frac{-x^2}{x^2+x-1}$, it follows that
$$ f'_{HH}(x) = \frac{-x(x-2)}{(x^2+x-1)^2} \hbox{ , } f''_{HH}(x) = \frac{2(x^3-3x^2-1)}{(x^2+x-1)^3}  ,$$
and $R(f_{HH}) = x_1 = (-1+\sqrt{5})/{2} >\frac{1}{2}$. By Proposition \ref{Prop1}, $\mu_{HH} = \frac{1}{2}f'_{HH}(\frac{1}{2}) = 6$ (see also \cite{HH}), $\sigma_{HH} = \sqrt{\frac{1}{4}f''_{HH}(\frac{1}{2}) + \mu_{HH} -  \mu_{HH}^2} =  \sqrt{22}$,
and
\begin{align*}
p_{HH}(> m) & = 1-p_{HH}(\le m) = 1- f_{HH,m}(\frac{1}{2}) \\ &= a_{HH}(m+1)\left(\frac{1}{2}\right)^{m-1} + a_{HH}(m)\left(\frac{1}{2}\right)^{m}\\
&=\left[2a_{HH}(m+1)+ a_{HH}(m)\right]\left(\frac{1}{2}\right)^{m}
= a_{HH}(m+3)\left(\frac{1}{2}\right)^{m}.
\end{align*}

\end{proof}

\section{Three-Letter Words}
\begin{theorem} When flipping a coin n times, let $W$ be one of the words $HHH, HTH, HTT, HHT$\footnote{The words $TTT$, $THH$, $TTH$, and $THT$ can be obtained by replacing all $H$'s with $T$'s and vice versa and the table  yields the corresponding recursion formulas.}, and let $a_{W}(n)$ be the number of ways that the word $W$ can appear for the first time at the $n$-th coin toss.
Then, $a_{W}(1) = a_{W}(2) = 0$, $a_{W}(3) = 1$, and
$$a_{W}(n+3) = Aa_{W}(n+2) + Ba_{W}(n+1)+ C a_{W}(n),$$ where the numbers $A,B,C$ as well as the first 15 terms of the sequences $a_W(n)$ are summarized in the following table.{\footnote{In \cite{OEIS}, the sequences for $HHH$, $HTT$, and $HTH$ are A000073, A000071, and A005314. There, the equivalent property of $a_{HHH}(n)$---that it gives the ``number of binary sequences of length n-3 that have no three consecutive 0's"---is noted. It also mentions that $a_{HTT}(n) = a_{HHT}(n)$ has the equivalent property that it gives the ``number of 001-avoiding binary words of length n - 3." Additionally, \cite{OEIS} touches on an equivalent property of $a_{HTH}(n)$, stating that it is ``the number of binary words of length n that begin with 1 and avoid the subword 101." }}
\smallskip

\begin{center}
\begin{tabular}{ |c|c|c|c|c| }
 \hline
  W & A, B, C & Sequence $a_W(n)$ for $1\le n\le 15$  \\
  \hline
 HHH & 1, ${}$ 1, ${}$ 1    & 0, 0, 1, 1, 2, 4, ${}$ 7, 13, 24, 44, 81, 149, 274, 504, 927\\
 HTT & 2, ${}$ 0, -1 & 0, 0, 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609 \\
 HHT & 2, ${}$ 0, -1 & 0, 0, 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609 \\
 HTH & 2, -1, ${}$ 1 & 0, 0, 1, 2, 3, 5, ${}$ 9, 16, 28, 49, 86, 151, 265, 465, 816 \\

 \hline
\end{tabular}
\end{center}
\end{theorem}

\smallskip
\begin{proof} Clearly, $a_{W}(1) = 0$, $a_{W}(2) = 0$, and $a_{W}(3) = 1$ for all three-letter words $W$. We now prove the four cases $HHH, HTH, HTT, HHT$ separately. In parts (I) - (III) below, note that $\mathcal{N}_n$ denotes different sets.

\smallskip \noindent
(I) $W = HHH$. Consider $a_n :=a_{HHH}(n)$ for $n>3$. Let $\mathcal{M}_n$ denote the set of sequences of $H$'s and $T$'s of length $n$ that contain the word $HHH$ only at the end. Then, $a_n = |\mathcal{M}_n|$. Let $\mathcal{N}_n$ be the set of sequences of length $n$ that end with a $T$ and do not contain the word $HHH$. Now, if $x\in\mathcal{M}_{n+3}$, then there exists a unique $y\in\mathcal{N}_n$ such that $x = yHHH$. Define $\Phi: \mathcal{M}_{n+3} \to \mathcal{N}_n$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$a_{n+3} = |\mathcal{M}_{n+3}| = |\mathcal{N}_n|.$$
Let $\mathcal{N}_n^{TT}, \mathcal{N}_n^{THT}, \mathcal{N}_n^{HHT}$ be the sets of sequences in $\mathcal{N}_n$ that end with $TT$, $THT$ or $HHT$, respectively. Then, $\mathcal{N}_n$ is the disjoint union of  $\mathcal{N}_n^{TT}$, $\mathcal{N}_n^{THT}$ and $\mathcal{N}_n^{HHT}$. Thus, $$|\mathcal{N}_n| = |\mathcal{N}_n^{TT}| + |\mathcal{N}_n^{THT}| + |\mathcal{N}_n^{HHT}|.$$
If $x\in \mathcal{N}_n^{TT}$, then there exists a unique $y\in N_{n-1}$ such that $x=yT$. Define $\Phi: \mathcal{N}_n^{TT} \to \mathcal{N}_{n-1}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$|\mathcal{N}_n^{TT}|= |\mathcal{N}_{n-1}| = |\mathcal{M}_{n+2}| = a_{n+2} .$$
If $x\in \mathcal{N}_n^{THT}$, then there exists a unique $y\in\mathcal{N}_{n-2}$ such that $x=yHT$.  Define $\Phi: \mathcal{N}_n^{HT} \to \mathcal{N}_{n-2}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$|\mathcal{N}_n^{HT}|= |\mathcal{N}_{n-2}| = |\mathcal{M}_{n+1}| = a_{n+1} .$$
If $x\in \mathcal{N}_n^{HHT}$, then $x$ must end with the word $THHT$ since $x$ cannot contain the word $HHH$ before the last $T$. That is, for every  $x\in \mathcal{N}_n^{HHT}$,  there exists a unique $y\in\mathcal{N}_{n-3}$ such that $x=yHHT$.  Define $\Phi: \mathcal{N}_n^{HHT} \to \mathcal{N}_{n-3}$ by $\Phi(x) := y$. Then, $\Phi$ is one-to-one and onto. Therefore,
$$|\mathcal{N}_n^{HT}|= |\mathcal{N}_{n-3}| = |\mathcal{M}_{n}| = a_n .$$
The equalities above imply that
$a_{n+3} = a_{n+2} + a_{n+1} + a_n$ for all $n\ge 1$.

\smallskip \noindent
(II) $W = HTT$ or $W = HHT$. Let $\mathcal{M}_n$ denote the set of sequences of $H$'s and $T$'s of length $n$ that contain the word $W$ only at the end. Then, $a_n:= a_{W}(n) = |\mathcal{M}_n|$. For each $x\in \mathcal{M}_{n-1}$, one creates two new sequences of length $n$ by placing an $H$ or a $T$ at the beginning of $x$. The set of these sequences is denoted by $\mathcal{L}_{n}$. Note that $\mathcal{L}_{n}$ contains $2a_{n-1}$ sequences, all ending with the word  $W$; i.e., $|\mathcal{L}_{n}|=2a_{n-1}$. Since $\mathcal{M}_{n} \subseteq \mathcal{L}_{n}$, we consider  $\mathcal{N}_{n} :=  \mathcal{L}_{n}\setminus \mathcal{M}_{n}$ and note that $\mathcal{L}_n = \mathcal{M}_n\, \dot\cup \, \mathcal{N}_n$ (disjoint union). Therefore,
	 $$2a_{n-1}= |\mathcal{L}_n| = |\mathcal{M}_n| + |\mathcal{N}_n| = a_n + |\mathcal{N}_n|.$$
	 Every sequence $x\in \mathcal{N}_n$ contains at least one occurrence of the word $W$ before the word $W$ at the end of the sequence. However, since all sequences in $\mathcal{N}_n$  are derived from adding a letter to the beginning of every sequence in $\mathcal{M}_{n-1}$, each $x\in\mathcal{N}_n$ must contain the word $W$ as its first three letters. Thus, each $x\in\mathcal{N}_n$ must begin with the word $W$ and end with it, with no occurrences of the word $W$ in between; i.e., for each $x\in\mathcal{N}_n$ there exists a unique $y\in \mathcal{M}_{n-3}$ such that $x= Wy$. Define $\Phi: \mathcal{N}_n \to \mathcal{M}_{n-3}$ by $\Phi(x):= y$. Then, $\Phi$ is one-to-one and onto. Therefore, $|\mathcal{N}_n| = |\mathcal{M}_{n-3}| = a_{n-3}$, and  $ 2a_{n-1} = a_n + a_{n-3}$. This shows that  $a_n = 2a_{n-1} -a_{n-3}$.

	 \smallskip \noindent
(III) $W = HTH$.
Let $\mathcal{M}_n$ denote the set of sequences of $H$'s and $T$'s of length $n$ that contain the word $HTH$ only at the end. Then, $a_n:=a_{HTH}(n) = |\mathcal{M}_n|$. For each $x\in \mathcal{M}_{n-1}$, one creates two new sequences of length $n$ by placing an $H$ or a $T$ at the beginning of $x$. The set of these sequences is denoted by $\mathcal{L}_{n}$. Note that $\mathcal{L}_{n}$ contains $2a_{n-1}$ sequences, all ending with $HTH$; i.e., $|\mathcal{L}_{n}|=2a_{n-1}$. Since $\mathcal{M}_{n} \subseteq \mathcal{L}_{n}$, we consider  $\mathcal{N}_{n} :=  \mathcal{L}_{n}\setminus \mathcal{M}_{n}$ and note that $\mathcal{L}_n = \mathcal{M}_n\, \dot\cup \, \mathcal{N}_n$ (disjoint union). Therefore,
	 \begin{equation*}
	 2a_{n-1}= |\mathcal{L}_n| = |\mathcal{M}_n| + |\mathcal{N}_n| = a_n + |\mathcal{N}_n|.
	 \end{equation*}
	 Every sequence $x\in \mathcal{N}_n$ contains at least one occurrence of the word $HTH$ before the $HTH$ at the end of the sequence. However, since all sequences in $\mathcal{N}_n$  are derived from adding a letter to the beginning of every sequence in $\mathcal{M}_{n-1}$, each $x\in\mathcal{N}_n$ must contain the word $HTH$ as its first three letters. Thus, each $x\in\mathcal{N}_n$ must begin with $HTH$ and end with it, with no occurrences of the word $HTH$ in between; i.e., for each $x\in\mathcal{N}_n$ there exists a unique $y\in \mathcal{M}_{n-3}$ such that $x= HTHy$. This does not imply an onto map between $\mathcal{N}_n$ and $\mathcal{M}_{n-3}$, as $y$ can not begin with the two-letter sequence $TH$. However, let us denote the set $\mathcal{M}_{n-2}^H$ as the set of $n - 2$ length sequences where $HTH$ appears only at the end and which begin with $H$. Then, we can construct a one-to-one and onto map $\Phi:\mathcal{N}_n \to \mathcal{M}_{n-2}^H$ defined by $\Phi(HTHy) = Hy$ for every $y \in \mathcal{M}_{n-3}$. Now we will verify that $\mathcal{M}_{n-2}^H = a_{n-2} - a_{n-3}$. Indeed, if we also denote the sets of $n - 2$ length sequences where $HTH$ appears only at the end and which begin with $T$ as $\mathcal{M}_{n-2}^T$, then it is clear that $a_{n-2} = |\mathcal{M}_{n-2}^H| + |\mathcal{M}_{n-2}^T|$. We can construct a map $\Phi': \mathcal{M}_{n-2}^T \to \mathcal{M}_{n-3}$ defined by $\Phi'(Ty) = y$ for $y \in \mathcal{M}_{n-3}$ which is clearly one-to-one and onto. As such, this implies $|\mathcal{M}_{n-2}^T| = a_{n-3}$. Hence,
	 $ a_{n-2} = |\mathcal{M}_{n-2}^H| + |\mathcal{M}_{n-2}^T| = |\mathcal{M}_{n-2}^H| + a_{n-3}$, or
	 \begin{equation*}
	     |\mathcal{M}_{n-2}^H| = a_{HTH}(n-2) - a_{HTH}(n-3).
	 \end{equation*}
	 Since we know that $|\mathcal{N}_{n}| = |\mathcal{M}_{n-2}^H|$, we have
	 \begin{equation*}
	     2a_{n-1} = |\mathcal{M}_n| + |\mathcal{N}_n| = a_n + a_{n-2} - a_{n-3}.
	 \end{equation*}
	 Thus, $
	     a_n = 2a_{n-1} - a_{n-2} +a_{n-3}.$
\end{proof}
\goodbreak

\begin{proposition} \label{Rec3} Consider the recurrence relation
$$a_n = Aa_{n-1} + Ba_{n-2} + Ca_{n-3} \hbox{ for }n\ge 4$$
with $a_1 = a_2 = 0$, and $a_3 = 1$. Then, the finite generating function $f_m(x) = \sum_{n=1}^m a_nx^n$ is given by
$$ \frac{-x^3}{Cx^3+Bx^2 +Ax-1} \left(1-x^m\left(\frac{a_{m+1}}{x^{2}} + \frac{Ba_m + Ca_{m-1}}{x}+Ca_m\right)\right) .$$
Moreover, for $x$ with sufficiently small magnitude, the generating function $f(x) = \lim_{m\to\infty}f_m(x) $ is given by
\begin{align*}f(x) &= \frac{-x^3}{Cx^3+Bx^2 +Ax-1}=  \frac{-x^3}{C(x-a)(x-b)(x-c)}
= \sum_{n=1}^\infty a_nx^n,
\end{align*}
where $a,b,c$ are the three roots of $Cx^3+Bx^2 +Ax-1=0$ and
\begin{align}\label{a_n}
  a_{n} =  \frac{a^{2-n}(b-c)-b^{2-n}(a-c)+c^{2-n}(a-b)}{C(a-b)(a-c)(b-c)}.
\end{align}
\end{proposition}

\smallskip
\begin{proof}
 Since $a_1 = 0$, $a_2 = 0$, and $a_3 = 1$, it follows that
\begin{align*}
    f_m(x) &= x^3 + \left( Aa_3 + Ba_2+ Ca_1\right) x^4 + \left(Aa_4+ Ba_3+ Ca_2\right) x^5 +\cdots \\
    & \qquad \qquad + (Aa_{m-1}+Ba_{m-2}+ Ca_{m-3})x^m \\
    &= x^3 + A\left( a_3x^4 +  a_4x^5 + \cdots  +a_{m-1}x^m\right)\\
    & \qquad \qquad  + B\left( a_2x^4 +  a_3x^5 + \cdots + +a_{m-2}x^m\right)\\
    & \qquad \qquad \qquad  + C\left( a_1x^4 +  a_2x^5 + \cdots + +a_{m-3}x^m\right)\\
    &= x^3 + Ax\left(f_m(x)- a_mx^m\right) \\
    & \qquad \quad + Bx^2\left(f_m(x) - a_{m-1}x^{m-1} - a_mx^m\right)\\
     & \qquad \quad \qquad + Cx^3\left(f_m(x) - a_{m-2}x^{m-2}- a_{m-1}x^{m-1} - a_mx^m\right)
     \end{align*}
    \begin{align*}
    &= Axf_m(x)+ Bx^2f_m(x) + Cx^3f_m(x) +x^3\\
    & \qquad \qquad - \left[Aa_{m}+Ba_{m-1}+Ca_{m-2}\right]x^{m+1}\\
    &\qquad\qquad \qquad- \left[Ba_m + Ca_{m-1}\right]x^{m+2}-Ca_mx^{m+3} \\
    &= Axf_m(x)+ Bx^2f_m(x) + Cx^3f_m(x) \\
    & \qquad \qquad + x^3\left(1-x^m\left(\frac{a_{m+1}}{x^{2}} + \frac{Ba_m + Ca_{m-1}}{x}+Ca_m\right) \right).
    \end{align*}
 This implies that $f_m(x)$ is given by
 \begin{align*}
 \frac{-x^3}{Cx^3+Bx^2 +Ax-1} \left(1-x^m\left(\frac{a_{m+1}}{x^{2}} + \frac{Ba_m + Ca_{m-1}}{x}+Ca_m\right)\right) .
\end{align*}
By (\ref{prob}), for $|x|<1/2$,
$$f(x) = \sum_{n=1}^\infty a_nx^n = \lim_{m\to\infty} f_m(x) = \frac{-x^3}{Cx^3+Bx^2 +Ax-1}$$
The Mathematica\textsuperscript{\textregistered}
command
``$\hbox{SeriesCoefficient}[-x^3/((x - a)*(x - b)*(x - c)), \{x, 0, n\}]$" yields the explicit formula for $a_n$ as stated (\ref{a_n}).
\end{proof}

 \smallskip

 \begin{corollary}
 Let $W = HHH$. Then, $a_{W}(1) = a_{W}(2) = 0$, $a_{W}(3) = 1$ and, for all $n\ge 1$, $a_{W}(n+3) = a_{W}(n+2) + a_{W}(n+1)+ a_{W}(n)$ is given by
\begin{align} \label{HHH}
a_{W}(n)
=\hbox{\rm{Round}}\left[ \frac{a^{2-n}}{(a-b)(a-c)} \right],
\end{align}
where $a,b,c$ are the three roots of $x^3+x^2+x-1=0$. Namely,
$ a =\frac{-1}{3}-\frac{2}{3K}+ \frac{K}{3} \approx 0.54.$, $
    b =\frac{1}{3}\left(-1+\frac{1+i\sqrt{3}}{K}-\frac{K(1-i\sqrt{3})}{2}\right)
    \approx -0.77 + 1.12 i$, and
    $c = \overline{b}$
    for $K:=(17+3\sqrt{33})^{1/3}$.
The expected value of flips it takes for the word $W=HHH$ to appear for the first time is
$\mu_{W} = 14$
with standard deviation  $\sigma_{W} = \sqrt{142} \approx 11.9$.  Moreover,
\begin{align*}
p_{W}(\ge N) = \frac{2a_{W}(N+2)- a_{W}(N-1)}{2^{N-1}}.
\end{align*}
In particular, $p_{W}(\ge 30) \approx 0.1$.

\end{corollary}

\smallskip
\begin{proof}
To simplify writing, let $W = HHH$, $a_n:= a_{W}(n)$, and $$f_m(x) := f_{W,m}(x)= \sum_{n=1}^m a_{W}(n) x^n = \sum_{n=1}^m a_nx^n.$$ By Proposition \ref{Rec3}, it follows that
\begin{align*} f_{m}(x) = \frac{-x^3}{x^3+x^2+x-1}\left[ 1 -R_m(x)\right],
\end{align*}
where $R_m(x) = x^m\left(\frac{a_{m+1}}{x^{2}} + \frac{a_m + a_{m-1}}{x}+a_m\right),$
and
\begin{align*}  f_{W}(x) = \lim_{m\to\infty}f_m(x) =  \frac{-x^3}{x^3+x^2+x-1}.
\end{align*}
It follows that
$ f'_{W}(x) = -\frac{x^2(x-1)(x+3)}{(x^3+x^2+x-1)^2}$, and$$
f''_{W}(x) = \frac{(2x+2x^2)(x^4 +2x^3-8x^2+6x-3)}{(x^3+x^2+x-1)^3}  .$$
By using the Mathematica\textsuperscript{\textregistered} command
``$\hbox{Solve}[x^3 + x^2 + x - 1 == 0, x]$,"
one obtains $x^3 + x^2 + x - 1 = (x-a)(x-b)(x-c)$ with $a, b, c$ as stated above.  Now, (\ref{HHH}) follows from the fact that $a_{W}(n)\in\mathbb{N}$  and that, by (\ref{a_n}),
$$ a_{W}(n) =  a_n = \frac{a^{2-n}}{(a-b)(a-c)} + R(n), $$ where
$R(n) := \frac{b^{2-n}(c-a)+c^{2-n}(a-b)}{(a-b)(a-c)}$ has absolute value less than $ \frac{1}{2}$  for all $n\ge 1$.
Finally, it follows from (\ref{HHH}) that $R(f_{W}) >1/2$. Thus, by Proposition \ref{Prop1},
$\mu_{W} = \frac{1}{2}f'_{W}(\frac{1}{2}) = 14$ (see also \cite{HHH}),
$\sigma_{W} = \sqrt{\hbox{Var}_{W}} = \sqrt{\frac{1}{4}f''_{W}(\frac{1}{2}) + \mu_{W}^{} -  \mu_{W}^2} = \sqrt{142}$,
and
\begin{align*}
p_{W}(> m) & = 1-p_{W}(\le m) = 1- f_{W,m}(\frac{1}{2}) = R_m\left(\frac{1}{2}\right) \\
&= \left(\frac{1}{2}\right)^m\left(4a_{m+1} + 3a_m + 2a_{m-1}\right)
= \left(\frac{1}{2}\right)^m\left(2a_{m+3} -a_m \right).
\end{align*}
\end{proof}

\begin{corollary}
Let $W = HHT$ or $W=HTT$. Then, $a_{W}(1) = a_{W}(2) = 0$, $a_{W}(3) = 1$ and, for all $n\ge 1$, $a_{W}(n+3) = 2a_{W}(n+2) - a_{W}(n)$ is given by the ``Fibonacci-Minus-One" sequence $ \{0,0,1,2,4,7,12,20,33,54,\dots\}$, where
\begin{align} \label{HHTa}
a_W(n) = \hbox{\rm Round}\left[ \frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^{n} \right]-1
\end{align}

\smallskip\noindent
The expected value of flips it takes for the word $W$ to appear for the first time is
$\mu_{W} = 8$
with standard deviation  $\sigma_{W} =\sqrt{24} \approx 4.9$; the probability of obtaining the word $W$ for the first time at or past the $N$-th flip is given by
\begin{align*}
p_W(\ge N) = \frac{2a_W(N+1)- a_W(N-1)}{2^{N-1}}.
\end{align*}
In particular, $p_{W}(\ge 15) \approx 0.1$.

\end{corollary}

\smallskip
\begin{proof}
To simplify writing, let $W = HTT$ or $W=HHT$, $a_n:= a_{W}(n)$, and $$f_m(x) := f_{W,m}(x)= \sum_{n=1}^m a_{W}(n) x^n = \sum_{n=1}^m a_nx^n.$$ By Proposition \ref{Rec3}, one obtains
$$f_{m}(x) = \frac{-x^3}{-x^3+2x-1}\left[ 1 -R_m(x)\right],$$ where
$R_m(x) = x^m\left(\frac{a_{m+1}}{x^{2}} - \frac{a_{m-1}}{x}-a_m\right)$ and
$$f_{W}(x) = \lim_{m\to\infty}f_m(x) =  \frac{-x^3}{-x^3+2x-1}.$$
Then,
$ f'_{W}(x) = \frac{x^2(3-4x)}{(-x^3+2x-1)^2}$, and  $f''_{W}(x) = \frac{-2x(6x^4-6x^3+4x^2-6x+3)}{(-x^3+2x-1)^3}.$
By using the Mathematica\textsuperscript{\textregistered} command
``$\hbox{Solve}[-x^3 + 2x - 1 == 0, x],$''
one finds the decomposition $-x^3 + 2x - 1 = -(x-a)(x-b)(x-c)$ with
$a = 1$, $
    b  = (-1-\sqrt{5})/2$, and $
    c = (-1+\sqrt{5})/{2}$. By (\ref{a_n}),
$$ a_{W}(n) =  \frac{b^{2-n}(a-c)+c^{2-n}(b-a)}{(a-b)(a-c)(b-c)} + R(n), $$ where
$R(n) := \frac{-a^{2-n}}{(a-b)(a-c)} = - 1$ for all $n\ge 1$.
With some algebra,
\begin{align*}
a_{W}(n) &= \frac{1}{\sqrt{5}}\left[ \left(\frac{1+\sqrt{5}}{2}\right)^{n}- \left(\frac{1-
\sqrt{5}}{2}\right)^{n} \right]-1\\
&= \hbox{\rm Round}\left[ \frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^{n} \right]-1.
\end{align*}
Finally, it follows from (\ref{HHTa}) that $R(f_{W}) >1/2$. Thus, by Proposition \ref{Prop1},
$\mu_{W} = \frac{1}{2}f'_{W}(\frac{1}{2}) = 8$ (see also \cite{HTT}),
$\sigma_{W} = \sqrt{\frac{1}{4}f''_{W}(\frac{1}{2}) + \mu_{W}^{} -  \mu_{W}^2} = \sqrt{24}$,
and
\begin{align*}
p_{W}(> m)&= 1-p_{W}(\le m) = 1- f_{W,m}(\frac{1}{2}) = R_m\left(\frac{1}{2}\right) \\
&= \left(\frac{1}{2}\right)^m\left(4a_{m+1} - a_m - 2a_{m-1}\right)
= \left(\frac{1}{2}\right)^m\left(2a_{m+2} -a_m \right)
\end{align*}
\end{proof}

\begin{corollary}  Let $W = HTH$. Then, $a_{W}(1) = a_{W}(2) = 0$, $a_{W}(3) = 1$ and, $a_{W}(n+3) = 2a_{W}(n+2) - a_{W}(n+1)+ a_{W}(n)$. Moreover, for $n\ge 3$,
\begin{equation} \label{HTHa}
a_{W}(n)
=\hbox{\rm{Round}}\left[ \frac{a^{2-n}}{(a-b)(a-c)} \right],
\end{equation}
where $a,b,c$ are the three roots of $x^3-x^2+2x-1=0$. Namely,
\begin{equation*}
        a = \frac{1}{3}-\frac{5}{3K} +\frac{K}{3}\approx 0.57, \quad
    b = \frac{1}{3} - \frac{(1+i\sqrt{3})K}{6} + \frac{5(1-i\sqrt{3}}{6K}), \quad
    c = \overline{b},
\end{equation*}
where $K=\left(\frac{11+3\sqrt{69}}{2}\right)^{1/3}$.
The expected value of flips it takes for the word $W=HTH$ to appear for the first time is
$\mu_{W} = 10$
with standard deviation  $\sigma_{W} = \sqrt{58} \approx 7.6$.  Moreover,
\begin{align*}
p_{W}(\ge N) = \frac{6a_{W}(N)- a_{W}(N-1)}{2^{N-1}}.
\end{align*}
In particular, $p_{W}(\ge 22) \approx 0.1$.
\end{corollary}
\begin{proof}
To simplify writing, let $W = HTH$, $a_n:= a_{W}(n)$, and $$f_m(x) := f_{W,m}(x)= \sum_{n=1}^m a_{W}(n) x^n = \sum_{n=1}^m a_nx^n.$$ By Proposition \ref{Rec3}, it follows that
\begin{align*}  f_{m}(x) = \frac{-x^3}{x^3-x^2+2x-1}\left[ 1 -R_m(x)\right],
\end{align*}
where $R_m(x) = x^m\left(\frac{a_{m+1}}{x^{2}} + \frac{-a_m + a_{m-1}}{x}+a_m\right),$
and
\begin{align*}  f_{W}(x) = \lim_{m\to\infty}f_m(x) =  \frac{-x^3}{x^3-x^2+2x-1}.
\end{align*}
It follows that
$ f'_{W}(x) = \frac{x^2(x-1)(x-3)}{(x^3-x^2+2x-1)^2}$  and  $$f''_{W}(x) = -\frac{2x(x^5-6x^4 +6x^3+3x^2-6x+3)}{(x^3-x^2+2x-1)^3}  .$$
By using the Mathematica\textsuperscript{\textregistered} command
``$\hbox{Solve}[x^3 -x^2 + 2x - 1 == 0, x]$'',
one obtains the decomposition $x^3 -x^2 + 2x - 1 = (x-a)(x-b)(x-c)$ with $a, b, c$ as stated in the corollary. The equality (\ref{HTHa}) follows from (\ref{a_n}), $a_n=a_W(n)\in\mathbb{N}$, and the fact that, for $n\ge 3$,
\begin{align*}
 \left|\frac{-b^{2-n}(a-c)+c^{2-n}(a-b)}{C(a-b)(a-c)(b-c)} \right| < \frac{1}{2}.
\end{align*}
Finally, it follows from (\ref{HTHa}) that $R(f_{W}) >1/2$. Thus, by Proposition \ref{Prop1},
$
    \mu_W = \frac{1}{2}f_{W}'\left(\frac{1}{2}\right) = 10
$,  $
    \sigma_{W} = \sqrt{\hbox{Var}_{W}} = \sqrt{\frac{1}{4}f''_{W}\left(\frac{1}{2}\right) + \mu_{W}^{} -  \mu_{W}^2} = \sqrt{58}
$, and
\begin{align*}
    p(> m) & = 1 - p(\leq m) = 1 - f_{HTH,m}\left(\frac{1}{2}\right)
     = R_m\left(\frac{1}{2}\right)\\
     &= \left(\frac{1}{2}\right)^m\left(4a_{m+1}+-2a_m + 2a_{m+1}+a_m\right)
    = \left(\frac{1}{2}\right)^m(6a_{m+1}-a_m).
\end{align*}
\end{proof}

Words in Random Binary Sequences I


Computation of Centroidal Voronoi Tessellations in High Dimensional spaces

Abstract: Owing to the natural interpretation and various desirable mathematical properties, centroidal Voronoi tessellations (CVT) have found a wide range of applications and correspondingly a vast development in their literature. However the computation of CVT in higher dimensional spaces still remains difficult. In this paper, we exploit the non-uniqueness of CVTs in higher dimensional spaces for their computation. We construct such high dimensional tessellations from CVTs in one-dimensional spaces. We then prove that such a tessellation is centroidal under the condition of independence among densities over the one-dimensional spaces considered. Various numerical evaluations backup the theoretical result through the low energy of the tessellations. The resulting grid-like tessellations are obtained efficiently with minimal computation time.

\section{Introduction}
\label{sec::introduction}

Voronoi diagram is a partition of a set into subsets containing elements that are close to each other according to a certain metric. Even though they date centuries, Voronoi tessellations have been found immensely helpful in various applications ranging from health to computer graphics to natural sciences. The first documented application of Voronoi tessellations appeared in \cite{JohnSnowCholera} on the 1854 cholera epidemic in London in which it is demonstrated that proximity to a particular well was strongly correlated to deaths due to the disease \cite{LiliJu2011}. In more recent decades, Voronoi tessellations have almost become a common basis tool for path planning algorithms by multi-robot systems in the field of coverage control \cite{CortesMartinezMobileSensing}.

In line with the popularity of Centroidal Voronoi tessellations (CVT), remarkable amount of contributions have been made to further their development. \cite{ConstrainedCVT_QiangDu} refines the notion of Constrained CVTs and derives various properties like their characterization as energy minimizers. Focusing on one-dimensional Voronoi diagrams, \cite{OneDimVD_Franz} develops an optimal algorithm for computing collinear weighted Voronoi diagrams that is conceptually simple and attractive for practical implementations. \cite{InverseVornoiGoberna} studies the inverse Voronoi problem in-depth.

Despite the wide applicability and vast development in the literature pertaining to CVTs, there remain challenges and open questions, especially in high dimensional spaces. For dimensions greater than one, rigorously verifying a given centroidal Voronoi tessellation is a local minimum can prove difficult, for example \cite{UniquenessCVT_Urschel} uses variational techniques to give a full characterization of the second variation of a centroidal Voronoi tessellation and provides sufficient conditions for a centroidal Voronoi tessellation to be a local minimum. Moreover, in high dimensional spaces, the number of CVTs under certain conditions and their quality is elusive, and their computation remains difficult.

In this paper, we show how one can employ CVTs in one-dimensional spaces to construct a tessellation in a higher dimensional space. Then we prove that such a tessellation is a CVT in the higher dimensional space under certain conditions. Such a construction is a simple and yet a powerful technique that is guaranteed to render at least one of the many non-unique CVTs in high dimensions in a fast and efficient way with minimal computational requirements.

The desired number of centroids in the higher dimensional space is a product of the number of centroids in the one-dimensional spaces. Accordingly, if the dimension is too large, one can limit the number of centroids in one-dimensional spaces in order to keep the total number of centroids meaningful. Doing so also has the advantages of further reduction in computational time.

The paper is structured as follows. In Section \ref{sec::preliminaries} we formally define CVTs, discuss their uniqueness properties, and existing methods to compute them. In Section \ref{sec:ComputationCVTHigherDimensions} we construct a tessellation in a higher dimensional space and prove that it is also a CVT. In Section \ref{sec::numericalresults} we provide numerical results of CVTs under different high dimensional spaces, densities and number of centroids. Finally, we present some conclusions and remarks on future work in Section \ref{sec::conclusion}.

\iffalse
Disadvantages:
1. If using SNLE to obtain the CVT in 1D, then the computation grows with the number of generators. This is because we need to solve an equation for each centroid. So if N centroids is high, then solving a system of high N number of equations is computationally taxing.
2. However, if other methods like Lloyds are used to determine the CVT in 1D, then it is not as computationally taxing.
3. If "still-to-be-resolved" point 1 turns true: that is, we can't use this for spaces like circles.

From either case, we can just use the CVT from 1D, repeat that for all the dimensions we have, and club them together to obtain a CVT in the higher dimension in a straight-forward manner.

Since CVTs are not unique in higher dimensional spaces, this method ensures we get at least one of the many CVTs in that higher dimension space. Overarching idea is that we can at least get these really well drawn out perfect grids in higher dimensions in a fast and efficient way that we know will be one of the many CVTs.

Still to be resolved:
1. Can we do weird spaces like a circle where one dimension is a function of another? Do we need to use some sort of constrained CVTs?
\fi

\section{Preliminaries}
\label{sec::preliminaries}

Consider a region $\Omega \subset \mathbb{R}^n, \ n \geq 1$. Let $N \in \mathbb{N}$, $V_i \subset \Omega, \ \forall i \in I_N$, and denote index set as $I_N = \{1, 2, \hdots, N\}$. Let $\rho(.)$ denote a measure of information or the probability density over $\Omega$.

\begin{itemize}
    \item[1] Tessellation: $\{V_i\}_{i\in I_N}$ is a tessellation of $\Omega$ if $V_i \cap V_j = \emptyset$ for $i \neq j$, and $\cup_{i\in I} {V}_i = {\Omega}$.
    \item[2] Voronoi region and generators: The Voronoi region ${V}_{z_i}$ of the Voronoi generator $z_i$ is ${V}_{z_i} = \{x \in \Omega : ||x - z_i|| < ||x-z_j||, \ i \neq j \ \text{and} \ i,j \in I_N \}$.
    \item[3] Voronoi tessellation: The set of Voronoi regions $\textbf{V}_{\textbf{z}} = \{V_{z_i}\}_{i \in I_N}$ of $\{z_i\}_{i \in I_N}$ is called a Voronoi tessellation $\{ \textbf{z},\textbf{V}_{\textbf{z}}\}$.
\end{itemize}

The mass centroid of a region $V_i \subset \Omega$ under the probability density function $\rho(.)$ is defined as:

\begin{equation}
    z_{V_i,\rho}^c  = \frac{\int_{V_i} x \rho(x) dx}{\int_{V_i}\rho(x) dx}
    \label{eq:MassCentroidDefn}
\end{equation}

\noindent A Voronoi tessellation in which the generators are the mass centroids of their respective Voronoi regions is called a \textit{Centroidal Voronoi Tessellation} (CVT), \cite{CVT_QiangDu}. The CVT obtained for 3 generators in the region $\Omega = [0,15]$ under Uniform and Normal distributions -- $\mathcal{U}(0,15)$ and $\mathcal{N}(7.5,1)$ -- are shown in Fig. \ref{fig:CVT_defn}. The generators under Uniform ad Normal distribution over $\Omega$ are marked in star and square symbols respectively.

\begin{figure}
    \centering
    \includegraphics[width=\columnwidth]{CVT_defn.png}
    \caption{Centroidal Voronoi Tessellations of $[0,15]$ under Uniform and Normal distributions, denoted in star and square symbols respectively.}
    \label{fig:CVT_defn}
\end{figure}

\subsection{Uniqueness of CVT}
\label{subsec:UniquenessofCVT}

Given a region $\Omega \subset \mathbb{R}^n$, a positive integer $N$, and a density function $\rho(x)$ on $\Omega$, consider the functional $\mathcal{F}$ with any $N$ points $\{z_i\}_{i \in I_N} \in \Omega$ and any tessellation $\{V_i\}_{i \in I_N}$ of $\Omega$ as its input arguments:

\begin{equation}
	\mathcal{F}((z_i,V_i), i \in I_N) = \sum_{i \in I_N} \int_{x\in V_i} \rho(x) ||x-z_i||^2 dx
	\label{eq:functionalF_QiangDu}
\end{equation}

\noindent Proposition $3.1$ in \cite{CVT_QiangDu} states that a necessary condition for the function $\mathcal{F}$ to be minimized is that $\{V_i\}_{i \in I_N}$ are the Voronoi regions corresponding to $\{z_i\}_{i \in I_N}$, and simultaneously, $\{z_i\}_{i \in I_N}$ are the centroids of their respective Voronoi regions. In other words, the minimizer of $\mathcal{F}$ is a Centroidal Voronoi Tessellation.

Additionally, if the tessellation in \eqref{eq:functionalF_QiangDu} is fixed to be the Voronoi tessellation of $\{z_i\}_{i \in I_N}$, then the following functional $\mathcal{K}$ has the same minimizer as $\mathcal{F}$, \cite{CVT_QiangDu}.

\begin{equation}
	\mathcal{K}((z_i), i \in I_N) = \sum_{i \in I_N} \int_{x\in V_{z_i}} \rho(x) ||x-z_i||^2 dx
	\label{eq:functionalK_QiangDu}
\end{equation}

\noindent This functional $\mathcal{K}$ is also referred to as the energy of the tessellation or the quantization energy. It is stated and proved in Lemma $3.4$ in \cite{CVT_QiangDu} that $\mathcal{K}$ is continuous and that it possesses a global minimum. Moving from existence of the CVT to its uniqueness, \cite{CVT_QiangDu} also mentions that $\mathcal{K}$ may have local minimizers.

It is showed in \cite{CVT_Fleischer} that the solution of \eqref{eq:functionalK_QiangDu} is unique in one-dimensional regions with a logarithmically concave continuous probability density function of finite second moment. As reiterated in \cite{UniquenessCVT_Urschel}, for $n=1$, the logarithmic concavity condition implies that any CVT is a local minimum, and further, that there is a unique CVT that is both a local and a global minimum of $\mathcal{K}(\textbf{z})$, where $\textbf{z} = \{z_i\}_{i\in I_N}$. Accordingly, since the two distributions -- Uniform and Normal -- considered in Fig. \ref{fig:CVT_defn} on the one-dimensional region $\Omega = [0,15]$ are log-concave with finite second moment, we have that the CVTs showed therein are the global minima for the two distributions.

The solution of \eqref{eq:functionalK_QiangDu} is also called scalar quantizer for $n=1$ and vector quantizer for higher dimensions. The conditions for uniqueness of vector quantizers for the general case, that is, without any assumptions on the region, density or the number of quantizers $N$, remains an open area of research. However, it is proved in \cite{UniquenessCVT_Urschel} that for $N=2$, there does not exist a unique CVT for any density for $n > 1$.

For a graphic illustration on non-uniqueness of CVTs, consider a rectangle in $\mathbb{R}^2$ with six generator points under Uniform distribution. As shown in Fig. \ref{fig:NonUniqueCVT_example}, there are multiple CVTs: all the four Voronoi tessellations shown are centroidal, and additional CVTs can be obtained through rotations.

\begin{figure}
    \centering
    \includegraphics[width=0.9\columnwidth]{NonUniqueCVT.png}
    \caption{CVT is not necessarily unique in $\mathbb{R}^2$: Four centroidal Voronoi tessellations, each of six generators, in a rectangle in $\mathbb{R}^2$ with uniform density. Voronoi regions are shown in different colors while their centroids are marked as black dots.}
    \label{fig:NonUniqueCVT_example}
\end{figure}

To summarize, the solution of \eqref{eq:functionalK_QiangDu} is unique in one-dimensional regions for log-concave density functions but there does not exist a unique CVT for any density for dimensions greater than one \cite{UniquenessCVT_Urschel}.

\subsection{Computation of CVT}
\label{sec::ComputeCVTmethods}

Given a region $\Omega \subset \mathbb{R}^n$, a number of generators $N$, and a density function $\rho(x)$ over $\Omega$, there are various iterative algorithms to compute a CVT in $\Omega$. As noted in the previous Section, in general, the CVT need not be unique for any dimensional region unless certain conditions are imposed on the density function. Accordingly, the solutions rendered by all the algorithms, to compute the CVT, need not be the unique global minimizers. In this Section, we first describe perhaps the most widely employed of all the algorithms: Lloyd's algorithm, and then show a computation method to obtain the exact solution of the problem of finding the CVT in one-dimensional regions.

Introduced in \cite{CVT_Lloyd_original} to find the optimal quantization in pulse-code modulation, Lloyd's algorithm, also known as Voronoi iteration or relaxation, has been modified or adapted in various fields. At the core of it, Lloyd's algorithm is an iteration between constructing Voronoi tessellations and their centroids:

\begin{framed}
\noindent Given: $\Omega \subset \mathbb{R}^n$, $N$, $\rho(x)$ \\
Initialize: Generators $\textbf{z} = \{z_i\}_{i \in I}$, where each $z_i \in \Omega$
\begin{itemize}
	\item[1] Construct the Voronoi tessellation $\textbf{V}_\textbf{z}$.
	\item[2] Compute the mass centroids $z^c_{\textbf{V}_{\textbf{z},\rho}}$ of $\textbf{V}_\textbf{z}$.
	\item[3] If the computed centroids meet certain stopping criteria then terminate. If not, then set $\textbf{z} = z^c_{\textbf{V}_{\textbf{z},\rho}}$, and return to Step 1.
\end{itemize}
 \end{framed}

\noindent Since we are looking for a CVT, the search/iterations stop when the centroids of the Voronoi regions are the generators. Accordingly, the stopping criteria can be defined to have the generators same as the centroids with some tolerance.

Even though Lloyd's algorithm is iterative and approximate, it has certain desirable convergence properties. \cite{ConvergenceLloyd_QiangDu} rigorously proves various global convergence properties of the Lloyd's algorithm and surveys all the results concerning the convergence of the Lloyd's algorithm. Specifically for one-dimensional spaces with log-concave density function, the local convergence using the Lloyd's algorithm has been proved in \cite{CVT_1d_uniquenessKieffer}.

Another method to obtain a CVT in a one-dimensional region is SNLE (system of nonlinear equations). Perhaps the most straightforward way to compute a CVT, the core idea behind SNLE, which is the analytical computation of the CVT in one-dimensional region, is to parameterize the Voronoi regions in terms of their centroids:  $V_i = [ \frac{z_{i-1}+z_i}{2}, \frac{z_i+z_{i+1}}{2}] , \forall i \in I_N$. The mass centroids from \eqref{eq:MassCentroidDefn}, with  $z_{V_i,\rho}^c$ denoted as $z_i^c$ for ease of notation, can then be written in terms of the parameterized regions:

\begin{equation}
	z_{i}^c  = \frac{\int_\frac{z_{i-1}^c+z_i^c}{2}^{\frac{z_i^c+z_{i+1}^c}{2}} x \rho(x) dx}{\int_\frac{z_{i-1}^c+z_i^c}{2}^{\frac{z_i^c+z_{i+1}^c}{2}}\rho(x) dx}
	\label{eq:Centroids_Parameterizing_1D}
\end{equation}

Writing \eqref{eq:Centroids_Parameterizing_1D} for all the centroids results in $N$ equations and $N$ number of unknowns: $z_i^c$'s. This is the system of nonlinear equations (SNLE), whose solution is the set of centroids of the CVT. In one-dimensional regions, the centroids are directly used to define the corresponding Voronoi partitions.

While the Lloyd's algorithm and SNLE obtain the CVT in a deterministic way, MacQueen's method developed in \cite{JMacQueen} takes a probabilistic approach. It was developed to partition an $n$-dimensional population into $k$ sets on the basis of a sample, and the process is also called $k-$means. As noted in \cite{CVTQiangDuParallel}, despite the elegance of MacQueen's method, the algorithm can be slow to converge due to a single random sampling point. Accordingly, \cite{CVTQiangDuParallel} presents a new method that can be viewed as a probabilistic version of Lloyd’s method and/or a generalization of the random MacQueen’s method. Some other algorithms that have faster convergence than Lloyd's have been proposed in \cite{CVT_LlyodsAlt_FastConvergenceLiu}, \cite{CVT_LloydsAlt_FastConvergenceWang}, \cite{CVT_LlyodsAlt_FastConvergenceHateley}.

However, the computation of CVT in higher dimensional spaces still remains a challenge. \cite{CVTQiangDuParallel} considers parallel implementations of Lloyd's, MacQueen's and a method developed therein, and presents the CVT results for regions up to two dimensions while noting that the method can be extended to higher dimensions. Although \cite{CVT_LlyodsAlt_FastConvergenceHateley} results in faster convergence to a CVT, it does not easily extend to higher dimensions. In the next Section, we present a way to extend SNLE (or any method to obtain one-dimensional CVTs) to obtain a higher dimensional CVT.

\section{COMPUTATION OF CVT IN HIGHER DIMENSIONS}
\label{sec:ComputationCVTHigherDimensions}

In this Section, we first propose a simple method to obtain a tessellation in any higher dimensional space from CVTs in one-dimensional spaces. Then, we present the proof that a tessellation constructed in such a way is also a CVT.

Consider a region $\Omega \subset \mathbb{R}^n, \ n > 1$, and $\Omega = \Omega_1 \times \Omega_2 \times \hdots \times \Omega_n$. Let $\rho(.)$ be the probability density function over $\Omega$, and $\rho_i(.)$ be the density function over $\Omega_i$, $\forall i \in I_n = \{1,2,\hdots, n\}$. That is, $\rho(.)$ is the joint density, and $\{\rho_i(.)\}_{i \in I_n}$ are the marginal densities.

Let the number of generators in a CVT of $\Omega_i$ under $\rho_i(.)$ be $N_i$, and let the number of generators in a CVT of $\Omega$ under $\rho(.)$ be $N$, where $N = N_1 \times \hdots \times N_n$. Denote a CVT in $\Omega_i$ as $\{\textbf{z}^*_i, \textbf{V}_{\textbf{z}^*_i}\}$. Here, $\textbf{z}^*_i = \{z^*_{i,j}\}_{j \in I_{N_i}}$ is the set of all the centroids of the CVT in $\Omega_i$, and $\textbf{V}_{\textbf{z}^*_i} = \{V_{z^*_{i,j}}\}_{j \in I_{N_i}}$ is the set of their respective Voronoi regions. Similarly, denote a CVT in $\Omega$ as $\{\textbf{z}^*,\textbf{V}_{\textbf{z}^*}\}$, where $\textbf{z}^* = \{z_k^*\}_{k \in I_N}$ denotes the centroids, $\textbf{V}_{\textbf{z}^*} = \{V_{z^*_k}\}_{k \in I_N}$  denotes their corresponding Voronoi regions.

Note that $\textbf{z}^* \in \mathbb{R}^N$ while $\textbf{z}^*_i \in \mathbb{R}^{N_i} $, and $z^*_k \in \mathbb{R}^n$ while $z^*_{i,j} \in \mathbb{R}$. Denote each element of $z^*_k \in \mathbb{R}^n$ by indexing as $z^*_k(1), z^*_k(2), \hdots, z^*_k(n)$. Additionally, note that $V_{z^*_k} \subset \mathbb{R}^n$ while $V_{z^*_{i,j}} \subset \mathbb{R}$.

Let $I_{n\times N}$ denote the matrix containing all combinations of vectors $I_{N_i}, \forall i \in I_n$. For example, if $n=2, N_1 = 2, N_2 = 3,$ then $N = 2\times3=6$ and

\begin{equation}
I_{n\times N} =
\begin{bmatrix}
1 & 1 & 1 & 2 & 2 & 2 \\
1 & 2 & 3 & 1 & 2 & 3
\end{bmatrix}
\end{equation}

With all the notations defined, we now present a straightforward method of constructing a tessellation in $\Omega$ from CVTs in $\Omega_i's$:

\begin{framed}

\hspace{1cm} \textbf{Tessellation construction in $\Omega$}

\noindent For each dimension $i \in I_n$, construct a CVT in $\Omega_i$: $\{\textbf{z}^*_i, \textbf{V}_{\textbf{z}^*_i}\}$

\noindent Obtain the $n$ coordinates of each centroid in $\Omega$ and its Voronoi region as:

$\forall k \in I_N:$

\hspace{0.5cm}$\forall i \in I_n:$

\hspace{1cm} $z^*_k =  z^*_{ I_{n \times N}(i,k)}$

\hspace{1cm} $V_{z^*_k}=  V_{z^*_{ I_{n \times N}(i,k)}}$

\noindent The set of all the centroids $\{z_k^*\}_{k \in I_N}$ and their Voronoi regions $\{V_{z^*_k}\}_{k \in I_N}$ make the tessellation in $\Omega$: $\{\textbf{z}^*,\textbf{V}_{\textbf{z}^*}\}$
\end{framed}

Having obtained the tessellation, we show in the following theorem that $\{\textbf{z}^*,\textbf{V}_{\textbf{z}^*}\}$ constructed from $\{\textbf{z}^*_i, \textbf{V}_{\textbf{z}^*_i}\}_{i \in I_n}$ is a CVT in $\Omega$.

{\textbf{Theorem:}} If events in $\Omega_i$ are independent of those in $\Omega_j$, $\forall i \neq j, \ i,j \in I_n$, then for some $k_i \in I_{N_i}, \forall i \in I_n$ and $\forall k \in I_N,$ we have:

\begin{equation}
z^*_k = (z^*_{1,k_1}, \ z^*_{2,k_2}, \hdots, z^*_{n,k_n})
\label{eq:TheoremCentroidStatement}
\end{equation}

\begin{equation}
V_{z^*_k} = V_{z^*_{1,k_1}} \times  V_{z^*_{2,k_2}} \times \hdots \times  V_{z^*_{n,k_n}}
\label{eq:TheoremVoronoiStatement}
\end{equation}

{\textbf{Proof:}}

Consider $x \in V_{z^*_{1,k_1}} \times \hdots \times V_{z^*_{n,k_n}}$, $\forall i \in I_n$, and denote $x = (x_1, \hdots, x_n)$. Because $V_{z^*_{i,k_i}}$ is the Voronoi region of $z^*_{i,k_i}$, $\forall i \in I_n$, we have for any $j_i \in I_{N_i}$:

\begin{align}
||x_i - z^*_{i,k_i}||_2 \leq ||x_i - z^*_{i,j_i}||_2 \nonumber \\
\implies (x_i - z^*_{i,k_i})^2 \leq (x_i - z^*_{i,j_i})^2
\label{eq:VoronoiRegionRnProof1}
\end{align}

Summing \eqref{eq:VoronoiRegionRnProof1} $\forall i \in I_n$,

\begin{align}
(x_1 - z^*_{1,k_1})^2 + & \hdots + (x_n - z^*_{n,k_n})^2 \leq \\   \ \ (x_1 & - z^*_{1,j_1})^2 + \hdots + (x_n - z^*_{n,j_n})^2  \\
\implies \sqrt((x_1 - z^*_{1,k_1})^2 &+ \hdots + (x_n - z^*_{n,k_n})^2) \leq \\ \sqrt((x_1 & - z^*_{1,j_1})^2 + \hdots + (x_n - z^*_{n,j_n})^2) \label{eq:VoronoiRegionRnProof2}
\end{align}

Let $\hat{z}^*_k = (z^*_{1,k_1},  z^*_{2,k_2}, \hdots, z^*_{n,k_n})$, then \eqref{eq:VoronoiRegionRnProof2} results in:

\begin{align}
  ||x-\hat{z}^*_k||_2 \ \ \leq \ \  ||x-z^*_j|| \nonumber \\
\implies   V_{\hat{z}^*_k} = V_{z^*_{1,k_1}} \times  \hdots \times V_{z^*_{n,k_1}}
\label{eq:VoronoiRegionRnProof2}
\end{align}

\noindent That is, $V_{z^*_{1,k_1}} \times  \hdots \times V_{z^*_{n,k_1}}$ is the Voronoi region of $\hat{z}^*_k$. We are yet to prove that $\hat{z}^*_k$ is a centroid of a CVT in $\Omega$ under $\rho(.)$, that is, $z^*_k = \hat{z}^*_k$.

Consider the $i^{th}$ coordinate of $\hat{z}^*_k$. Since $z^*_{i,k_i}$ is the centroid of $V_{z^*_{i,k_i}}$, by definition of centroid, we have:

\begin{align}
  z^*_{i,k_i} &= \frac{\int_{V_{z^*_{i,k_i}}} x_i \rho_1(x_i)}{\int_{V_{z^*_{i,k_i}}} \rho_n(x_i) dx_i} \nonumber  \\
  &= \frac{\int_{V_{z^*_{1,k_1}}} \rho_1(x_1)dx_1}{\int_{V_{z^*_{1,k_1}}} \rho_1(x_1)dx_1} \times \hdots \times \frac{\int_{V_{z^*_{i,k_i}}} x_i\rho_i(x_i)dx_i}{\int_{V_{z^*_{i,k_i}}} \rho_i(x_i)dx_i} \nonumber \\
 &\hspace{2cm} \times \hdots \frac{\int_{V_{z^*_{n,k_n}}} \rho_n(x_n)dx_n}{\int_{V_{z^*_{n,k_n}}} \rho_n(x_n)dx_n}
 \label{eq:MassCentroidRnProof1}
\end{align}

Because the events in $\Omega_i$ are independent of those in $\Omega_j$, $\forall i \neq j, \ i,j \in I_n$, we have $\rho(x_1, \hdots, x_n) = \rho_1(x_1), \hdots, \rho_n(x_n)$. Substituting this relation in \eqref{eq:MassCentroidRnProof1} implies:

\begin{align*}
  z^*_{i,k_i} &= \frac{\int_{V_{z^*_{1,k_1}}} \hdots  \int_{V_{z^*_{n,k_n}}} x_i \rho(x_1, \hdots, x_n) dx_1 \hdots dx_n }{\int_{V_{z^*_{1,k_1}}} \hdots \int_{V_{z^*_{n,k}}} \rho(x_1, \hdots, x_n) dx_1 \hdots dx_n }
\end{align*}

\noindent which, by definition of mass centroids, is the $i^{th}$ coordinate of the $k^{th}$ of the $N$ centroids -- $z^*_k$ -- in $\Omega$ with density $\rho(.)$. That is, $z^*_k(i) = z^*_{i,k_i}$. Since this holds for all $i \in I_n$ coordinates, we have $z^*_k = \hat{z}^*_k = (z^*_{1,k_1},  z^*_{2,k_2}, \hdots, z^*_{n,k_n})$, and hence proving \eqref{eq:TheoremCentroidStatement}. On the other hand, since $V_{z^*_{1,k_1}} \times  \hdots \times V_{z^*_{n,k_1}}$ is the Voronoi region of $\hat{z}^*_k$ from \eqref{eq:VoronoiRegionRnProof2}, and $z^*_k = \hat{z}^*_k$, we have $V_{z^*_{1,k_1}} \times  \hdots \times V_{z^*_{n,k_1}}$ is the Voronoi region of $z^*_k$, hence proving \eqref{eq:TheoremCentroidStatement}. Since this holds for all $N$ centroids in $\Omega$, we have that $\textbf{z}^* = \{z^*_k\}_{k \in I_N}$ and $\textbf{V}_{\textbf{z}^*} = \{V_{z^*_k}\}_{k \in I_N}$ is a CVT in $\Omega$ with density $\rho(.)$.

$\hfill \square$

Recall the non-uniqueness of CVTs in $\mathbb{R}^2$ from Fig. \ref{fig:NonUniqueCVT_example}, that shows some of the CVTs for $N=6$ generators in a rectangle in $\mathbb{R}^2$ with uniform density. We construct the CVT in Fig. \ref{fig:NonUniqueCVT_example}(d) under different conditions.

Consider $\Omega = [0,20] \times [0,10]$ in $\mathbb{R}^2$ with density $\rho(.) \sim \mathcal{N}(\mu,\Sigma)$, where $\mu = (12,7)$ and $\Sigma=[4 \ \ 0; 0 \ \ 1]$. Denote the CVT as $\{\textbf{z}^*,\textbf{V}_{\textbf{z}^*}\}$, where $\textbf{z}^* = (z^*_1, \hdots, z^*_6)$, and $z^*_k \in \mathbb{R}^2, \forall k \in I_6 = \{1, \hdots, 6\}$.

On the other hand, let $N_1 = 3$ and $N_2 = 2$. Consider the unique CVT in $\Omega_1 = [0,20]$ for $\rho_1(.) \sim \mathcal{N}(12,4)$, which is denoted $\{\textbf{z}_1^*,\textbf{V}_{\textbf{z}_1^*}\}$. Note $\textbf{z}_1^* = (z^*_{1,1}, z^*_{1,2}, z^*_{1,3})$, and $z^*_{1,j} \in \mathbb{R}, \forall j \in I_3$. Similarly, consider the unique CVT in $\Omega_2 = [0,10]$ for $\rho_1(.) \sim \mathcal{N}(7,1)$, which is denoted $\{\textbf{z}_2^*,\textbf{V}_{\textbf{z}_2^*}\}$. Note $\textbf{z}_2^* = (z^*_{2,1}, z^*_{1,2})$, and $z^*_{1,j} \in \mathbb{R}, \forall j \in I_2$. These generators are shown in Fig \ref{fig:Is1plus1equalto2_step1}: the region $\Omega_1$ and the CVT generators in it are showed in pink, and the region $\Omega_2$ and the CVT generators in it are showed in blue. While this method of obtaining a CVT in higher dimensions by employing a combination of CVTs in $\mathbb{R}$ does not result in every possible CVT of the higher dimension under the given conditions, we are guaranteed to obtain at least one of them in a straightforward manner with minimal computation.

\begin{figure}
\centering
    \includegraphics[width=0.9\columnwidth]{Is1plus1equalto2_step1.png}
    \caption{CVTs in $\Omega_1$ and $\Omega_2$ with densities $\mathcal{N}(12,4)$ and $\mathcal{N}(7,1)$ respectively.}
    \label{fig:Is1plus1equalto2_step1}
\end{figure}

\begin{figure}
\centering
    \includegraphics[width=0.9\columnwidth]{Is1plus1equalto2.png}
    \caption{CVT in $\Omega$ with density $\mathcal{N}(\mu,\Sigma)$ where $\mu = [12; 7]$ and $\Sigma = [4 \ \ 0; 0 \ \ 1]$ .}
    \label{fig:Is1plus1equalto2_step1}
\end{figure}

\section{NUMERICAL RESULTS}
\label{sec::numericalresults}

In this Section, we present a set of numerical results to demonstrate the ease of extension in higher dimensions through the time required to compute the CVT and the CVT energy. Additionally, for 2 and 3 dimensional spaces we also present the tessellations graphically. To obtain the CVTs in one-dimensional spaces, one can employ Lloyd's algorithm or solve the system of nonlinear equations; the latter being more desirable when $N_i's$ are low.

Consider the region $\Omega _1 = \Omega _2 = [-1, 1]$ and $\Omega = \Omega_1 \times \Omega_2 \subset \mathbb{R}^2$. Following the cases taken up in \cite{CVTQiangDuParallel}, we let the density function over $\Omega$ be $e^{-10x^2}$. The CVT of 256 centroids, obtained from $16$ in each dimension, in the aforementioned $\Omega$ is shown in Fig. \ref{fig:CVT_2D_16x16_expminus10xsq}. As designed and expected, the tessellation has a well drawn out grid-like structure with the intensity of centroids being higher in the center of $\Omega$. The resulting tessellation is a CVT with (low) energy of $2.9 \times 10^{-4}$ and was obtained in computational time as less as $13.18$ minutes in an ordinary laptop -- MacBook Air 2015 with 2.2 GHz Dual-Core Intel Core i7.

\begin{figure}
    \centering
    \includegraphics[width=\columnwidth]{CVT_2D_16x16_expminus10xsq.eps}
    \caption{CVT of 256 centroids in a two-dimensional square under $\rho_1(x_1) = \rho_2(x_2) = e^{-10x^2}$ }
    \label{fig:CVT_2D_16x16_expminus10xsq}
\end{figure}

Next case of demonstration is in the region $\Omega = [0,20] \times [0,20]$ with a Gaussian density of means $\begin{bmatrix} 5 \\ 6.5 \end{bmatrix}$ and variance $\begin{bmatrix} 2 \ \ 0 \\ 0 \ \ 1 \end{bmatrix}$. Here, we consider $N_1 = 60$ and $N_2 = 50$, implying total number of centroids in $\Omega$ being $N=3000$. The resulting CVT with energy $0.0112$ is shown in Fig. \ref{fig:CVT_2D_60x50_GammaGaussianWorkComp}.

\begin{figure}
    \centering
    \includegraphics[width=\columnwidth]{CVT_2D_60x50_GammaGaussianWorkComp.eps}
    \caption{CVT of 3000 centroids in $\Omega = [0,20]\times [0,20]$ with Gaussian density.}
    \label{fig:CVT_2D_60x50_GammaGaussianWorkComp}
\end{figure}

Moving to 3 dimensional spaces, we consider $\Omega = [0,10]\times [0,10] \times [0,10]$ under Gaussian density with mean $\mu$ and variance $\Sigma$ as:

\begin{equation*}
\mu =  \begin{bmatrix} 6 \\ 5 \\ 1 \end{bmatrix} \hspace{1cm}
\Sigma = \begin{bmatrix} 2 \ \ 0 \ \ 0 \\ 0 \ \ 1 \ \ 0 \\ 0 \ \ 0 \ \ 1 \end{bmatrix}
\end{equation*}

\noindent The resulting well-aligned grid looking CVT with $16$ centroids in each dimension, with energy $0.1616$, is shown in Fig. \ref{fig:CVT_3D_16x16x16_Gaussian62_51_3p51}.

\begin{figure}
    \centering
    \includegraphics[width=0.9\columnwidth]{CVT_3D_16x16x16_Gaussian62_51_3p51.eps}
    \caption{Scalability and generalizability to any density: CVT of 4096 centroids in a 3D space under Gaussian density.}
    \label{fig:CVT_3D_16x16x16_Gaussian62_51_3p51}
\end{figure}

One of the areas where higher dimensional CVTs have found an application is in the field of evolutionary optimization. Recently introduced, MAP-elites \cite{MAP_elites} is an algorithm that illuminates search spaces in evolutionary optimization, allowing researchers to understand how interesting attributes of solutions combine to affect performance. To scale up the MAP-elites algorithm, authors in \cite{CVT_MAP_elites} employ centroidal Voronoi tessellations, and therein, following \cite{CVTQiangDuParallel}, they employ MacQueen's method to obtain the CVTs and show the sufficiency of using $5000$ centroids. In line with their result, we keep the total number of centroids around the same. Accordingly, we vary $N_i, \forall i \in I_n$ such that $N = \prod_i N_i$ is around $5000$. The corresponding results are given in Table \ref{tab:HighDimensionQiangDu} where we see that the computation time decreases with the increase in dimension $n$. This is because with increase in $n$, we decrease $N_i$ to keep $N$ around $5000$. Hence, the computation of CVT in one-dimensional spaces with fewer centroids is faster. The low energy of all the tessellations is also worth noting.

\begin{table}[]
\begin{tabular}{@{}cccc@{}}
\toprule
Dimension, $n$ & $N = \prod_i N_i$       & CVT energy            & Time (minutes) \\ \midrule
4              & $4096 = 8^4$            & $0.68 \times 10^{-3}$ & $6.174$                    \\
5              & $4096 = 4^3 \times 8^2$ & $1.2 \times 10^{-3}$  & $4.248$                    \\
8              & $6561 = 3^8 $           & $0.74 \times 10^{-3}$ & $0.641$                    \\
12             & $4096 = 2^{12}$           & $0.21 \times 10^{-3}$ & $0.480$                    \\ \bottomrule
\end{tabular}
\label{tab:HighDimensionQiangDu}
\caption{Tessellation energy and time taken for computing the tessellation for $\Omega_i = [-1,1], \forall i \in I_n$ under density $e^{-10x^2}$ over each $\Omega_1$.}
\end{table}

\section{CONCLUSIONS}
\label{sec::conclusion}

In order to fully rank the quality of all the CVTs under a certain higher dimensional space (read fixed region, number of centroids, and density), the knowledge of all the CVTs and their tessellation energy is required. However, the problem in such a comparison is the difficulty in obtaining CVTs in higher dimension spaces. Nevertheless, the tessellations constructed from CVTs in one-dimensional spaces, that appear to be well drawn out grid-like structures, are proved to be one of the many CVTs in such spaces of dimensions greater than 1. Hence, we are guaranteed to obtain at least one of the many non-unique CVTs in the higher dimensional space.

Additionally, as seen in the simulation results, the tessellation energy of such CVTs is quantifiably low and are obtained with minimal computational requirement. The method described does not make specific assumptions on the density function, it is scalable to a large number of centroids, and is flexible in terms of dimensions and discretization over each dimension.

However, the (only) key assumption in the construction of CVTs in a higher dimensional spaces from CVTs in one-dimensional spaces is the independence of the densities of the latter spaces. This limits the applicability of the developed idea in areas where CVTs are constrained to a surface, say computing CVT on a sphere, and will be a point of investigation for our future work.

\addtolength{\textheight}{-12cm}