# Pseudoperiodic Words and a Question of Shevelev

Joseph Meleshko, Pascal Ochem, Jeffrey Shallit, Sonja Linghui Shan

► To cite this version:

Joseph Meleshko, Pascal Ochem, Jeffrey Shallit, Sonja Linghui Shan. Pseudoperiodic Words and a Question of Shevelev. 2023. lirmm-03799690

HAL Id: lirmm-03799690

https://hal-lirmm.ccsd.cnrs.fr/lirmm-03799690

Preprint submitted on 17 Oct 2023

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Pseudoperiodic Words and a Question of Shevelev

Joseph Meleshko<fnref n="1" /> Pascal Ochem<fnref n="2" /> Jeffrey Shallit<fnref n="1" />*Sonja Linghui Shan<fnref n="1" />

revisions 15th Aug. 2022, 2nd Jan. 2023; accepted 26th May 2023.

We generalize the familiar notion of periodicity in sequences to a new kind of pseudoperiodicity, and we prove some basic results about it. We revisit the results of a 2012 paper of Shevelev and reprove his results in a simpler and more unified manner, and provide a complete answer to one of his previously unresolved questions. We consider finding words with specific pseudoperiod and having the smallest possible critical exponent. Finally, we consider the problem of determining whether a finite word is pseudoperiodic of a given size, and show that it is NP-complete.

**Keywords:** pseudoperiodic word, automata, Thue-Morse sequence, Rudin-Shapiro sequence, Tribonacci sequence, paperfolding sequence, critical exponent

## In honor of Vladimir Shevelev (1945–2018)

### 1 Introduction

Periodicity is one of the simplest and most studied aspects of words (sequences). Let $w = a_0a_1a_2\cdots a_{t-1}$ be a finite word. We say that $w$ is (purely) *periodic* with period $p$ ($1 \le p \le t$) if $a_i = a_{i+p}$ for $0 \le i < t-p$. For example, the French word *entente* is periodic with periods 3, 6, and 7. The definition is extended to infinite words as follows: $w = a_0a_1\cdots$ is periodic with period $p$ if $a_i = a_{i+p}$ for all $i \ge 0$. Unless otherwise stated, all words in this paper are indexed starting with index 0. All infinite words are defined over a finite alphabet.

In this paper we begin the study of a simple and obvious—yet apparently little-studied—generalization of periodicity, which we call *k*-pseudoperiodicity.

**Definition 1.** We say that a finite word $w = a_0a_1\cdots a_{t-1}$ is *k*-pseudoperiodic if there exist $k \ge 1$ integers $0 < p_1 < p_2 < \cdots < p_k$ such that $a_i \in \{a_{i+p_1}, a_{i+p_2}, \ldots, a_{i+p_k}\}$ for all $i$ with $0 \le i < t - p_k$. For infinite words the membership must hold for all $i$. If this is the case, we call $(p_1, p_2, \ldots, p_k)$ a *pseudoperiod* for $w$.

<footnote n="1">¹ University of Waterloo, Canada</footnote>

<footnote n="2">² LIRMM, CNRS, Université de Montpellier, France</footnote>

<footnote>*The research of JS is supported by NSERC Grant 2018-04118.</footnote>
In this paper, when we write a pseudoperiod ($p_1, p_2, \dots, p_k$) we always assume $0 < p_1 < \dots < p_k$. Note that 1-pseudoperiodicity is the ordinary notion of (pure) periodicity. If an infinite word $w$ is $k$-pseudoperiodic for some $k < \infty$, we call it *pseudoperiodic*.

We note that our definition of pseudoperiodicity is not the same as that studied by Blondin Massé et al. (2012). Nor is it the same as the notion of quasiperiodicity, as introduced by Marcus (2004), and now widely studied in many papers. Nor is it the same as “almost periodicity”, which is more commonly called uniform recurrence (i.e., every block that occurs, occurs with bounded gaps between successive occurrences).

## 1.1 Notation

We use the familiar regular expression notation for regular languages. For infinite words, we let $x^\omega$ for a nonempty finite word $x$ denote the infinite word $xxx\dots$.

The exponent of a finite word $x$, denoted $\exp(x)$ is $|x|/p$, where $p$ is the smallest period of $x$. For example, if $x = \text{entente}$, then $\exp(x) = 7/3$. If $q$ divides $|x|$, then by $x^{p/q}$ we mean the word of length $p|x|/q$ that is a prefix of $x^\omega$. For example, $(\text{alff})^{7/3} = \text{alfalfa}$.

If all the nonempty factors $f$ of a (finite or infinite) word $x$ satisfy $\exp(f) < e$, we say that $x$ is *e-free*. If they satisfy $\exp(f) \le e$, we say that $x$ is *e<sup>+</sup>-free*.

The *critical exponent* of an infinite word $w$ is the supremum of $\exp(x)$ over all finite nonempty factors $x$ of $w$. Here the supremum is taken over the extended real numbers, where for each real number $\alpha$ there is a corresponding number $\alpha^+$ satisfying $\alpha < \alpha^+ < \beta$ for all $\beta > \alpha$. Thus if $x$ is a real number, the inequality $x \ge \alpha^+$ has the same meaning as $x > \alpha$.

If $S$ is a set of (finite or infinite) words, then its *repetition threshold* is the infimum of the critical exponents of all its words.

A *run* in a word is a maximum block of consecutive identical letters. The first run is called the *initial run*.

An *occurrence* of a finite nonempty word $x$ in another word $w$ (finite or infinite) is an index $i$ such that $w[i+j] = x[j]$ for $0 \le j < |x|$. The *distance* between two occurrences $i$ and $i'$ is their difference $|i' - i|$.

The *Thue-Morse word* $t = 01101001\dots$ is the infinite fixed point, starting with 0, of the morphism $\mu(0) = 01$ and $\mu(1) = 10$.

## 1.2 Goals of this paper

There are five basic questions that interest us in this paper.

1. Given an infinite sequence $s$, is it pseudoperiodic?

2. If $s$ is $k$-pseudoperiodic for some $k$, what is the smallest such $k$?

3. If $s$ is $k$-pseudoperiodic, what are all the possible pseudoperiods of size $k$?

4. What is the smallest possible critical exponent of an infinite pseudoperiodic word with specified pseudoperiod?

5. How quickly can we tell if a given finite sequence has a pseudoperiod of bounded size?
In particular, we are interested in answering these questions for the class of sequences called automatic. A novel feature of our work is that much of it is done using a theorem-prover for automatic sequences, called *Walnut*, originally developed by Hamoon Mousavi. For more information about *Walnut*, see Mousavi (2016); Shallit (2022).

Here is a brief summary of what we do in our paper. In Section 2 we prove basic results about pseudoperiodicity, and show that questions 1, 2, and 3 above are decidable for the class of automatic sequences. In Section 3, we recall Shevelev's problems about pseudoperiods of the Thue-Morse word, solve them using our method, and also solve his open question from 2012. In Section 4, we obtain analogous pseudoperiodicity results for some other famous sequences. In Section 5 we turn to question 4, obtaining the best possible critical exponent for binary words having certain pseudoperiods. In Section 6 we treat the case of larger alphabets and obtain some results. In Section 7 we prove that checking the existence of a pseudoperiod of size $k$ is, in general, a difficult computational problem, thus answering question 5. Along the way, we state two conjectures (Conjectures 34 and 39) and one open problem (Open Problem 30). Finally, in Section 8, we make some brief biographical remarks about Vladimir Shevelev.

## 2 Basic results

**Proposition 2.** An infinite word $s$ is pseudoperiodic if and only if there exists a bound $B < \infty$ such that two consecutive occurrences of the same letter in $s$ are always separated by distance at most $B$.

*Proof:* Suppose $s$ has pseudoperiod $(p_1, p_2, \dots, p_k)$, with $p_1 < \dots < p_k$. Then clearly we may take $B = p_k$.

On the other hand, if two consecutive occurrence of every letter are always separated by distance $\le B$, then we may take $(1, 2, \dots, B)$ as a pseudoperiod for $s$. $\square$

For binary words we can say this in another way.

**Proposition 3.** Let $x$ be an infinite binary word.

(a) If $M$ is the maximum element of a pseudoperiod, then the longest non-initial run in $x$ is of length $\le M - 1$;

(b) if the longest non-initial run length in $x$ is $B$, then $(1, 2, 3, \dots, B + 1)$ is a pseudoperiod.

In particular, an infinite binary word is pseudoperiodic if and only if it consists of a single letter repeated, or its sequence of run lengths is bounded.

*Proof:* Suppose $x$ is pseudoperiodic with pseudoperiod $(p_1, p_2, \dots, p_k)$ and let $M = \max_{1 \le i \le k} p_i$. Let $a \in \{0, 1\}$ and let $x[p..q]$ be a run of $a$'s and $x[q+1..r]$ be the following run (of $\bar{a}$'s). Then $x[r+1] = a$. Now consider $x[q] = a$. Since $x$ is pseudoperiodic, we know that $(r+1) - q \le M$. Hence all non-initial runs are of length at most $M-1$.

On the other hand, if index $p$ does not correspond to the last letter of a run, then $x[p] = x[p+1]$. If it does so correspond, since the word is binary and all non-initial run lengths are bounded, say by $B$, we know that $x[p+i] = x[p]$ for some $i \le B+1$. So $(1, 2, \dots, B+1)$ is a pseudoperiod. $\square$

**Proposition 4.** The only infinite words with pseudoperiod (1, 2) are those of the form $a^\omega$ or $a^*(ab)^\omega$ and $b^*(ba)^\omega$ for distinct letters $a, b$. The only finite words with pseudoperiod (1, 2) are those of the form $a^*(ab)^*(a+\epsilon)$ with $a \ne b$.
**Proof:** Follows immediately from Proposition 3. □

**Theorem 5.** If an infinite word has pseudoperiod $S$ then it has $\leq \max S$ distinct letters. If it has exactly $\max S$ distinct letters, then it must have a suffix of the form $x^\omega$, where $x$ is a word of length $\max S$ containing each letter exactly once.

