$k$-ary Shift Rule | Output | ||||||||
|
Let $\Sigma_k = \{0,1,\ldots, k{-}1\}$. Let $\Sigma_k(n)$ denote the set of $k$-ary strings with length $n$. A function $f : \Sigma_k(n) \rightarrow \Sigma_k$ is a $k$-ary DB-successor if there exists a DB sequence $\mathcal{D}$ such that each string $\alpha = a_1a_2\cdots a_n \in \Sigma_k(n)$ is followed by the symbol $f(\alpha)$ in $\mathcal{D}$.
Using the PCR as the underlying feedback function, the four binary DB-successors are generalized to a larger alphabet [GSWW18], each in two different ways. These rules test in $O(n)$ time whether or not a string is a necklace, which is a string that is lexicographically smallest amongst all its rotations.
The following generalizes the binary Granddaddy DB-successor, the lexicographically least $k$-ary DB sequence. The rule is implicitly given in the proof of its corresponding concatenation construction [FM78]. It can also be constructed via the Prefer-smallest greedy approach.
If $\alpha = (k{-}1)^n$, let $j=n$; otherwise let $j$ be the smallest index of $a_2a_3\cdots a_n$ such that $a_j \ne k{-}1$. Let $x$ be the smallest symbol in $\Sigma_k$ such that $a_ja_{j+1}\cdots a_n x (k{-}1)^{j-2}$ is a necklace, or let $x=-1$ if no such symbol exists.
$f(\alpha) = \left\{ \begin{array}{ll} x &\ \ \mbox{if $x \geq 0$ and $a_1 = k-1$;}\\ a_1{+}1 &\ \ \mbox{if $x \geq 0$ and $a_1 \leq k-2$;}\\ {a_1} \ &\ \ \mbox{otherwise.}\end{array} \right.$
The following corresponds to the $k$-ary Grandmama DB-successor [DHS+18], which can also be constructed via a concatenation approach.
Let $j$ be the largest index of $a_2a_3\cdots a_n$ such that $a_j \ne 0$ or $j=1$ if no such index exists. Let $x$ be the largest symbol in $\Sigma_k$ such that $0^{n-j} x a_2\cdots a_{j}$ is a necklace, or let $x=-1$ if no such symbol exists.
$f(\alpha) = \left\{ \begin{array}{ll} 0 &\ \ \mbox{if $x \geq 0$ and $a_1 = x$;}\\ a_1{+}1 &\ \ \mbox{if $x \geq 0$ and $a_1 \leq x{-}1$;} \ \ \ \ \ \ \ \ \\ {a_1} \ &\ \ \mbox{otherwise.}\end{array} \right.$
The following generalizes the binary PCR3 DB-successor. It first corresponds to the shift rule in [SWW17].
$f(\alpha) = \left\{ \begin{array}{ll} x{-}1 &\ \ \mbox{if $x \geq 0$ and $a_1 = k{-}1$;}\\ a_1{+}1 &\ \ \mbox{if $x \geq 0$ and $x{-}1 \leq a_1 \leq k{-}2$;}\\ {a_1} \ &\ \ \mbox{otherwise,}\end{array} \right.$
where $x$ is the smallest symbol in $\{1,2,\ldots, k{-}1\}$ such that $a_2a_3\cdots a_{n} x$ is a necklace, or $x=-1$ if no such symbol exists.
Perhaps the simplest $k$-ary DB successor to state (along with PCR3 above) generalizes the binary PCR4 DB-successor.
$f(\alpha) = \left\{ \begin{array}{ll} 0 &\ \ \mbox{if $x \geq 0$ and $a_1 = x{+}1$;}\\ a_1{+}1 &\ \ \mbox{if $x \geq 0$ and $a_1 \leq x$;}\\ {a_1} \ &\ \ \mbox{otherwise,}\end{array} \right.$
where $x$ is the largest symbol in $\{0,1,\ldots, k{-}2\}$ such that $xa_2a_3\cdots a_{n}$ is a necklace, or $x=-1$ if no such symbol exists.
Other works that present $k$-ary DB-successors include [ETZ86] and [YD93].
A more generic approach for any underlying non-singular feedback function, is available for download (the underlying feedback function is hard-coded). The option available for generation above uses the feedback function $f(a_1a_2\cdots a_n) = a_1 + 1$. This implementation is based on [GSWW18]. It generalizes both the Grandmama and the PCR3.