Information Processing Letters 22 (1986) 125-131

North-Holland

3 March 1986

SQUARE-FREE W O R D S O N PARTIALLY C O M M U T A T I V E FREE M O N O I D S *
Arturo CARPI
Institute of Fundamental Mathematics, University of Rome, 00100 Rome, Italy

Aldo DE LUCA
Department of Applied Mathematics "'R. Caccioppoli", University of Napoli, Via Mezzocannone 8, 80134 Napoli, Italy
Communicated by L. Boasson
Received March 1985
Revised May 1985

We give a characterization of the partially commutative free monoids having an infinite number of square-free elements. We
prove that it is decidable whether a given partially commutative free monoid contains infinitely many square-free words.

Keywords: Square-free words, partially commutative free monoids

1. Introduction

Since the beginning of this century, many papers
have been devoted to the investigation of squarefree words. This problem has several applications
in various fields, such as game theory, symbolic
dynamics, group theory, and formal language theory.
The first work on this subject was due to Thue
[11] who proved that the set of square-free words
on an alphabet A is infinite, provided A contains
at least three letters.
In this article we are concerned with square-free
elements of partially commutative free monoids.
Roughly speaking, partially commutative free
monoids are obtained by considering words in
which only some pairs of letters can commute.
These objects have been studied for the first time
by Cartier and Foata [3] who used them in a
combinatorial problem. More recently, several
authors have been .interested in the study of ra* T h i s research was partially supported by the Italian Ministry
of Education.

tional subsets of partially commutative free monoids (cf., for instance, [2,4,5] and references therein).
The main result of this article is a characterization of the partially commutative free monoids
containing an infinite number of square-free elements. It shows that it is effectively decidable
whether a given partially commutative free monoid
contains infinitely many square-free words.

2. Preliminaries

Let A* be the free monoid generated by a finite
alphabet A. The length of a word w ~ A* is denoted by Iwl. A is the empty word and A += A * \
{ A } the free semigroup over A.
Let 0 _ A X A be a symmetric relation and the congruence in A* generated by the set of pairs
(ab, ba) such that (a, b) ~ 0. The quotient monoid
M(A, 0 ) = A * \ - is said to be the partially commutatioe free monoid on A (relatively to 0). The
canonical epimorphism of A* onto M(A, 0) is
denoted by ¢.
A word w ~ A* is square-free if it contains no

0020-0190/86/$3.50 © 1986, Elsevier Science Publishers B.V. (North-Holland)

125