**Proof:** Suppose $w$ has pseudoperiod $S$, with $k = \max S$. Since each occurrence of a letter is followed by another occurrence of the same letter at distance $\leq k$, it follows that each letter of $w$ must occur with frequency $\geq 1/k$ in $w$. But the total of all frequencies must sum to 1, so there cannot be more than $k$ distinct letters.

Now suppose $w$ has exactly $k$ distinct letters, say $0, 1, \dots, k-1$. Without loss of generality, assume that the last letter to occur for the first time is $k-1$ and $p_{k-1}$ is this first occurrence. Furthermore, let $p_0, \dots, p_{k-2}$ be the positions of the last occurrence of the letters $0, 1, \dots, k-2$ that precede $p_{k-1}$, and again, without loss of generality assume $p_0 < \dots < p_{k-2} < p_{k-1}$. Thus $w[p_0 \dots p_{k-1}] = 0w_1 1 w_2 2 \dots (k-2) w_{k-1} (k-1)$ for some words $w_1, w_2, \dots, w_{k-1}$, where $w_i$ contains no occurrences of letters $< i$. However, if any of these $w_i$ were nonempty then $w$ could not be pseudoperiodic (because the $0$ at position $p_0$ would not be followed by another $0$ at distance $\leq k$). So all the $w_i$ are empty. Furthermore, pseudoperiodicity also shows that $w[p_{k-1} + 1] = 0$, and inductively, that $w[p_{k-1} + i] = (i-1) \mod k$ for all $i \geq 0$. □

We now turn to results about automatic sequences. This is a large and interesting class of sequences where the $n$th term is computed by a finite automaton taking as input the representation of $n$ in some base (or generalizations, such as Fibonacci base). For more information about automatic sequences, see Allouche and Shallit (2003).

**Corollary 6.** Problems 1, 2, and 3 above are decidable, if $s$ is an automatic sequence.

**Proof:** By the results of Bruyère et al. (1994), it suffices to create first-order logical formulas asserting each property. The domain of the variables in all logical statements is assumed to be $\mathbb{N} = \{0, 1, 2, \dots\}$, the natural numbers.

By Proposition 2, we know that $s$ is pseudoperiodic if there is a bound on the separation of two consecutive occurrences of the same letter. We can assert this as follows. First, define a formula that asserts that $i < j$ are two consecutive occurrences of the same letter:

$$ \text{twoconsec}(i, j) := i < j \wedge \mathbf{s}[i] = \mathbf{s}[j] \wedge \forall p (p > i \wedge p < j) \Rightarrow \mathbf{s}[i] \neq \mathbf{s}[p]. $$

Next, the formula

$$ \text{sep}(B) := \forall i, j \text{ twoconsec}(i, j) \Rightarrow j \leq i + B. $$

asserts the claim that two consecutive occurrences of the same letter are separated by at most $B$. Finally, the formula $\exists B \ \text{sep}(B)$ evaluates to TRUE if and only $s$ is pseudoperiodic. This solves the first problem.

Once we know that $s$ is pseudoperiodic, we can find the smallest $B$ such that $\text{sep}(B)$ holds. To do so, form the automaton for

$$ \text{sep}(B) \wedge \neg \text{sep}(B-1); $$

it will accept exactly one value of $B$, which is the desired minimum. This tells us that $s$ has pseudoperiod $(1, 2, \dots, B)$, so certainly it is $B$-pseudoperiodic.
We can now write the assertion that $\mathbf{s}$ has a pseudoperiod of size $p$, as follows:

$$ \exists a_1, a_2, \dots, a_p \ 1 \le a_1 \wedge a_1 < a_2 \wedge \dots \wedge a_{p-1} < a_p \wedge \\ \qquad \forall n (\mathbf{s}[n] = \mathbf{s}[n+a_1] \lor \mathbf{s}[n] = \mathbf{s}[n+a_2] \lor \dots \lor \mathbf{s}[n] = \mathbf{s}[n+a_p]). $$

By testing this for $p = 1, \dots, B$, we can find the smallest $p$ for which this holds. This solves problem 2. Finally, we can determine all possible pseudoperiods of size $p$ with the formula

$$ 1 \le a_1 \wedge a_1 < a_2 \wedge \dots \wedge a_{p-1} < a_p \wedge \\ \qquad \forall n (\mathbf{s}[n] = \mathbf{s}[n+a_1] \lor \mathbf{s}[n] = \mathbf{s}[n+a_2] \lor \dots \lor \mathbf{s}[n] = \mathbf{s}[n+a_p]). $$

The corresponding finite automaton accepts all the possible pseudoperiods $(a_1, \dots, a_p)$ of size $p$. $\square$

From these ideas we can prove an interesting corollary.

**Corollary 7.** Suppose the automatic sequence $\mathbf{s}$ is not $k$-pseudoperiodic. Then there exists a constant $C$ (depending only on $\mathbf{s}$) such that for all $k$-tuples $0 < p_1 < p_2 < \dots < p_k$, the smallest $n$ for which $\mathbf{s}[n] \notin \{\mathbf{s}[n+p_1], \mathbf{s}[n+p_2], \dots, \mathbf{s}[n+p_k]\}$ satisfies $n \le C p_k$.

**Proof:** A trivial variation on the previous arguments shows that if $\mathbf{s}$ is automatic, then there is an automaton accepting, in parallel, $n, p_1, p_2, \dots, p_k$ such that $n$ is the smallest natural number satisfying $\mathbf{s}[n] \notin \{\mathbf{s}[n+p_1], \mathbf{s}[n+p_2], \dots, \mathbf{s}[n+p_k]\}$. Thus, in the terminology of Shallit (2021), this $n$ can be considered a “synchronized function” of $(p_1, \dots, p_k)$. We can then apply the known linear bound on synchronized functions (Shallit, 2021, Thm. 8) to deduce the existence of $C$ such that $n \le C p_k$. $\square$

Although, as we have just seen, these problems are all decidable for automatic sequences in theory, in practice, the automata that result can be extremely large and require a lot of computation to find. We can use *Walnut*, a theorem-prover originally designed by Mousavi (2016) to translate logical formulas to automata.

**Example 8.** Let us consider an example, the Fibonacci word $\mathbf{f} = 01001010\dots$, the fixed point of the morphism $0 \to 01, 1 \to 0$. The following *Walnut* code demonstrates that it is 2-pseudoperiodic. (In fact, this follows from the much more general Proposition 9 below.)

eval isfibpseudo "?msd_fib Ea,b 1<=a & a<b & An (F[n]=F[n+a] | F[n]=F[n+b]) ":

It returns TRUE.

We can determine all possible pseudoperiods of size 2 using *Walnut*, as follows:

def fib2pseudoperiod "?msd_fib 1<=a & a<b & An (F[n]=F[n+a] | F[n]=F[n+b]) ":

The resulting automaton accepts all pairs $(a, b)$ that are pseudoperiods of $\mathbf{f}$, in Fibonacci representation. It has 28 states and is displayed in Figure 1.

We now consider a famous uncountable class of binary sequences, the *Sturmian words* (Lothaire, 2002, Chap. 2). These are infinite words of the form $\mathbf{s}_{\alpha, \beta} := (\lfloor(n+1)\alpha+\beta\rfloor - \lfloor n\alpha+\beta\rfloor)_{n \ge 1}$, where $0 < \alpha < 1$ is an irrational real number and $0 \le \beta < 1$.

**Proposition 9.** Every *Sturmian sequence* is 2-pseudoperiodic but not 1-pseudoperiodic.
<figure><img src="image_2.png" /><figcaption>**Fig. 1:** Pseudoperiods of size 2 for the Fibonacci word.</figcaption></figure>

**Proof:** If $s_{\alpha,\beta}$ were 1-pseudoperiodic, it would be periodic and hence the letter 1 would occur with rational density. However, the 1's appear in $s_{\alpha,\beta}$ with density $\alpha$, which is irrational.

Now let $[0, c_1, c_2, \dots]$ be the continued fraction expansion of $\alpha$. Without loss of generality, we can assume that $\alpha < 1/2$; otherwise consider $s_{1-\alpha,0}$ which is the binary complement of $s_{\alpha,0}$. Hence $c_1 \ge 2$.

It is easy to see from the definition of $s_{\alpha,\beta}$ that $s_{\alpha,0}$ is a suffix of an infinite concatenation of blocks of the form $0^{c_1-1}1$ and $0^{c_1}1$. It follows that $(c_1, c_1+1)$ is a pseudoperiod. $\square$

*Remark 10.* There are, of course, non-Sturmian sequences that are 2-pseudoperiodic but not 1-pseudoperiodic. For example, every sequence in $\{01, 001\}^\omega$ has pseudoperiod (2, 3).

*Remark 11.* Trivial observation: to determine whether a given fixed tuple $(p_1, p_2, \dots, p_k)$ is a pseudoperiod of an infinite sequence $s$, it suffices to examine all of the factors of length $p_k + 1$ of $s$.

## 3 Shevelev's problems

In this section, we consider some results of Vladimir Shevelev (2012). We reprove some of his results in a much simpler manner, obtain new results, and completely solve one of his open questions.

Recall from Section 1.1 that the Thue-Morse sequence $t = 01101001\cdots$ is the infinite fixed point, starting with 0, of the map sending $0 \to 01$ and $1 \to 10$. Shevelev was interested in the pseudoperiodicity of $t$, and gave a number of theorems and open questions involving this sequence. We are able to prove all of the theorems and conjectures in Shevelev (2012) using our method, with the exception of his Conjecture 1. Luckily, this conjecture was already proved by Allouche (Allouche, 2015, Thm. 3.1).

**Proposition 12.** The Thue-Morse sequence is 3-pseudoperiodic, but not 2-pseudoperiodic.

**Proof:** The first statement follows from the (almost trivial) fact that every word in $\{01, 10\}^\omega$ has pseudoperiod (1, 2, 3).
For the second statement, we use Walnut again. To prove the second half of the theorem, we assert 2-pseudoperiodicity as follows and show that it is false:

$$ \exists a, b (a \ge 1) \wedge (a < b) \wedge \forall i (\mathbf{t}[i] \in \{\mathbf{t}[i+a], \mathbf{t}[i+b]\}). $$

Translating the assertion into Walnut, we have:

