On an algorithm for multiperiodic words

We consider an algorithm by Tijdeman and Zamboni constructing a word of a given length that has a given set of periods, and the richest possible alphabet. We show that this algorithm can be easily stated and its correctness briefly proved using the class equivalence approach.


A short (personal) history
Non-trivial words with a given set of periods P = {p 1 , p 2 , . . ., p r } have received a lot of attention in the past decade.The motivation was to generalize the result by Fine and Wilf dealing with two periods, which became part of the folklore.A word with periods P is called trivial if gcd(P ) is its period too.Papers [1] and [4] are two (independent) results considering non-trivial such words with maximal length and maximal cardinality of its alphabet.Those papers completed some older research of Castelli, Mignosi, Restivo and Justin (see, e.g., [5] for more details and references).Already in 1998, I wrote a short manuscript giving an analogous result (without considering its publication), which I showed to Sorin Constantinescu during the conference WORDS 2003 in Turku, where he presented their results.Since this was passed without notice in the subsequent publication and since I considered my approach simpler and more natural, I later decided to publish it in [2].There was a gap in my paper, discovered by Gwénaël Richomme, which is fixed in [3].
The present paper extends the same approach to the construction of the richest word with a given set of periods and a given length.The basic idea is to consider relations defined by the periods and understand letters as (names of) equivalence classes generated by those relations.The idea is obvious and well known, usually expressed using the graph terminology (edges and connected components), rather than the algebraic terminology (relations and equivalence classes).Tijdeman and Zamboni [5] point out that the straightforward algorithm based on the graph approach is "simple but inefficient" and then present an algorithm based on less transparent combinatorial analysis.The aim of this paper is to give a short description of their algorithm, as well as a short and intuitive proof of its correctness, using consistently the graph/equivalence viewpoint.

Notation
Let w be a word of length n over an alphabet A. The set of all letters that occur in w is denoted by alph(w).The i-th letter of w is denoted by w We say that a positive integer p is a period of a word w if w[i] = w[i + p] for all 0 ≤ i ≤ |w| − i − 1 (where |w| denotes the length of the word).Note that any p ≥ |w| is a period of u.If P is a set of positive integers such that each p ∈ P is a period of w, we say that w has periods P .
The word of length n having periods P and the maximal possible cardinality of alph(w) is called an FW-word relative to P (where FW stands for "Fine and Wilf" for historic reasons).The word is called trivial with respect to P if gcd(P ) is a period of w.The longest non-trivial FW-word relative to P is called an extremal FW-word relative to P .We denote its length by L(P ) (note that L(P ) = L(P ) − 1 where L(P ) is the notation adopted in [5]).

Classes of Equivalence
Let w be a word which has periods P .For the rest of the paper we denote m = min P .Obviously, if i ≡ j mod m or |i − j| ∈ P , then w[i] = w[j].These two conditions induce the relation ∼ P,k on integers {0, . . ., k − 1} defined by: i ∼ P,k j if Let ≈ P,k be the equivalence closure of ∼ P,k .In other words, we have i ≈ P,k j if and only if i and j lie in the same connected component of the graph defined by edges i ∼ P,k j.The class of ≈ P,k containing i will be denoted by [i] P,k and represented by its minimal element min[i] P,k .Then we obtain a word FW(P, k) of length k over the alphabet N by The construction immediately yields that FW(P, k) is the unique (up to renaming of letters) FW-word of length k relative to P .

The algorithm
The basic step of the algorithm is the reduction of P to a new set of periods Q defined by ( 1) (where m = min P according to our convention).This reduction is, in fact, one step in the Eucledean algorithm, and is well known in the literature on multiperiodic words.The key fact about P and Q is expressed in the following lemma, which is an improved version of Lemma 2 from [2].
Corollary 1.For any k ≥ 0, the word FW(Q, k) is a prefix of FW(P, k + m).
The following lemma is an easy observation.
Proof.Both i−p and i+p are out of range {0, 1, . . ., n−1} for any p ∈ P (including m).Therefore i is not related by ∼ P,k to any other element.
From Corollary 1 and Lemma 2, the formula can be readily derived (see [2,3]).In addition, it yields the following construction of FW(P, n), equivalent to Algorithm B described in [5].
(1) If n ≤ m, then Lemma 2 with k = 0 gives (Recall that we consider integers as letters.To stress that, we use the typewriter font for them.The multiplication sign means concatenation).Example.Let P = {5, 7} and n = 8.Recursive definition of FW(P, 8) leads to

( 2 )
Let n > m.Since the word FW(P, n) has a period m, it is determined by its prefix w of length m.Denote u = FW(Q, n − m).Corollary 1 and Lemma 2 imply that• w = pref m (u) if m ≤ n − m, and • w = u • |u| • (|u| + 1) • • • (m − 1)otherwise.This can be succinctly stated as:FW(P, n)[i] = FW(Q, n − m)[i mod m] if (i mod m) < n − m i mod motherwise.