(iv) There exist five distinct letters a. also 0-permutation-free.Volume 22. c). then w is simply called permutation-free. b)} a n d w---cabaca. equivalently. (iii) There exist four distinct letters a. c). a word w ~ A* is 0-permutation-free if w does not contain factors such as ff'. ) Proof. Similarly.. We recall that. 3. Conditions sufficient for the infiniteness of Lz(M(A.. a) ~ 0. it is a square-free element of M(A. We denote by Lz(M) the set of the square-free elements of a partially c o m m u t a t i v e free m o n o i d M = M(A. and f . Let A = (a. L 2 ( M ) is infinite).. t h e n L2(M(A. h ( a . d). the c o n g r u e n c e class ( m o d .i>~0). then w is a e-permutation-free wordofA*. 0)) We call inalterable (relatively to 0) any word (finite or infinite) which contains no factor of the f o r m ab with (a.an. Proposition 3.. . We use the notation a=a0al.is the congruence generated by the set of pairs (ab.. (a.cba2ca. (a. 0) is said to be square-free if it cannot be factorized as m = rs2t with s ~ 1. is square-free. 0). for any given symmetric relation 0 an A. with f . T h e following proposition gives sufficient conditions for the existence of an infinite inalterable square-free world. (c. (ai~A. (d. b). d ~ A such that (a. 0). b. is not true in general. Hence. It is clear that if w A* is such that the congruence class of w ( m o d . w is permutation-free and. 0). we define the image of a by setting Then there exists an infinite inalterable square-free word (and. b. b.hf 2k which is a contradiction. c ~ A such that (a. However. thus. a :g b. b ) ~ 0. from the concept of a O-permutation-free word of A* as i n t r o d u c e d in [8]. k ~ A*. 3 March 1986 A m o r p h i s m h : A* ~ B* is said to be square-free if h(w) is square-free for all the square-free words w ~ A*. (a. c.) is a square-free element of M(A. c). f. in fact. If f' can be any p e r m u t a t i o n of f (this occurs if 0 = A × A). (b. an element m ~ M(A. f' ~ A +. e ) ~ O. c. then all the 126 . b). the square-free elements of M(A.1. . If condition (i) is verified. Berstel [1] and C r o c h e m o r e [6] have given tests to decide whether a given morphism. (b. 0)) is infinite. b) ~ 0. 0) are the congruence classes (mod . if there exists an infinite inalterable square-free word). We say that an infinite word is square-free if all of its factors are square-free. then its congruence class (mod . A n infinite word on A is a function a : N ~ A.) of w is not a square-free element of M(A. d) ~ 0. where .) which contain only square-free words. . This is s h o w n by the following easy example. Otherwise. d). therefore. 0 = ((a. f' ~ A +. (c.) does not contain other words and. e A such that A factor of a is any word of the form a i a i + 1 • • • a i +j (i.f'. b). 0) is quite different from the n o t i o n of a permutation-free word of A* in the sense of Pleasants [10] or. b. b. c. d ~ A such that (a. (c. 0) be a partially commutative free monoid verifying one of the following conditions: (i) There exist three distinct letters a. therefore. m o r e general. 0) since cabaca . d. (d.f'. Number 3 INFORMATION PROCESSING LETTERS factor of the form uu with u 4: A.. b). It is w o r t h noting that the previous notion of a square-free element of M(A. c}. a ) ~ O. h. The converse of the preceding statement. (ii) There exist four distinct letters a. f. h(a) = h ( a 0 ) h ( a l ) . If w ~ A* is an inalterable square-free word. defined on a finite alphabet. c). ba) such that (a. however. If h is a m o r p h i s m defined on A*. Let M = M(A. This would imply w . w = hff'k.. In other words. (b. if there exist arbitrarily long square-free words of A* which are inalterable relatively to 0 (or. j >~ 0).

am+2n_l). The answer is. u E (b. and cd. one has x ~ (b. m 1 .am+2n=amUamUa 1 . 0). c. b. b. Then there exist two integers m >i 0 and n > 0 such that amain+ 1 . c. A less trivial e x a m p l e is the following. of course. c). in general. This is a contradiction since b is overlap-free. b. e } or am+ . 0). By deleting in v all the occurrences of a. be an infinite overlap-free word on the alphabet (b. then there exists a unique letter x such that sx is a factor of a.12] (cf. one has that am+ n_ l ~ (a. cd. O n e has n >/2 because a contains no factor xx with x ~ A. be the infinite word on the alphabet A defined by a 2 n ----. v ( b ) = ac. de. c}* --. b. moreover. . . cd. then there exists a unique letter y such that yr is a factor of a.d}*). ed. one easily verifies that the morphism ~. d}. positive. . ! a2n+l = if a2n = a2n+2 = if . ~ {a. c. b). if a2n = a2n+2 = d (n >~ 0). We conclude that a is an infinite inalterable square-free word. Let a = a 0 a l a 2 . . a2n 4= a2n+2 1 b. that is. ed}. In fact. and.b n . e}. c} are inalterable.: (a. b.(a) = ab. {a. ba. and d obtained f r o m t by inserting a letter d between adjacent a's and b's. .. C. d}* defined by ~. a m = a m {b. a contains the factor V-----amam+ (U = am+ 1. For instance. . and. One can ask oneself the question whether infinite square-free words exist which are not inalterable relatively to 0. 0)) is infinite. . as proved b y T h u e [11. an infinite word which contains no factor of the form xuxux with x ~ {b. c. W e observe that the same result can be obtained in a m o r e direct way by considering the sequence of D e a n [7] which is an infinite squarefree word over four letters a. dc. dc. de). We suppose am+n_ 1 {a. b. to an infinite square-free word on {a. . Let us n o w suppose that condition (iv) is verified. ~. moreover. a is inalterable.am+2n_ 1. bc. c. bc. c} by replacing the letter c with cd is not inalterable but such that all its finite factors are square-free elements of M(A. Such a w o r d exists. y ~ {b. . b. and d without the factors of length 2: ab. (c. therefore. in view of (B). d)}. b. de} d = adbcacbdadbcbdac . b. ba. By (A). [] Remark. . therefore. Since d is inalterable. d} and 0 = ((c. 0)) is infinite. d}.. if A = {a. an infinite inalterable square-free word can be obtained by applying ~. cb. and e one obtains a factor of b of the form VC=amUamUam (~E (b. Let us now suppose that condition (iii) is verified. . if t is the Thue-sequence LETTERS 3 March 1986 (B) If s ~ (ba. d}* be the morphism 127 . Hence. cb.am+n_ 1 = am+n+ + n = a m+ 2.V o l u m e 22. then the infinite w o r d obtained from an infinite square-free word on {a. e} (in the other case one can proceed symmetrically). suppose that a contains a square. Let b = b0blb 2 . c}* ~ {a. (1) t = abcacbabcbac . . d}. and c while d is the infinite square-free word over four letters a. dc. . d}*. if r ~ (ab.. d}. N o w let t be an infinite square-free word over three letters a.(c) = ad is square-free. b. d)} a n d 13: (a. and such that all their (finite) factors are square-free elements of M(A.am+n_ 1 = am+nam+n+ 1 • . . Let 0 = {(a. d}. For instance. By means of one of the algorithms given in [1] or in [6]. We now prove by reductio ad absurdum that a is square-free. N u m b e r 3 INFORMATION PROCESSING infinite square-free words over (a. . it follows that L2(M(A. Hence. also [9]). if condition (ii) is verified. Symmetrically. . In these cases. c. L2(M(A. c. Then by (1) and (A) one has then am+n_2am+n_ 1 = am+2n_2am+2n_ {ba. bc. dc. b. c. F r o m the definition of a one derives the following facts: (A) The only factors of length 2 of a are ab.

L2(Mn) .1 is verified (and. a n a n d a l a 2 . It is evident that the morphisms "rrA~: A * ~ (i = 1. Proposition 4. t. 2 . then M = M(A. a 2 . Hence. This proves the inclusion L2(M) G L 2 ( M 1 ) L 2 ( M 2 ) . and a k (1 ~< k ~< n) such that (ak. 128 . a . 0). one has k 4= 1 and k ~ n. is such that all its (finite) factors are square-free elements of M(A.rs 2 t. 0) be a partially commutative free monoid such that A=A1UA 2. s ~ A* such that 0 ( w l ) ~ L2(M1). 0)) In this section we shall prove that L 2 ( M ( A . where 0~ is the restriction of 0 to A~ ( i = 1. [] By iterated applications of the preceding proposition one obtains a decomposition L2(M(A. . and a k + 1. %. 0i) ( i = 1 . . It provides an effective procedure to decide whether L2(M(A. Proposition 4. . b) ff 0. therefore. condition (ii) of Proposition 3.1. from the hypothesis. 4. . c}. 2). Hence.l. b. If. 2).1 is satisfied. a2.1. .2. . Proof. If M i = O(A*) (i = 1. 0)) is infinite. By (2). m 1 and m 2 are square-free. Let us n o w s u p p o s e that the inverse inclusion does not hold true. i = 1. anb are not inalterable. a 2 . [3(b) = bcad. 2). . obviously. . 0) be a partially commutative free monoid such that no partition A = A1 L) A 2 exists with A1 × A 2 G O. W e state the following proposition. but this is a contradiction because s is nonempty.. [] W e are n o w able to prove o u r main result.' G 0. 0) is generated by M~ U M 2 and each element of M 1 commutes with the elements of M 2. .2). The following proposition concerns m o n o i d s of this kind.% . s :~ A and wlw2 -. . b. where M i = M ( A i . Since O(w 1) and O(w2) are square-free. then at least one of conditions (ii) or (iv) of Proposition 3. . I f Im I >/5. Then there exist w o r d s % ~ A~'. then let s = 13(O be the infinite sequence o b t a i n e d b y applying 13 to t. (aa. one has Wi = 'TrAi (WlW2) . then % . ( 0 ( % .1 is verified b y the letters a k. ( 0 M = M. a n }. . By the •maximality of n. w2 ~ A~. all m ~ L 2 ( M ) can be factorized as m = m l m 2 (m i ~ M i . A* are such that if u.. M 2" 3 March 1986 (i=1. ~(w2) ~ L2(M2). . r.n) are partially c o m m u t a t i v e free m o n o i d s such that there exists no partition A i = A~ U A'~' with A ' i X A. which is not inalterable relatively to 0. therefore. Number 3 INFORMATION PROCESSING LETTERS defined b y 13(a) = acbd. Hence.1[ is verified. on the contrary. A = A 1 u A 2 (A~ N A 2 =~0) such that each letter of A 1 c o m m u t e s with all the letters of A 2. . Let ala 2 . one derives ~rA. • .(v). 0~).%<i. 2) and. n ~< 4. Then one has L2(M ) = L2(M. } ) ~ 0 and therefore there exist b ~ A \ (a 1. v ~ A* and u . b a l a 2 . . L2(M ) is infinite).(s) = ¢rA~(S) = A.v. .Volume 22. Let there exist a partition of the alphabet A. Decidability for the infiniteness of L2(M(A. AI×A2___0. . one has (2) We remark that M i = M(A~. A ifa~Ai. If n >/5. a k . and. a n } x ( A \ ( a l . then condition (iii) of Proposition 3. ( u ) %. Let M = M(A. 2) defined b y 13(c) = abd.(a)= a ifa~Ai. O n e can prove that s. . Let M = M(A. . a n (a i~A.)L2(M2) . 0)) is infinite only when at least one of the conditions of Proposition 3.%<n) be an inalterable word of maximal length such that a~ aj for i :# j. where M i = 0 ( A * ) (i = 1. one has. . 0))=L2(M1)L2(M2). Proof. ( s ) ) 2 % . If t is the T h u e sequence over {a. Alf3A2=~.

(a) (b) In case (a). 0)) is infinite if and only if one of the following four conditions is satisfied: (i) There exist three distinct letters a. a manual verification of the finiteness of L2(M(A. R. b). [] Acknowledgment We wish to thank the anonymous referee for his (or her) useful suggestions. if rbcd ~ R. = R \ 0 . dcb}A*). Therefore. c). c. (c. Lz(M(A. 0)) is finite since there exists no square-free word of length larger than 3 over two letters. d)}. Let us define the following subsets of A*: R = qb-'(L2 ( M ( A . where s o = dacadbda for some g ~ A*.' 0 ( A * { a b c . Appendix A We want to show that if A = {a. c. s ~ A * . it is sufficient to prove that if none of these conditions is verified. 3 March 1986 Indeed there are only two cases in which all these requirements are verified. then by Proposition 3. d. (3) If abs ~ R1. one has L2(M(A. we suppose IAI > 2 and proceed by induction on IA I . (d. If one of the preceding four conditions is satisfied. d ~ A such that (a. (b. 129 . L2(Ma) and L2(M2) are both finite. abA* n R1. one derives from Proposition 4. (1) If a b c s ~ R . 1. d ~ A such that (a. 0)) is infinite. (b. ]r t >/ 12. e A such that (a.1 0 (A * {ab. Hence. If IAI < 2 . therefore. (2) no partition A = A 1 U A 2 exists with A~ × A2 __c0. d} and 0 = {(a. (c. c). A 2 =/:~) such that A 1 X A 2 c 0. s ~ A*. a) ff O. Such a partition does not exist. and. This verification is given in Appendix A. They can be derived from Figs. b. L2(M(A. c). to complete the proof. 0)) is finite. c). R 2 = R. 0)) contains a rather large number of elements. Number 3 INFORMATION PROCESSING LETTERS Proposition 4. then L2(M(A.s0dc g. b. b.1 one has that L2(M(A. There exists a partition A = A mU A 2 (AI. By the induction hypothesis.~cdadbdacada for some ~ c A*. d). 0)) is finite. b. L2(M(A. d) ff O. also L2(M(A. Case 1. c ~ A such that (a. which give the initial parts of the trees representing abcA* c3 R. These are illustrated by the following graphs (in which the nodes represent the letters of A and the arcs join the letters which can commute): (ii) There exist four distinct letters a.%<4. (c. then r .3. 0)) is finite. then L2(M(A.2 that ]A ] . c). 0)) is more elaborate.1. 0)) is finite. 0)) is finite.Volume 22. (a. (a. and 3. (iii) There exist four distinct letters a. 2. t sl >/12. one easily verifies that all the words of length larger than 7 are congruent (mod . The following facts only require some patience to be verified. (b. In case (b). (iv) There exist five distinct letters a. In Case 1. (b. then s . with the-notation of Proposition 4. L2(M(A. (d. r ~ A*. then L2(M(A. b). (2) Symmetrically. 0 ) ) = L 2 ( M a ) L 2 ( M 2 ) . (3) none of the conditions (i)-(iv) is verified. b). d). a) ff O. c. Hence. e)ff 0 Proof. therefore. and bA* n R 2. We distinguish two cases. c. b). Ist >7 12. since. b. then s dadbdacadab~ for some g ~ A*. in this case.) to some word containing a square and. b). it is sufficient to verify that whenever M(A. (c. 0))). 0) is a partially commutative free monoid such that: (1) 3 < I n l < 4 . In Case 2. cd}A*). Case 2. \ 0 .

O n e has w 1 = v2v3v4v5 E R 1.~ ( c d a d b d a c a d a b ) 2 g. If it were not true. o n e w o u l d h a v e w~ . s ~ A * . if d c r ~ R 1. (5) If b s ~ R 2. r ~ A*. abA* (~ R l.rabcs . if rb ~ R2. bA*~R 2. a~b Ib c a d / u a--a a d~a X o a tl --c a II c/a ~ c Fig. w h i c h is a c o n t r a d i c t i o n . (6) S y m m e t r i c a l l y . 2. [v3[ > 3. In fact. o n e w o u l d o t h e r w i s e derive w . dadbd}A*.b~ ~d a~d II bll Fig. Number 3 ~b a a/ %. then s~ {dacadb. Iv6[ = 12 d< c tl b/ / C~a ¢ II Iv21= [v41=8. s e A * .r 0 a b L w h e r e r o = a d b d a c a d for s o m e ~A*. T h e n o n e c a n f a c t o r i z e w as w = vlv2v3v4vsv6 with Iv 1 [ = 11. abcA* (~ R.. \b abe / d/ . b II d a/b-. F r o m (1) a n d (2) o n e w o u l d h a v e w .r a b c d a d b d a c a d a b ~ d b d~ . (4) S y m m e t r i c a l l y .INFORMATION PROCESSING LETTERS Volume 22.r d c b s f o r s o m e r. then r ~ A*{bdacad. 1.tabs or wl - . r ~ A*. 130 r. and Iv5[=42. t h e n r . L e t us n o w s u p p o s e t h a t R c o n t a i n s a w o r d w such that I w l > 84. 2b dc . Isl>~8.. a c __ a ~ d/ ~ b c -. Ir l >/ 12.r a b c s or w .. W e shall c o n s i d e r h e r e o n l y the first case since the s e c o n d o n e can b e d e a l t with in an a n a l o g o u s way. dbdad}. s ~ A* such that Jr I >/ Iv1 ] = 11 a n d Is I >i Iv6 I = 12. d~bll Fig.Ull a b ~e X c 3 March 1986 . ~ b all e all II b. 3.. [r I >i 8. a H . L e t us n o w s h o w that w: = v2v3v4 ~ R a.

dcs' ~ R~. M.l . Berlin. One arrives at a similar c o n t r a d i c t i o n w h e n w~ tdcs with Is I >~ 42. therefore. Cambridge Phil.roabr'. Crochemore. 3 March 1986 References [1] J. (dbda)2cadb. Foata. [s'[ >~ 12. b d a c ( a d b d ) 2. A sequence without repeats on x. tabs. [4] R.R. G. [3] P. Hence. therefore. 18 (1982) 221-226. 1984. in: Lecture Notes in Computer Science 71 (Springer. Uber die gegenseitige Lage gleicher Teile gewisser Zeichenreihen. Encyclopedia of Mathematics and its Applications 17 (Addison-Wesley. Berstel. Perrin. IN I >/32. [6] M. Comput. W e c o n c l u d e that R is finite and. 1969). d }*. 1979) 16-25. [8] M. Selsk. in view of (5) and (6). Pleasants. RAIRO I. r'~ h*. then by (3) a n d (4) o n e obtains If w 1 - s . [12] A. Sur la reconnaissabilit~ dans les monoides partiellement commutatifs libres. Norske Vid.. Nonrepetitive sequences. Bertoni. KI. Proc. Theoret. 68 (1970) 267-274. s ~ A*. to appear. 1984. Thue.R. g ~ A*. Lothaire. Thue. Ir [ >~ 22. which is a contradiction. [9] M. 8418. de Bordeaux 1. 0)) is finite. Cartier and D. [11] A. w 2 w o u l d c o n t a i n o n e of the factors (bdacad)2b. Sharp characterization of square-free morphisms. Lecture Notes in Mathematics 85 (Springer. Norske Vid. U. Combinatorics on Words. Probl~mes Combinatoires de Commutation et Rdarrangements. In fact. An application of the theory of free partially commutative monoids: Asymptotic densities of trace languages. Univ. Metivier. Monthly 72 (1965) 383-385. Math. Mots infinis sans carr6 partiellement abrliens sur trois lettres. Brambilla. 1983). Moreover. MA.T. Sci. 131 . Sur les mots sans carr~ drfinis par un morphisme. x . 1. ? E A*. 198t) 205-215. Cori and Y. Skr.roab? .19. Is[ ~ IvsI = 4 2 .R. Preprint No. Berlin. Christiania 7 (1906) 1-22. Rational subsets of some partially abelian monoids. dc~ ~ R ] . This yields the c o n t r a d i c t i o n w 2 .sodcs. [5] R. v3 ~ { a. Sabadini. also L2(M(A. By the s y m m e t r y of 0.E. Skr. . ab? ~ R~. Mauri and N. s ' . Amer. de Bordeaux 1. Christiania 1 (1912) 1-67. o n e also has v3 ff A ' c A * and. Mat. 84. [7] R. (dbda)2dbd. de Mathrmatiques et Informatique. Ober unendliche Zeichenreihen. Nat. s A* with I r I. Nat. [10] P. Preprint No.sodcs'. one would otherwise have w 2 = rbs for some r. Reading. Berlin. K1. Dean.Volume 22. I.t(abs0dcr 0)2abr'. This is a c o n t r a d i c t i o n because v 3 is square-free a n d there exists n o square-free w o r d of length larger t h a n 3 on a two-letter alphabet. Univ. [2] A. de Mathrmatiques et Informatique. Formisano.E. Soc. y. s' E A*. Mat. Number 3 I N F O R M A T I O N PROCESSING LETTERS tdcs f o r s o m e t. Selsk. in: Lecture Notes in Computer Science 118 (Springer. one has that v3 ff A * b A * . I s I >/ Iv2 I = Iv41 = 8. v 1. U. g . Cori and D.