eval twopseudotm "Ea,b (a>=1 & a<b) & Ai (T[i]=T[i+a] | T[i]=T[i+b]) ":
# returns FALSE
# 23 ms

This returns FALSE, which proves that the Thue-Morse sequence is not 2-pseudoperiodic.

<figure><img src="image_3.png" /></figure>

Since t is not 2-pseudoperiodic, we know from Corollary 7 that there exists a constant C such that for $1 \le a < b$ we have $\mathbf{t}[n] \notin \{\mathbf{t}[n+a], \mathbf{t}[n+b]\}$ for some $n \le Cb$. For the Thue-Morse word, we can prove the following bound:

**Theorem 13.**

(a) For all $a, b$ with $1 \le a < b$ there exists $n \le \frac{5}{3}b$ such that $\mathbf{t}[n] \notin \{\mathbf{t}[n+a], \mathbf{t}[n+b]\}$.

(b) The previous result is optimal, in the sense that if the bound $\frac{5}{3}b$ is reduced, then there are infinitely many counterexamples.

**Proof:** To prove (a) and (b), we can use the following Walnut commands:

eval casea "Aa,b (1<=a & a<b) => En (3*n<=5*b) &
T[n] != T[n+a] & T[n] != T[n+b] ":
# evaluates to TRUE

eval caseb "Am Ea,b 1<=a & a<b & b>m & Ai (3*i<5*b) =>
(T[i]=T[i+a] | T[i]=T[i+b]) ":
# evaluates to TRUE

<figure><img src="image_4.png" /></figure>

We now turn to Shevelev's Proposition 1 in Shevelev (2012) which (in our terminology) asserts the following:

**Theorem 14.** The triples $\{(a, a + 2^k, a + 2^{k+1}) : a \ge 1, k \ge 0\}$ are pseudoperiods for the Thue-Morse sequence.

Shevelev's proof of this was rather long and involved. We can prove it almost instantly with Walnut, as follows:

**Proof:** We express the conditions placed on the triples as follows.

$$ \text{Power2}(x) := \exists k x = 2^k $$

$$ \text{ShevCond}(a, b, c) := (a \ge 1) \wedge (\exists x \text{ Power2}(x) \wedge (b = a + x) \wedge (c = a + 2x)). $$

We write the proposition as:

$$ \forall a, b, c, i \text{ ShevCond}(a, b, c) \implies (\mathbf{t}[i] \in \{\mathbf{t}[i+a], \mathbf{t}[i+b], \mathbf{t}[i+c]\}). $$

Translating the above into Walnut commands, we have:
```
reg power2 msd_2 "0*10*":
def shevcond "(a>=1) & (Ex $power2(x) & (b=a+x) & (c=a+2*x))":
# returns a DFA with 7 states
# 13 ms
eval prop1 "Aa,b,c,i $shevcond(a,b,c) =>
(T[i]=T[i+a] | T[i]=T[i+b] | T[i]=T[i+c])":
# returns TRUE
# 6 ms
```

The assertion returns TRUE, which proves that the Thue-Morse sequence is 3-pseudoperiodic. ☐

Shevelev observed that Theorem 14 did not characterize all such triples. In his Proposition 2, he showed (1, 8, 9) is a pseudoperiod. We can do this with Walnut as follows:

```
eval shevprop2 "Ai (T[i]=T[i+1]) | (T[i]=T[i+8]) | (T[i]=T[i+9])":
# 97 ms
# return TRUE
```

These two results caused Shevelev to pose his “Open Question 1”, which in our terminology is the following:

**Open Problem 15.** Characterize all triples $(a, b, c)$ with $1 \le a < b < c$ that are pseudoperiods for the Thue-Morse sequence.

Shevelev was unable to solve this, but using our methods, we can easily solve it.

**Theorem 16.** There is a DFA of 53 states that accepts exactly the triples $(a, b, c)$ such that $1 \le a < b < c$ is a pseudoperiod of $t$.

**Proof:** We want to characterize the triples $(a, b, c)$ such that

$$ \text{Triple}(a, b, c) := (a \ge 1) \land (a < b) \land (b < c) \land \forall i \, \mathbf{t}[i] \in \{\mathbf{t}[i+a], \mathbf{t}[i+b], \mathbf{t}[i+c]\}. $$

We construct the following DFA triple in Walnut to answer the question.

```
def triple "(a>=1) & (a<b) & (b<c) &
Ai (T[i]=T[i+a] | T[i]=T[i+b] | T[i]=T[i+c])":
# returns a DFA with 53 states
# 4356513 ms
```

This gives us an automaton of 53 states, which is presented in the Appendix. Determining it was a major calculation in Walnut, requiring 4356 seconds of CPU time and 18 GB of storage. The complete answer to Shevelev's question is then the set of triples accepted by our DFA triple. ☐

Because the answer is so complicated, it is not that surprising that Shevelev did not find a simple answer to his question.

Now that we have the automaton triple, we can easily check any triple $(a, b, c)$ to see if it is a pseudoperiod of $t$ in $O(\log abc)$ time, merely by feeding the automaton with the base-2 representations of the triple $(a, b, c)$.

Furthermore, our automaton can be used to easily prove other aspects of the pseudoperiods of the Thue-Morse sequence. For example:
**Corollary 17.**

(a) For each $a \ge 1$ there exist arbitrarily large $b, c$ such that $(a, b, c)$ is a pseudoperiod of $t$.

(b) For each $b \ge 2$ there exist pairs $a, c$ such that $(a, b, c)$ is a pseudoperiod of $t$.

(c) For each $c \ge 3$ there exist pairs $a, b$ such that $(a, b, c)$ is a pseudoperiod of $t$.

**Proof:** We use the following Walnut code.

eval tmpa "Aa,m (a>=1) => Eb,c b>m & c>m & $triple(a,b,c)":

eval tmpb "Ab (b>=2) => Ea,c $triple(a,b,c)":

eval tmpc "Ac (c>=3) => Ea,b $triple(a,b,c)":

and Walnut returns TRUE for all three.

<figure><img src="image_5.png" /></figure>

We now look at the possible distances between pseudoperiods of $t$.

**Corollary 18.**

(a) $\{b-a : \exists c (a,b,c) \text{ is a pseudoperiod of } t\} = \{(2^j-1)2^i : j \ge 1, i \ge 0\} \cup \{(2^{2j-1}+1)2^i : j \ge 1, i \ge 0\} \cup \{11 \cdot 2^i : i \ge 0\}$.

(b) $\{c-b : \exists a (a,b,c) \text{ is a pseudoperiod of } t\} = \{(2^j-1)2^i : j \ge 1, i \ge 0\} \cup \{(2^j+1)2^i : j \ge 1, i \ge 0\}$.

**Proof:** We use the following Walnut code.

reg parta msd_2 "0*11*0*|0*1(00)*10*|0*10110*":

reg partb msd_2 "0*100*10*|0*11*0*":

eval checka "An $\parta(n) \iff (Ea,b,c \ $triple(a,b,c) & b=a+n)$":

eval checkb "An $\partb(n) \iff (Ea,b,c \ $triple(a,b,c) & c=b+n)$":

and Walnut returns TRUE twice.

<figure><img src="image_6.png" /></figure>

We now turn to Shevelev's Theorem 2 in Shevelev (2012).

**Theorem 19.** The only triples of distinct positive integers $(a, b, c)$ for which both $t[i]$ and $\overline{t[i]}$ belong to $\{t[i+a], t[i+b], t[i+c]\}$ for all $i \ge 0$ are those satisfying $b = a + 2^k$ and $c = a + 2^{k+1}$ for some $k \ge 0$.

**Proof:** To assert the claim in first-order logic, we first construct a formula to show that at least one of the values in $S$ is not equal to the other two; this implies that $S$ contains both $t[i]$ and $\overline{t[i]}$:

$$ \text{NeqTriple}(a, b, c) := (a \ge 1) \land (a < b) \land (a < c) \land \\ \quad \forall i (t[i+a] \neq t[i+b] \lor t[i+b] \neq t[i+c] \lor t[i+c] \neq t[i+a]). $$

Our theorem can then be expressed as follows.

$$ \forall a, b, c (\text{Triple}(a, b, c) \land \text{NeqTriple}(a, b, c)) \iff \text{ShevCond}(a, b, c). $$

Translating the above into Walnut, we build a DFA neqtriple.
def neqtriple "(a>=1) & (a<b) & (b<c) &
    Ai (T[i+a]!=T[i+b] | T[i+b]!=T[i+c] | T[i+c]!=T[i+a])":
# returns a DFA with 7 states
# 554 ms

We prove the theorem with the Walnut command below:

eval thm2 "Aa,b,c ($triple(a,b,c) & $neqtriple(a,b,c)) <=> $shevcond(a,b,c)":
# returns TRUE
# 6 ms

This returns TRUE, which proves the Theorem.

<figure><img src="image_7.png" /></figure>

We now turn to Shevelev's Propositions 3 and 4 in Shevelev (2012). In our terminology, these are as
follows:

**Proposition 20.** For all $k \ge 1$, the Thue-Morse sequence has pseudoperiod $(a, b, c)$ if and only if it has pseudoperiod $(2^k a, 2^k b, 2^k c)$.

**Proof:** We prove the following equivalent statement which implies the proposition by induction on $k$:

$$ \forall a, b, c \text{ Triple}(a, b, c) \iff \text{Triple}(2a, 2b, 2c). $$

Translating this into Walnut, we have the following.

eval prop3n4 "Aa,b,c $triple(a,b,c) <=> $triple(2*a, 2*b, 2*c)":
# returns TRUE
# 14 ms

This returns TRUE, which proves the proposition.

<figure><img src="image_8.png" /></figure>

# 4 Other sequences

After having obtained pseudoperiodicity results for the Thue-Morse sequence **t**, it is logical to try to obtain similar results for other famous sequences.

In this section we examine sequences such as the Rudin-Shapiro sequence **rs**, the variant Thue-Morse sequence **vtm**, the Tribonacci sequence **tr**, and so forth.

For each sequence **s** in this section, we assert 2-pseudoperiodicity as follows and use **Walnut** to determine whether it holds:

$$ \exists a, b (a \ge 1) \land (a < b) \land \forall i (s_i \in \{s_{i+a}, s_{i+b}\}). $$

And we assert 3-pseudoperiodicity as follows and use Walnut to determine whether it holds:

$$ \exists a, b, c (a \ge 1) \land (a < b) \land (b < c) \land \forall i (s_i \in \{s_{i+a}, s_{i+b}, s_{i+c}\}). $$
**4.1 The Mephisto Waltz sequence**

The Mephisto Waltz sequence **mw** = 001001110... is defined by the infinite fixed point of the morphism
0 → 001, 1 → 110 starting with 0. It is sequence **A064990** in the OEIS.

**Proposition 21.** *The Mephisto Waltz sequence is 3-pseudoperiodic, but not 2-pseudoperiodic.*

**Proof:** We translate the assertions of 2-pseudoperiodicity into *Walnut* as follows and show that it is
false.

eval twopseudomw "?msd_3 Ea,b (a>=1 & a<b) &
    Ai (MW[i]=MW[i+a] | MW[i]=MW[i+b])":
# 496 ms
# return FALSE

We translate the assertions of 3-pseudoperiodicity into *Walnut* as follows and show that it is true.

eval threepseudomw "?msd_3 Ea,b,c (a>=1 & a<b & b<c) &
    Ai (MW[i]=MW[i+a] | MW[i]=MW[i+b] | MW[i]=MW[i+c])":
# 2202253 ms
# return TRUE

<figure><img src="image_9.png" /></figure>

Knowing that the Mephisto Waltz sequence is 3-pseudoperiodic naturally leads to the following problem.

**Problem 22.** Characterize all triples (*a*, *b*, *c*) with 1 ≤ *a* < *b* < *c* that are pseudoperiods for the Mephisto Waltz sequence.

We want to characterize the triples (*a*, *b*, *c*) such that

TripleMW(a, b, c) := (a ≥ 1) ∧ (a < b) ∧ (b < c) ∧ ∀i m w [ i ] ∈ { m w [ i + a ] , m w [ i + b ] , m w [ i + c ] } .

We construct the following DFA *triplemw* in *Walnut* to solve the problem.

def triplemw "?msd_3 (a>=1 & a<b & b<c) &
    Ai (MW[i]=MW[i+a] | MW[i]=MW[i+b] | MW[i]=MW[i+c])":
# returns a DFA with 13 states
# 2331762 ms

The complete answer to this problem is the set of triples accepted by our DFA *triplemw*.

**4.2 The ternary Thue-Morse sequence**

The ternary Thue-Morse sequence **vtm** = 210201... is defined by the infinite fixed point of the morphism
2 → 210, 1 → 20, and 0 → 1 starting with 2. It is sequence **A036577** in the OEIS.

**Proposition 23.** *The ternary (variant) Thue-Morse sequence is 3-pseudoperiodic, but not 2-pseudoperiodic.*

**Proof:** We translate the assertions of 2-pseudoperiodicity into *Walnut* as follows and show that it is false.
eval twopseudovtm "Ea,b (a>=1 & a<b) &
   Ai (VTM[i]=VTM[i+a] | VTM[i]=VTM[i+b]) ":
# 235 ms
# return FALSE

We translate the assertions of 3-pseudoperiodicity into Walnut as follows and show that it is true.

eval threepseudovtm "Ea,b,c (a>=1 & a<b & b<c) &
   Ai (VTM[i]=VTM[i+a] | VTM[i]=VTM[i+b] | VTM[i]=VTM[i+c]) ":
# 505315560 ms
# 188 GB
# return TRUE

<figure><img src="image_10.png" /></figure>

Knowing that the ternary Thue-Morse sequence is 3-pseudoperiodic naturally leads to the following problem.

**Problem 24.** Characterize all triples $(a, b, c)$ with $1 \le a < b < c$ that are pseudoperiods for the ternary Thue-Morse sequence.

We want to characterize the triples $(a, b, c)$ such that

TripleVTM$(a, b, c) := (a \ge 1) \land (a < b) \land (b < c) \land \forall i (\mathbf{vtm}[i] \in \{\mathbf{vtm}[i+a], \mathbf{vtm}[i+b], \mathbf{vtm}[i+c]\})$.

We construct the following DFA *triplevtm* in *Walnut* to solve the problem.

def triplevtm "(a>=1 & a<b & b<c) &
   Ai (VTM[i]=VTM[i+a] | VTM[i]=VTM[i+b] | VTM[i]=VTM[i+c]) ":
# returns a DFA with 12 states
# 815830898 ms

The complete answer to this problem is the set of triples accepted by our DFA *triplevtm*. It is depicted
in Figure 2. Again, this was a very large computation with *Walnut*.

<figure><img src="image_11.png" /><figcaption>**Fig. 2:** Automaton recognizing all pseudoperiods of size 3 for the vtm sequence.</figcaption></figure>
By looking at the acceptance paths of Figure 2, we can deduce the following result.

**Theorem 25.** The only 3-pseudoperiods for the vtm sequence are

* {((2^{2i+1} - 1)2^{2j+1}, (2^{2i+2} - 1)2^{2j}, 2^{2i+2j+2}) : i, j \ge 0}

* {((3 \cdot 2^{2j}, (2^{2i+2} + 1)2^{2j+1}, (2^{2i+1} + 1)2^{2j+2}) : i, j \ge 0}

* {((2^{2i+2j+3}, (2^{2i+3} + 1)2^{2j}, (2^{2i+2} + 1)2^{2j+1}) : i, j \ge 0}

**Proof:** There are only essentially three possible paths to the accepting state labeled 8 in Figure 2. They are labeled

* [0, 0, 0]*[0, 0, 1][1, 1, 0]([1, 1, 0][1, 1, 0])*[0, 1, 0]([0, 0, 0][0, 0, 0])*

* [0, 0, 0]*[0, 1, 1]([0, 0, 0][0, 0, 0])*[0, 0, 1][1, 1, 0][1, 0, 0]([0, 0, 0][0, 0, 0])*

* [0, 0, 0]*[1, 1, 1][0, 0, 0]([0, 0, 0][0, 0, 0])*[0, 0, 1][0, 1, 0]([0, 0, 0][0, 0, 0])*

By considering the base-2 numbers specified by each coordinate, we obtain the theorem. ☐

## 4.3 The period-doubling sequence

The period-doubling sequence `pd = 1011101011...` is defined by the infinite fixed point of the morphism $1 \to 10, 0 \to 11$ starting with 1. It is sequence A035263 in the OEIS.

**Proposition 26.** The period-doubling sequence is 3-pseudoperiodic, but not 2-pseudoperiodic.

**Proof:** We translate the assertions of 2-pseudoperiodicity into Walnut as follows and show that it is false.

eval twopseudopd "Ea,b (a>=1 & a<b) &
   Ai (PD[i]=PD[i+a] | PD[i]=PD[i+b])":
# 424 ms
# return FALSE

We translate the assertions of 3-pseudoperiodicity into Walnut as follows and show that it is true.

eval threepseudopd "Ea,b,c (a>=1 & a<b & b<c) &
   Ai (PD[i]=PD[i+a] | PD[i]=PD[i+b] | PD[i]=PD[i+c])":
# 40 ms
# return TRUE

Knowing that the period-doubling sequence is 3-pseudoperiodic naturally leads to the following problem.

**Problem 27.** Characterize all triples $(a, b, c)$ with $1 \le a < b < c$ that are pseudoperiods for the period-doubling sequence.
We want to characterize the triples $(a, b, c)$ such that

$$ \text{TriplePD}(a, b, c) := (a \ge 1) \land (a < b) \land (b < c) \land \forall i (\mathbf{pd}[i] \in \{\mathbf{pd}[i+a], \mathbf{pd}[i+b], \mathbf{pd}[i+c]\}). $$

We construct the following DFA `triplepd` in Walnut to solve the problem.

```python
def triplepd "(a>=1 & a<b & b<c) &
             Ai (PD[i]=PD[i+a] | PD[i]=PD[i+b] | PD[i]=PD[i+c])":
# returns a DFA with 28 states
# 30 ms
```

The complete answer to this problem is the set of triples accepted by our DFA `triplepd`.

## 4.4 The Rudin-Shapiro sequence

The Rudin-Shapiro sequence $r = 00010010\dots$ is defined by the relation $r[n] = |(n)_2|_{11} \mod 2$, that is, the number of occurrences of $11$, computed modulo 2, in the base-2 representation of $n$. It is sequence A020987 in the OEIS.

**Theorem 28.** The Rudin-Shapiro sequence is 4-pseudoperiodic, but not 3-pseudoperiodic.

*Proof:* To check 3-pseudoperiodicity, we used the `Walnut` command

```shell
eval rudinpseudo "Ea,b,c a>=1 & a<b & b<c &
                An (RS[n]=RS[n+a] | RS[n]=RS[n+b] | RS[n]=RS[n+c]) ":
```

which returned the result `FALSE`. This was a big computation, requiring 20003988ms and more than 200 GB of memory on a 64-bit machine.

It is 4-pseudoperiodic, as `Walnut` can easily verify that $(2, 3, 4, 5)$ is a pseudoperiod. ☐

## 4.5 The Tribonacci sequence

The Tribonacci sequence is a generalization of the Fibonacci sequence. It is defined by the infinite fixed point of the morphism $0 \to 01, 1 \to 02$, and $2 \to 0$ and is sequence A080843 in the OEIS.

**Theorem 29.** The Tribonacci sequence is 3-pseudoperiodic, but not 2-pseudoperiodic.

*Proof:* It has pseudoperiod $(4, 6, 7)$, as can be easily verified by checking all factors of length 8 (or with `Walnut`). ☐

**Open Problem 30.** Characterize all the 3-pseudoperiods of the Tribonacci sequence.

Although this is in principle doable with `Walnut`, so far, this seems to be beyond our computational abilities, requiring the determinization of a large nondeterministic automaton.
## 4.6 The paperfolding sequences

The paperfolding sequences are an uncountable family of sequences originally introduced by Davis and Knuth (1970) and later studied by Dekking et al. (1982). The first-order theory of the paperfolding sequences was proved decidable in Goč et al. (2015). Every infinite paperfolding sequence is specified by an infinite sequence *f* of unfolding instructions. Since *Walnut*'s automata work on finite strings—they are not *Büchi automata*—we have to approximate an infinite *f* by considering its finite prefixes *f*. A fuller discussion of exactly how to do this can be found in (Shallit, 2022, Chap. 12); we just sketch the ideas here.

We can use *Walnut* to determine the pseudoperiods of any specific paperfolding sequence, or the pseudoperiod common to all paperfolding sequences.

*Walnut* can prove that no paperfolding sequence is 2-pseudoperiodic, as follows:

```
reg linkf {-1,0,1} {0,1} "() * [0,1] [0,0] *":
def pffactoreq "?lsd_2 At (t<n) => FOLD[f][i+t]=FOLD[f][j+t]":
eval paper_pseudo2 "?lsd_2 Ef,a,b,x 1<=a & a<b & $linkf(f,x) &
       x>=2*b+3 & Ai (i>=1 & i+b+1<=x) =>
       ($pffactoreq(f,i,i+a,1) | $pffactoreq(f,i,i+b,1))":
# FALSE, 26926 secs
```

Here *pffactoreq* asserts that the two length-*n* factors of the paperfolding sequence specified by a finite code *f*, one beginning at position *i* and one at position *j* are the same. And *linkf* asserts that *x = 2^|f|*.
The assertion *paper_pseudo2* is that there exists some paperfolding sequence and numbers *a*, *b* such that every position *i* has a symbol equal to either the symbol at position *i + a* or *i + b*.

All paperfolding sequences are 3-pseudoperiodic; for example, (1, 3, 4) is a pseudoperiod of all paperfolding sequences.

```
eval paper_pseudo134 "?lsd_2 Af,x,i ($linkf(f,x) & i>=1 & i+5<=x) =>
($pffactoreq(f,i,i+1,1) | $pffactoreq(f,i,i+3,1) |
$pffactoreq(f,i,i+4,1))":
```

However, not all pseudoperiods work for all paperfolding sequences. For example, we can use *Walnut* to show that (1, 2, 16) is a pseudoperiod for the paperfolding sequence specified by the unfolding instructions 1 1 1 ..., but not a pseudoperiod for the regular paperfolding sequence (specified by 1 1 1 ...).

We can compute the pseudoperiods that work for all paperfolding sequences simultaneously, using the following *Walnut* code:

```
def paper_pseudo3 "?lsd_2 1<=a & a<b & b<c &
    Af,x,i ($linkf(f,x) & i>=1 & i+c+1<=x) =>
    ($pffactoreq(f,i,i+a,1) | $pffactoreq(f,i,i+b,1) | $pffactoreq(f,i,i+c,1))":
# 10 states, 2356 ms
```

The automaton in Figure 3 accepts the base-2 representation (here, least significant digit first) of those triples (*a*, *b*, *c*) with 1 ≤ *a* < *b* < *c* as a pseudoperiod for all paperfolding sequences.
<figure><img src="image_12.png" /><figcaption>**Fig. 3:** Automaton accepting base-2 representations of pseudoperiod triples common to all paperfolding sequences.</figcaption></figure>

# 5 Critical exponents

In this section we consider the following problem. Suppose we consider the class $C_{a,b}$ of all infinite binary words with a specified pseudoperiod $(a, b)$, for integers $1 \le a < b$. Can we construct words of small critical exponent in $C_{a,b}$? And what is the repetition threshold of $C_{a,b}$?

The general strategy we employ is the following. We use a heuristic search procedure to try to guess a morphism $h_{a,b}$ such that either $h_{a,b}(\mathbf{t})$ or $h_{a,b}(\mathbf{vtm})$ has pseudoperiod $(a, b)$ and avoids $e^+$ powers for some suitable exponent $e$. Once such an $h_{a,b}$ is found, we can verify its correctness using Walnut. Simultaneously we can do a breadth-first search over the tree of all binary words having pseudoperiod $(a, b)$ and avoiding $e$-powers. If this tree turns out to be finite, we have proved the optimality of this $e$.

Our first result shows that this critical exponent can never be $\le 7/3$.

**Theorem 31.** If $\mathbf{x}$ is an infinite binary word that is 2-pseudoperiodic, then $\mathbf{x}$ contains a $(7/3)$-power.

**Proof:** Suppose $\mathbf{x}$ has pseudoperiod $1 \le a < b$, but is $(7/3)$-power-free. Theorem 6 of Karhumäki and Shallit (2004) says that every infinite $(7/3)$-power-free binary word contains factors of the form $\mu^i(0)$ for all $i \ge 0$. These factors are all prefixes of $\mathbf{t}$.

However, as we have seen in Theorem 13, the prefix of length $\frac{5}{3}b + 1$ of $\mathbf{t}$ cannot have pseudoperiod $a, b$, as the relation $\mathbf{t}[n] \in \{\mathbf{t}[n+a], \mathbf{t}[n+b]\}$ is violated for some $n \le \frac{5}{3}b$. Thus it suffices to choose $i$ large enough such that $2^i \ge \frac{5}{3}b + 1$. This contradiction proves the result. $\square$

Next we consider the case $b = 2a$.

**Proposition 32.** Let $a \ge 1$ be an integer. If an infinite word has pseudoperiod $(a, 2a)$, then it has critical exponent $\infty$.
**Proof:** Suppose that $x$ has pseudoperiod $(a, 2a)$. From $x$ extract the subsequences

$$x_{a,i} = (x[an + i])_{n \ge 0}$$

corresponding to indices that are congruent to $i$ (mod $a$), for $0 \le i < a$. Clearly each such subsequence has pseudoperiod $(1, 2)$. By Proposition 4, each subsequence $x_{a,i}$ must be of the form $c^\omega$ or $c^*(cd)^\omega$ for $c, d$ distinct letters. It now follows that $x$ is eventually periodic with period $2a$, and hence has infinite critical exponent. □

**Proposition 33.** Let $\alpha \ge 2^+$. If an $\alpha$-free (resp., $\alpha^+$-free) binary word $w$ has pseudoperiod $(a_1, \dots, a_k)$, then $\mu(w)$ is an $\alpha$-free (resp., $\alpha^+$-free) binary word with pseudoperiod $(2a_1, \dots, 2a_k)$.

**Proof:** The claim about the pseudoperiods is clear. The result about power-freeness can be found in, e.g., (Karhumäki and Shallit, 2004, Theorem 5). □

We now summarize our results on critical exponents in the following table. Each entry corresponding to a pseudoperiod $(a, b)$ with $b \ne 2a$ has three entries:

(a) upper left: an exponent $e$, where the repetition threshold for $C_{a,b}$ is $e^+$;

(b) upper right: the length of the longest finite word having pseudoperiod $(a, b)$ and avoiding $e$-powers;

(c) lower line: the morphic word with pseudoperiod $(a, b)$ and avoiding $e^+$ powers.

<table><caption>**Tab. 1:** Optimal critical exponents for binary words with certain specified pseudoperiod.</caption><thead><tr><th>a<br>1</th><th>b<br>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th><th>12</th></tr></thead><tbody><tr><td>1</td><td>&infin;</td><td>5/2 33<br>h<sub>1.3</sub>(t)</td><td>3 11<br>h<sub>1.1</sub>(t)</td><td>13/5 29<br>h<sub>1.5</sub>(t)</td><td>7/3 15<br>h<sub>1.6</sub>(vtm)</td><td>3 61<br>h<sub>1.7</sub>(t)</td><td>3 45<br>h<sub>1.8</sub>(t)</td><td>5/2 43<br>h<sub>1.9</sub>(t)</td><td>5/2 33<br>h<sub>1.10</sub>(t)</td><td>5/2 52<br>h<sub>1.11</sub>(t)</td><td>5/2 57<br>h<sub>1.12</sub>(t)</td></tr><tr><td>2</td><td></td><td>13/5 30<br>h<sub>1.5</sub>(t)</td><td>&infin;</td><td>3 15<br>h<sub>2.5</sub>(t)</td><td>5/2 66<br>&mu;(h<sub>1.3</sub>(t))</td><td>13/5 84<br>h<sub>2.7</sub>(t)</td><td>13/5 30<br>h<sub>1.5</sub>(t)</td><td>5/2 19<br>h<sub>2.9</sub>(t)</td><td>13/5 60<br>&mu;(h<sub>1.5</sub>(t))</td><td>5/2 20<br>h<sub>2.11</sub>(t)</td><td>7/3 31<br>&mu;(h<sub>1.6</sub>(vtm))</td></tr><tr><td>3</td><td></td><td></td><td>5/2 33<br>h<sub>1.3</sub>(t)</td><td>13/5 34<br>h<sub>1.5</sub>(t)</td><td>&infin;</td><td>13/5 98<br>h<sub>1.5</sub>(t)</td><td>5/2 42<br>h<sub>1.3</sub>(t)</td><td>8/3 28<br>h<sub>3.9</sub>(t)</td><td>13/5 69<br>h<sub>1.5</sub>(t)</td><td>5/2 59<br>h<sub>1.3</sub>(t)</td><td>8/3 72<br>h<sub>3.12</sub>(t)</td></tr><tr><td>4</td><td></td><td></td><td></td><td>3 21<br>h<sub>4.5</sub>(t)</td><td>7/3 40<br>h<sub>4.6</sub>(t)</td><td>3 61<br>h<sub>1.7</sub>(t)</td><td>&infin;</td><td>7/3 18<br>h<sub>1.6</sub>(vtm)</td><td>5/2 33<br>h<sub>1.10</sub>(t)</td><td>5/2 19<br>h<sub>4.11</sub>(t)</td><td>5/2 141<br>&mu;<sup>2</sup>(h<sub>1.3</sub>(t))</td></tr><tr><td>5</td><td></td><td></td><td></td><td></td><td>5/2 66<br>h<sub>5.6</sub>(t)</td><td>3 68<br>h<sub>2.5</sub>(t)</td><td></td><td>5/2 66<br>h<sub>2.6</sub>(t)</td><td>&infin;</td><td>5/2 20<br>h<sub>2.11</sub>(t)</td><td>18/7 158<br>h<sub>5.12</sub>(t)</td></tr><tr><td>6</td><td></td><td></td><td></td><td></td><td></td><td>7/3 40<br>h<sub>4.6</sub>(t)</td><td>5/2 60<br>&mu;(h<sub>1.3</sub>(t))</td><td>17/6 89<br>h<sub>6.9</sub>(t)</td><td>7/3 48<br>h<sub>6.10</sub>(t)</td><td>5/2 69<br>h<sub>1.11</sub>(t)</td><td>&infin;</td></tr><tr><td>7</td><td></td><td></td><td></td><td></td><td></td><td></td><td>13/5 50<br>h<sub>1.5</sub>(t)</td><td>7/3 41<br>h<sub>4.6</sub>(t)</td><td>13/5 92<br>h<sub>2.7</sub>(t)</td><td>13/5 84<br>h<sub>7.11</sub>(t)</td><td>7/3 31<br>h<sub>1.6</sub>(vtm)</td></tr><tr><td>8</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>5/2 66<br>h<sub>8.9</sub>(t)</td><td>5/2 33<br>h<sub>1.10</sub>(t)</td><td>3 65<br>h<sub>8.11</sub>(t)</td><td>7/3 82<br>&mu;(h<sub>4.6</sub>(t))</td></tr><tr><td>9</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>7/3 40<br>h<sub>6.10</sub>(t)</td><td>5/2 57<br>h<sub>9.11</sub>(t)</td><td>55/21 200<br>h<sub>9.12</sub>(t)</td></tr><tr><td>10</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>5/2 33<br>h<sub>1.10</sub>(t)</td><td>7/3 54<br>h<sub>10.12</sub>(t)</td></tr><tr><td>11</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>7/3 31<br>h<sub>11.12</sub>(vtm)</td></tr></tbody></table>

See the files `longest finite seqs.txt` and `critical exp morphisms.txt` at https://github.com/sonjashan/sha_gen.git for the specific morphisms.

From examination of Table 1, we see that all the critical exponents are at most $3^+$. This leads to the following conjecture.
**Conjecture 34.** For all pairs $(a, b)$ with $1 \le a < b$ and $b \ne 2a$, there exists an infinite binary word with pseudoperiod $(a, b)$ and avoiding $3^+$-powers.

We verified this conjecture for $1 \le a < b \le 54$. For each pair of $a$ and $b$, we first try each previously saved morphism $h$ on the Thue-Morse sequence $t$ to see if $h(t)$ has pseudoperiod ${a, b}$ and avoids $3^+$-powers. If that fails, we use backtracking to search for a new morphism that meets the criteria. Once we find such an morphism, we verify the pseudoperiodicity and the powerfreeness with Walnut and save the morphism for future use.

The following morphism is an example. It is initially generated for $a = 1$ and $b = 5$ but it also works for 122 other pairs of $a$ and $b$ we tested.

```
morphism sha3 "0->11100011000 1->11100111000":
image S3 sha3 T:
eval pp1_5_checkS3 "An (S3[n]=S3[n+1]|S3[n]=S3[n+5])":
eval cubeplusfree_S3 "~Ei,n n>0 & Aj (j<=2*n) => S3[i+j] = S3[i+j+n]":
```

For more details on this implementation, please see the github repository at

https://github.com/sonjashan/sha_gen.git.

Let us also provide details about the exceptional case of $a = 1$ and $b = 6$. The morphic word with pseudoperiod (1, 6) which avoids $(7/3)^+$-powers is $h_{1,6}(\mathbf{vtm})$, where $h_{1,6}(0) = 0011011001011001$, $h_{1,6}(1) = 0011011001$, and $h_{1,6}(2) = 001101$.

A simple computation shows that $h(\mathbf{vtm})$ has pseudoperiod (1, 6) and that its factors of length 1000 avoid $(7/3)^+$-powers.

Suppose that $h_{1,6}(\mathbf{vtm})$ contains a factor $w$ that is a $(7/3)^+$-power. Thus $|w| > 1000$. Notice that the factor 0011 is a common prefix of the $h_{1,6}$-image of all three letters. Moreover, 0011 appears in $h_{1,6}(\mathbf{vtm})$ only as the prefix of the $h$-image of a letter.

We consider the word $w'$ obtained from $w$ by erasing the smallest prefix of $w$ such that $w'$ starts with $0011$. Since we erase at most $|h(0)| - 1 = 15$ letters, the word $w'$ is a repetition of period $p$ and exponent at least 2.2.

So $w'[1..4] = w'[p + 1..p + 4] = w'[2p + 1..2p + 4] = 0011$. This implies that $w'[1..2p] = h(uu)$ where the pre-image $uu$ must be a factor of $vtm$. This is a contradiction, since $vtm$ is squarefree.

Finally, the results with a morphic word using $\mu$ as outer morphism are obtained via Proposition 33.

## 5.1 Binary words with pseudoperiods of the form $(1, a)$

**Theorem 35.** For at least 85% of all positive integers $a \ge 3$ there is an infinite binary word with pseudoperiod (1, a), and avoiding $3^+$-powers.

**Proof:** The idea is to search for words with the given properties that have pseudoperiod (1, a) for all $a$ in a given residue class $a \equiv i \pmod{n}$. As before, our words are constructed by applying an $n$-uniform morphism (obtained by a heuristic search) to the Thue-Morse word $t$, and then correctness is verified with Walnut.

Our results are summarized in Table 2.

As an example, here is the Walnut code verifying the results for $(i, n) = (4, 5)$:

```
morphism a45 "0->00011 1->00111":
image B45 a45 T:
```
<table><thead><tr><th>i</th><th>n</th><th>morphism</th></tr></thead><tbody><tr><td>4</td><td>5</td><td>0 → 00011<br>1 → 00111</td></tr><tr><td>3</td><td>7</td><td>0 → 0010011<br>1 → 0011011</td></tr><tr><td>4</td><td>9</td><td>0 → 000100011<br>1 → 000110011</td></tr><tr><td>8</td><td>9</td><td>0 → 110011000<br>1 → 110011100</td></tr><tr><td>4</td><td>11</td><td>0 → 11000111000<br>1 → 11000111001</td></tr><tr><td>5</td><td>11</td><td>0 → 11000111000<br>1 → 11000111001</td></tr><tr><td>7</td><td>11</td><td>0 → 10011001000<br>1 → 10011001001</td></tr><tr><td>8</td><td>11</td><td>0 → 10110100100<br>1 → 10110100101</td></tr><tr><td>10</td><td>11</td><td>0 → 11000111000<br>1 → 11000111001</td></tr></tbody></table>

<table><caption>**Tab. 2:** Words avoiding $3^+$ powers with pseudoperiods in residue classes.</caption><thead><tr><th>i</th><th>n</th><th>morphism</th></tr></thead><tbody><tr><td>5</td><td>13</td><td>0 → 1010010110100<br>1 → 1010010110101</td></tr><tr><td>8</td><td>13</td><td>0 → 1100110001000<br>1 → 1100110001001</td></tr><tr><td>4</td><td>14</td><td>0 → 11000100011000<br>1 → 11000100011001</td></tr><tr><td>9</td><td>14</td><td>0 → 11001110011000<br>1 → 11001110011101</td></tr><tr><td>13</td><td>14</td><td>0 → 11001100111000<br>1 → 11001100011001</td></tr><tr><td>7</td><td>15</td><td>0 → 110110011001000<br>1 → 110110011001001</td></tr><tr><td>4</td><td>16</td><td>0 → 1000111000111000<br>1 → 1000111000111001</td></tr><tr><td>6</td><td>16</td><td>0 → 1011001001101000<br>1 → 1011001001101001</td></tr><tr><td>10</td><td>16</td><td>0 → 1000111000111000<br>1 → 1000111000111001</td></tr><tr><td>15</td><td>16</td><td>0 → 1100111000111000<br>1 → 1100111000110001</td></tr></tbody></table>

eval cube45 "~Ei,n (n>=1) & At (t<=2*n) => B45[i+t]=B45[i+n+t]":
eval test45 "Ap (Ek p=5*k+4) => An (B45[n]=B45[n+1]|B45[n]=B45[n+p])":

and both commands return TRUE.

The residue classes in Table 2 correspond to $n = 5, 7, 9, 11, 13, 14, 15, 16$. Now $lcm(5, 7, 9, 11, 13, 14, 15, 16) = 720720$, and the residue classes above cover 614614 of the possible residues (mod 720720). So we have covered $614614/720720 \doteq .852$ of all the possible $a$. $\square$

Theorem 35 can obviously be improved by considering larger moduli. For example, there exists a morphism for every residue class modulo 41 except 0, 1, 2, 5, 6, 21, 23, 39.

# 6 Larger alphabets

Up to now we have been mostly concerned with binary words. In this section we consider pseudoperiodicity in larger alphabets.

The (unrestricted) repetition threshold $RT(k)$ for words over $k$ letters is well-known: we have $RT(3) = 7/4$, $RT(4) = 7/5$, and $RT(k) = k/(k-1)$ if $k = 2$ or $k \ge 5$ Currie and Rampersad (2011); Rao (2011). Notice that the words attaining the repetition threshold are necessarily 3-pseudoperiodic. Indeed, every infinite $(k-1)/(k-2)$-free word over $k \ge 3$ letters is $(k-1, k, k+1)$-periodic. Thus, it remains to investigate 2-pseudoperiodic words.
Let us consider the repetition threshold $RT'(k)$ for 2-pseudoperiodic words over $k$ letters. Obviously, $RT(k) \le RT'(k)$. From the previous section, we know that $RT'(2) = 7/3$. The following results show that $RT'(3) = 7/4$, $RT'(4) \le 3/2$, and $RT'(5) \le 4/3$, respectively.

**Theorem 36.** *The image of every $(7/5)^+$-free word over 4 letters by the following 188-uniform morphism avoids $(7/4)^+$-powers and has pseudoperiod (18, 37).*

$$
\begin{array}{rcl}
0 & \to & p201021201210120102120210201202120121020102120121012010210 \\
& & 1210201202120121020102101201020120210121021201210120102120 \\
1 & \to & p201021201210120102101210201202120121021202101201020120210 \\
& & 1210212012101201021202101201020120210201021201210120102120 \\
2 & \to & p201021201210120102101210201202120121020102101201020120210 \\
& & 1210212012101201021202102012021201210201021201210120102101 \\
3 & \to & p121021201210120102120210120102012021020102120121012010210 \\
& & 1210201202120121021202101201020120210121021201210120102120
\end{array}
$$

where $p = 2102012021201210201021012010201202101210201202120121021202101201020120210$.

**Theorem 37.** *The image of every $(7/5)^+$-free word over 4 letters by the following 170-uniform morphism avoids $(3/2)^+$-powers and has pseudoperiod (4, 10).*

$$
\begin{array}{rcl}
0 & \to & p301020323132102010313231201020323130102012313230201021323120102032 \\
& & 313210201031323020102132313010203231321020123132302010313231201020 \\
1 & \to & p201020323132102012313230201021323130102012313210201031323120102132 \\
& & 313010203231321020103132302010213231301020123132302010313231201020 \\
2 & \to & p201020323132102010313231201021323130102032313210201231323020102132 \\
& & 313010201231321020103132312010203231301020123132302010313231201021 \\
3 & \to & p201020323132102010313231201021323130102012313230201021323120102032 \\
& & 313010201231321020103132312010203231321020123132302010313231201021
\end{array}
$$

where $p = 32313010201231321020103132302010213231$.

**Theorem 38.** *The image of every $(5/4)^+$-free word over 5 letters by the following 84-uniform morphism avoids $(4/3)^+$-powers and has pseudoperiod (9, 19).*
0 $\rightarrow$ p312402104302403104201403204230243210230140210420124320423124021423024031
1 $\rightarrow$ p312402104301403204231203210230140210430120310420124320423124021423024032
2 $\rightarrow$ p012432102312402104301403104201243204230140210430120310423024321023014031
3 $\rightarrow$ p012402104302403104201243210231240210420140320423120321423024321023014032
4 $\rightarrow$ p012402104301403104201243214231240210420140320423124321423024031023014032

where $p = 043012032142$.

Theorems 36, 37, and 38 make use of (Ochem, 2006, Lemma 2.1), which has been recently extended to larger exponents in (Mol et al., 2020, Lemma 23). In each case, the common prefix $p$ appears only as the prefix of the image of a letter. This ensures that the morphism is synchronizing. Then we check that the image of every considered Dejean word $u$ of length $t$ is $RT'(k)^+$-free, where $t$ is specified by (Ochem, 2006, Lemma 2.1).

In addition, using depth-first search of the appropriate space, we have constructed:

* A $(5/4)^+$-free word over 6 letters with pseudoperiod (9,24), of length 500000.

* A $(6/5)^+$-free word over 7 letters with pseudoperiod (22,33), of length 500000.

These examples suggest the following conjecture.

**Conjecture 39.** For every $k \ge 4$ we have $RT'(k) = \frac{k-1}{k-2}$.

# 7 Computational complexity

For a finite word, checking a given specific pseudoperiod is obviously easy. However, checking the existence of an arbitrary pseudoperiod is computationally hard, as we show now.

Consider the following decision problem:

**PSEUDOPERIOD:**

*Instance:* a string $x$ of length $n$, and positive integers $k$ and $B$.

*Question:* Does there exist a set $S = \{p_1, p_2, \dots, p_k\}$ of cardinality $k$ with $1 \le p_1 < \dots < p_k \le B$ such that $x[i] \in \{x[i+p_1], x[i+p_2], \dots, x[i+p_k]\}$ for $1 \le i \le n-p_k$?

**Theorem 40.** *PSEUDOPERIOD is NP-complete.*

**Proof:** It is easy to see that PSEUDOPERIOD is in NP, as we can check an instance in polynomial time.

To see that PSEUDOPERIOD is NP-hard, we reduce from a classical NP-complete problem, namely, HITTING SET Karp (1972). It is defined as follows:

**HITTING SET**

*Instance:* A list of sets $S_1, S_2, \dots, S_m$ over a universe $U = \{1, 2, \dots, n\}$ and an integer $k'$.

*Question:* Does there exist a set $H = \{h_1, h_2, \dots, h_{k'}\}$ of cardinality $k'$ such that $S_i \cap H \ne \emptyset$ for all $i$?
Given an instance of HITTING SET $S_1, S_2, \dots, S_m$ and $U = \{1, 2, \dots, n\}$, and integer $k'$, define $a_{\ell,i} = 1$ if $\ell \in S_i$ and $a_{\ell,i} = 0$ otherwise. We construct a PSEUDOPERIOD instance with $k = k' + 4$, $B = 4n + 5$, and a string $x$, as follows:

$$x = uvwz_1z_2\cdots z_m$$

and

$$u = 11 0^{4n+3}$$

$$v = 101 0^{4n+3}$$

$$w = 1001 0^{4n+3}$$

$$z_i = 1000 a_{1,i} 000 a_{2,i} \cdots 000 a_{n,i} 0000 (0011)^n 0.$$

We first show that if the PSEUDOPERIOD instance has a solution, then we can extract a solution for the HITTING SET instance. To do so, we examine what a valid pseudoperiod would look like for $x$ by first considering each 1 symbol.

The first 1 symbol, $u[1] = x[1] = 1$, is followed by $10^{4n+3}$ and since the $p_j$ forming the pseudoperiod are bounded by $B = 4n + 5$, we require $p_1 = 1$ for the pseudoperiod property to be satisfied at $x[1]$. Similarly, the next 1 symbol $u[2] = x[2] = 1$ is followed by $0^{4n+3}1$, which requires that some $p_j$ equal $4n+4$, in order to satisfy the pseudoperiod property. The $v$ factor is analogous in that $v[1] = 1$ is followed by $010^{4n+3}$, which gives us that $p_2 = 2$ and $v[3] = 1$ has a 1 symbol $4n+4$ symbols afterward, so it also satisfies the pseudoperiod property. The $w$ factor is such that $w[1] = 1$ is followed by $0010^{4n+3}$, which then forces $p_3 = 3$ with $w[4]$ satisfied by having a 1 symbol $4n+4$ symbols afterward as previous.

We now consider the $z_i$ factors. For each $z_i$, the 1 symbol at $z_i[1]$ satisfies the pseudoperiod property if and only if the pseudoperiod contains some $p_j$ such that $p_j/4 \in S_i$. Since the only possible indices that can be 1 within the $B$ bound are the $a_{\ell,i}$, the pseudoperiod property is satisfied at $z_i[1]$ using some $p_j$ of the pseudoperiod if and only if $z_i[1 + p_j] = a_{p_j/4,i} = 1$ which means $p_j/4 \in S_i$.

Considering the remaining 1 symbols in $z_i$, we see that each $a_{j,i}$ is followed by a 0 symbol and has a 1 symbol exactly $4n + 4$ indices later in the $(0011)^n$ factor. Regardless of the assignment of $a_{j,i}$ the pseudoperiod property is satisfied. Each 1 symbol in the $(0011)^n$ factor has another 1 symbol either $p_1 = 1$, $p_2 = 2$, or $p_3 = 3$ indices later, as each 0011 is followed by one of: another 0011, 01 where the 1 symbol is $z_{i+1}[1]$, or the end of the string if $i = m$ in which case it satisfies the pseudoperiod property by default.

Finally, we observe that there are no more than two consecutive 1 symbols in $x$, so the pseudoperiod property is satisfied at every 0 symbol, as there is another 0 symbol either $p_1 = 1$, $p_2 = 2$, or $p_3 = 3$ indices later.

Taken together, a satisfying pseudoperiod for this instance is of the form $\{1, 2, 3, 4n+4\} \cup P$, where $P$ is a set of cardinality $k'$ that has the property for all $S_i$, there exists $p_j \in P$ such that $p_j/4 \in S_i$. Therefore, if such a pseudoperiod exists, then we can derive a solution $H = \{p_j/4 | p \in P\}$ for the HITTING SET instance from the solution to the generated PSEUDOPERIOD instance.

Conversely, if the HITTING SET instance has a solution $H$ then

$$P = \{1, 2, 3, 4n + 4\} \cup \{4 \cdot h \mid h \in H\}$$
is a valid pseudoperiod for $x$. All of the 0 symbols and most of the 1 symbols are satisfied by the $p_1 = 1, p_2 = 2, p_3 = 3$, or $p_k = 4n + 4$ as previously explained. We only need to check that the $z_i[1] = 1$ also satisfy the desired property. There exists some $h_i \in S_i \cap H$, since $H$ is a hitting set, which means that $a_{h_i,i} = 1$. This gives us that $z_i[1 + h_i \cdot 4] = a_{h_i,i} = 1$ and $4 \cdot h_i \in P$, which means each $z_i[1]$ also satisfies the pseudoperiod property and $P$ is a pseudoperiod for this instance.

Therefore, PSEUDOPERIOD is NP-Hard. This completes the proof. ☐

## 8 About Vladimir Shevelev

Here we present some details about Vladimir Shevelev’s life and contributions, based on Shevelev (2022).

Vladimir Samuil Shevelev was born on March 9 1945 in Novocherkassk, Russia, under the name Vladimir Abramovich. He received his Ph.D. in mathematics in 1971 from the Rostov-on-Don State University in the USSR. In 1992 he received a D.Sc. in combinatorics from the Glushkov Cybernetic Institute, Academy of Ukraine, Kiev.

From 1971 to 1974 he was Assistant Professor at the Department of Mathematics, Rostov State University. From 1974 to 1999 he taught at the Department of Mathematics, Rostov State Building University. In 1982 he took the surname “Shevelev” and in 1999 he emigrated to Israel, where he taught at the Ben-Gurion University of the Negev and did research at the Tel Aviv University.

From 1969 to 2016, Vladimir Shevelev published approximately 60 mathematical papers in refereed journals. He also published approximately 40 preprints on the arXiv. He was an excellent chess player, played the violin, and was a member of a Russian vocal group. He was married and had three children and six grandchildren. He died on May 3 2018 in Beersheba, Israel.

May his memory be a blessing.

<figure><img src="image_13.png" /><figcaption>Photograph taken from https://www.math.bgu.ac.il/~shevelev/Hobbies.pdf.</figcaption></figure>
Acknowledgements

This work benefited from the use of the CrySP RIPPLE Facility at the University of Waterloo. Thanks to Ian Goldberg for allowing us to run computations on this machine.

We thank the referees for a careful reading of the paper and for many useful suggestions and corrections.

We are grateful to Daniel Berend and Simon Litsyn for their assistance in obtaining information about the life of Vladimir Shevelev.

References

J.-P. Allouche. Thue, combinatorics on words, and conjectures inspired by the Thue-Morse sequence. *J. Théorie Nombres Bordeaux*, 27:375–388, 2015.

J.-P. Allouche and J. Shallit. *Automatic Sequences: Theory, Applications, Generalizations*. Cambridge University Press, 2003.

A. Blondin Massé, S. Gaboury, and S. Hallé. Pseudoperiodic words. In H.-C. Yen and O. H. Ibarra, editors, *DLT 2012*, volume 7410 of *Lecture Notes in Computer Science*, pages 308–319. Springer-Verlag, 2012.

V. Bruyère, G. Hansel, C. Michaux, and R. Villemaire. Logic and $p$-recognizable sets of integers. *Bull. Belgian Math. Soc.*, 1:191–238, 1994. Corrigendum, *Bull. Belgian Math. Soc.* **1** (1994), 577.

J. Currie and N. Rampersad. A proof of Dejean's conjecture. *Math. Comp.*, 80:1063–1070, 2011.

C. Davis and D. E. Knuth. Number representations and dragon curves–I, II. *J. Recreational Math.*, 3: 66–81, 133–149, 1970.

F. M. Dekking, M. Mendès France, and A. J. v. d. Poorten. Folds! *Math. Intelligencer*, 4:130–138, 173–181, 190–195, 1982. Erratum, *5* (1983), 5.

D. Goč, H. Mousavi, L. Schaeffer, and J. Shallit. A new approach to the paperfolding sequences. In A. B. et al., editor, *Computability in Europe, Cie 2015*, volume 9136 of *Lecture Notes in Computer Science*, pages 34–43. Springer-Verlag, 2015.

J. Karhumäki and J. Shallit. Polynomial versus exponential growth in repetition-free binary words. *J. Combin. Theory. Ser. A*, 105(2):335–347, 2004.

R. M. Karp. Reducibility among combinatorial problems. In R. E. Miller and J. W. Thatcher, editors, *Complexity of Computer Computations*, pages 85–104. Plenum Press, 1972.

M. Lothaire. *Algebraic Combinatorics on Words*, volume 90 of *Encyclopedia of Mathematics and its Applications*. Cambridge University Press, 2002.

S. Marcus. Quasiperiodic infinite words. *Bull. European Assoc. Theor. Comput. Sci.*, 82:170–174, 2004.

L. Mol, N. Rampersad, and J. Shallit. Extremal overlap-free and extremal $\beta$-free binary words. *Electronic J. Combinatorics*, 27(4):#P4.42, 2020.

H. Mousavi. Automatic theorem proving in *Walnut*. Arxiv preprint arXiv:1603.06017 [cs.FL], available at http://arxiv.org/abs/1603.06017, 2016.
P. Ochem. A generator of morphisms for infinite words. *RAIRO Inform. Théor. App.*, 40:427–441, 2006.

M. Rao. Last cases of Dejean's conjecture. *Theoret. Comput. Sci.*, 412:3010–3018, 2011.

J. Shallit. Synchronized sequences. In T. Lecroq and S. Puzynina, editors, *WORDS 2021*, volume 12847 of *Lecture Notes in Computer Science*, pages 1–19. Springer-Verlag, 2021.

J. Shallit. *The Logical Approach To Automatic Sequences: Exploring Combinatorics on Words with Walnut*, volume 482 of *London Math. Soc. Lecture Note Series*. Cambridge University Press, 2022.

V. Shevelev. Equations of the form $t(x + a) = t(x)$ and $t(x + a) = 1 - t(x)$ for Thue-Morse sequence. Arxiv preprint arXiv:0907.0880 [math.NT], available at https://arxiv.org/abs/0907.0880, 2012.

V. Shevelev. Website of Vladimir Shevelev, 2022. Available at https://www.math.bgu.ac.il/~shevelev/.

## Appendix A The automaton triple

In this section we provide the Walnut code for the automaton triple.

<table><thead><tr><th>msd_2 msd_2 msd_2</th><th>7 0<br>0 1 1 -> 24<br>1 1 1 -> 25</th><th>17 0<br>0 1 0 -> 35<br>0 1 1 -> 6</th><th>27 0<br>1 0 1 -> 43</th><th>37 0<br>1 0 1 -> 24</th></tr></thead><tbody><tr><td>0 0</td><td>8 0</td><td>18 0</td><td>28 0</td><td>38 1</td></tr><tr><td>0 0 0 -> 0</td><td>0 0 0 -> 26</td><td>1 1 0 -> 18</td><td>0 0 0 -> 44</td><td>0 0 0 -> 50</td></tr><tr><td>0 0 1 -> 1</td><td>1 0 0 -> 27</td><td>1 1 1 -> 24</td><td>0 0 1 -> 29</td><td>1 1 1 -> 19</td></tr><tr><td>0 1 1 -> 2</td><td>9 0</td><td>19 1</td><td>29 0</td><td>39 0</td></tr><tr><td>1 1 1 -> 3</td><td>0 0 0 -> 28</td><td>0 0 0 -> 19</td><td>1 1 0 -> 24</td><td>0 1 0 -> 51</td></tr><tr><td>1 0</td><td>1 0 0 -> 4</td><td>1 0 1 -> 29</td><td>30 1</td><td>40 1</td></tr><tr><td>0 1 0 -> 5</td><td>1 0 0 -> 14</td><td>1 1 1 -> 19</td><td>0 0 0 -> 46</td><td>0 0 0 -> 24</td></tr><tr><td>0 1 1 -> 6</td><td>0 0 1 -> 29</td><td>20 0</td><td>1 1 1 -> 19</td><td>1 1 0 -> 23</td></tr><tr><td>1 1 1 -> 7</td><td>1 0 1 -> 19</td><td>0 0 0 -> 36</td><td>31 0</td><td>41 0</td></tr><tr><td>2 0</td><td>10 0</td><td>0 1 0 -> 37</td><td>1 0 1 -> 47</td><td>0 0 0 -> 26</td></tr><tr><td>0 0 0 -> 8</td><td>1 1 0 -> 22</td><td>21 1</td><td>32 1</td><td>42 1</td></tr><tr><td>1 0 0 -> 9</td><td>11 1</td><td>0 0 0 -> 38</td><td>0 0 0 -> 24</td><td>0 0 0 -> 52</td></tr><tr><td>0 0 1 -> 10</td><td>0 0 0 -> 30</td><td>0 1 0 -> 39</td><td>1 0 1 -> 48</td><td>1 1 0 -> 24</td></tr><tr><td>1 0 1 -> 11</td><td>1 1 0 -> 24</td><td>1 0 1 -> 24</td><td>43 0</td><td>1 1 1 -> 19</td></tr><tr><td>1 1 1 -> 12</td><td>1 0 1 -> 31</td><td>1 1 1 -> 19</td><td>0 1 1 -> 24</td><td>0 0 0 -> 28</td></tr><tr><td>3 0</td><td>1 1 1 -> 19</td><td>22 0</td><td>1 0 0 -> 24</td><td>0 0 1 -> 29</td></tr><tr><td>0 0 0 -> 3</td><td>12 0</td><td>1 0 0 -> 24</td><td>33 0</td><td>51 0</td></tr><tr><td>0 0 1 -> 13</td><td>0 0 1 -> 24</td><td>1 0 1 -> 32</td><td>0 0 1 -> 24</td><td>0 1 0 -> 39</td></tr><tr><td>0 1 1 -> 14</td><td>1 0 1 -> 32</td><td>1 1 1 -> 33</td><td>1 0 1 -> 24</td><td>1 1 1 -> 24</td></tr><tr><td>1 1 1 -> 3</td><td>1 1 1 -> 33</td><td>23 0</td><td>1 1 1 -> 33</td><td>44 0</td></tr><tr><td>4 0</td><td>13 0</td><td>1 1 0 -> 40</td><td>34 0</td><td>45 0</td></tr><tr><td>0 0 0 -> 15</td><td>0 1 0 -> 19</td><td>24 1</td><td>1 0 0 -> 16</td><td>0 1 0 -> 24</td></tr><tr><td>1 0 0 -> 16</td><td>1 1 0 -> 13</td><td>0 0 0 -> 24</td><td>1 1 1 -> 24</td><td></td></tr><tr><td>0 1 0 -> 17</td><td>1 1 0 -> 13</td><td>25 0</td><td>35 0</td><td>46 1</td></tr><tr><td>1 1 0 -> 18</td><td>14 0</td><td>0 1 0 -> 24</td><td>0 1 0 -> 17</td><td>0 0 0 -> 30</td></tr><tr><td>1 1 1 -> 19</td><td>1 0 0 -> 14</td><td>0 1 1 -> 24</td><td>1 1 0 -> 49</td><td>1 1 0 -> 24</td></tr><tr><td>5 0</td><td>15 0</td><td>1 1 1 -> 7</td><td>36 0</td><td>1 1 1 -> 19</td></tr><tr><td>0 0 0 -> 20</td><td>0 0 0 -> 15</td><td>26 0</td><td>0 0 0 -> 20</td><td>47 0</td></tr><tr><td>0 1 0 -> 21</td><td>1 1 1 -> 19</td><td>0 0 0 -> 41</td><td>0 1 0 -> 37</td><td>1 0 1 -> 31</td></tr><tr><td>1 1 0 -> 13</td><td>0 0 0 -> 15</td><td>0 0 1 -> 10</td><td>0 1 1 -> 22</td><td>1 1 1 -> 24</td></tr><tr><td>0 1 1 -> 22</td><td>1 1 1 -> 19</td><td>1 0 1 -> 42</td><td></td><td></td></tr><tr><td>6 0</td><td>16 0</td><td></td><td></td><td></td></tr><tr><td>1 1 0 -> 23</td><td>1 0 0 -> 34</td><td></td><td></td><td></td></tr></tbody></table>