Theoretical Computer Science 340 (2005) 179 – 185 www.elsevier.com/locate/tcs
Preface A good friend, a good companion, a brilliant research partner, an enemy of any redundance and useless diversions, restless in tackling scientific problems, an enthusiastic follower of research by his colleagues, a person that people around him can rely on. These are only some qualities of Antonio Restivo that we (the editors, with very different backgrounds) have come up with. These qualities supported him throughout his research career that began when he was a young theoretical physicist at the “Istituto di Cibernetica” (IC), Arco Felice, Naples, where he provided for his own Copernican revolution by moving to Theoretical Computer Science. Fundamental for this decision was meeting the research team of the Istituto of Cibernetica, directed by E.R. Caianiello, and especially the meeting with Professor M.P. Schützenberger—Antonio was very impressed by the way that they approached research problems and by the respect that they had for competence and hard work. The following lines from Divina Commedia by Dante, an author often quoted by Professor Schützenberger, have become a sort of common inheritance of the research team of IC, since they can be seen as a link between scientific discoveries and the truth. Vie più che ’ndarno da riva si parte, perché non torna tal qual è si move, chi pesca per lo vero e non ha l’arte. 1 (Dante Alighieri, Divina Commedia, Paradiso, Canto XIII, Lines 121–123) The art of research is the ability of going straight into the heart of problems, whenever you believe that this is the right direction, even if going this way implies a high cost and even if it means going against the general opinion. But, it is also a “complementary” ability of detecting and hence avoiding false avenues of research. These abilities as well as the ability of asking the right questions in order to generate new ones, have led him to many relationships of genuine scientific cooperation with researchers all over the world, in a sort of successful globalization of scientific research. This special issue is a testimony to the positive influence that Antonio Restivo had and still has on his fellow researchers. Many papers in this issue contain clear traces of his influence.
1 It is even worse than vain to go off shore for one who wants to find the truth but hasn’t got the art, since he’ll come back not as he was before.
0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.019
180
Preface / Theoretical Computer Science 340 (2005) 179 – 185
His influence extends beyond individual researchers into whole research institutes. Some of them are particularly dear to Antonio’s heart—these are places where he worked or currently works, and where some of his dearest friends and students are still working: Palermo, Napoli, Paris—just to mention some of them. These are the places where he spent years of his own formation, and with which he still cooperates sharing his vast knowledge and the enthusiasm for research. We conclude by quoting Leonardo da Vinci’s words—this is a statement that Antonio wanted to be included on the website for students in a lecture in computer science at Palermo University; he thinks that this quotation encapsulates the fundamental meaning of research. Quelli che s’innamoran di pratica senza scienza, son come ’l nocchiere, ch’entra in naviglio senza timone o bussola, che mai ha certezza dove si vada. 2 (Leonardo da Vinci) To Antonio Restivo, a master of Theoretical Informatics, on the occasion of his 60th birthday. A. de Luca, F. Mignosi, D. Perrin, G. Rozenberg Leiden University, Leiden Institute of Advanced Computer Science, Niels Bohrweg 1, Leiden 2333 CA, Netherlands E-mail address:
[email protected] Publications by Antonio Restivo [1] R. Ascoli, G. Epifanio, A. Restivo, On the mathematical description of quantized fields, Comm. Math. Phys. 18 (1970) 291–300. [2] A. Restivo, Codes and aperiodic languages, in: K.-H. Böhling, K. Indermark (Eds.), Automatentheorie und Formale Sprachen, Lecture Notes in Computer Science, Vol. 2, Springer, Berlin, 1973, pp. 175–181. [3] R. Ascoli, G. Epifanio, A. Restivo, *-Algebrae of unbounded operators in scalarproduct spaces, Riv. Mat. Univ. Parma, 3 (1974) 1–12. [4] A. Restivo, S. Termini, An algorithm for deciding whether a strictly locally testable submonoid is free, Cahiers Math. Université de Montpellier, Vol. 3, 1974, pp. 299–303. [5] A. Restivo, On a question of McNaughton and Papert, Inform. Control 25(1) (1974) 93–101. [6] A. Restivo, A combinatorial property of codes having finite synchronization delay, Theoret. Comput. Sci. 1(2) (1975) 95–101.
2 Those who fall in love with Practice without Theory are like the seaman on a boat without a steering wheel or a compass, who is never sure where he’ll land.
Preface / Theoretical Computer Science 340 (2005) 179 – 185
181
[7] A. Restivo, A characterization of bounded regular sets, in: H. Barkhage (Ed.), Automata Theory and Formal Languages, Lecture Notes in Computer Science, Vol. 33, Springer, Berlin, 1975, pp. 239–244. [8] A. Restivo, S. Termini, On a family of rational languages, in: E. Caianiello (Ed.), New Concepts and Technologies in Parallel Information Processing, Nato Advanced Study Institutes Series, Series E, Noordhoff, Leyden, 1975, pp. 349–357. [9] A. Restivo, On a family of codes related to factorization of cyclotomic polynomials, in: S. Michaelson, R. Milner (Eds.), ICALP, Edinburgh University Press, 1976, pp. 38–44. [10] L. Boasson, A. Restivo, Une caractérisation des langages algébriques bornés, ITA 11(3) (1977) 203–205. [11] A. Restivo, Mots sans répétitions et langages rationnels bornés, ITA 11(3) (1977) 197–202. [12] A. Restivo, On codes having no finite completions, Discrete Math. 17(3) (1977) 309–316. [13] A. Restivo, Some decision results for recognizable sets in arbitrary monoids, in: G. Ausiello, C. Böhm (Eds.), ICALP, Lecture Notes in Computer Science, Vol. 62, Springer, Berlin, 1978, pp. 363–371. [14] A. de Luca, A. Restivo, Synchronization and maximality for very pure subsemigroups of a free semigroup, in: J. Becvár (Ed.), MFCS, Lecture Notes in Computer Science, Vol. 74, Springer, Berlin, 1979, pp. 363–371. [15] J. Berstel, D. Perrin, J.F. Perrot, A. Restivo, Sur le théorème du defaut, J. Algebra 60 (1979) 169–180. [16] A. de Luca, D. Perrin, A. Restivo, S. Termini, Synchronization and simplification, Discrete Math. 27 (1979) 287–308. [17] J.-M. Boë, A. de Luca, A. Restivo, Minimal complete sets of words, Theoret. Comput. Sci. 12 (1980) 325–332. [18] A. de Luca, A. Restivo, On some properties of very pure codes, Theoret. Comput. Sci. 10 (1980) 157–170. [19] A. de Luca, A. Restivo, A characterization of strictly locally testable languages and its applications to subsemigroups of a free semigroup, Inform. Control 44(3) (1980) 300–319. [20] A. de Luca, A. Restivo, On some properties of local testability, in: J.W. de Bakker, J. van Leeuwen (Eds.), ICALP, Lecture Notes in Computer Science, Vol. 85, Springer, Berlin, 1980, pp. 385–393. [21] S. Mauceri, A. Restivo, A family of codes commutatively equivalent to prefix codes, Inform. Process. Lett. 12(1) (1981) 1–4. [22] A. Restivo, Some remarks on complete subsets of a free monoid, 1981, pp. 19–25. [23] A. de Luca, A. Restivo, A synchronization property of pure subsemigroups of a free semigroup, 1981, pp. 233–240. [24] A. de Luca, A. Restivo, S. Salemi, On the centers of a language, Theoret. Comput. Sci. 24 (1983) 21–34. [25] A. Restivo, C. Reutenauer, Some applications of a theorem of Shirshov to language theory, Inform. Control 57(2/3) (1983) 205–213. [26] A. Restivo, S. Salemi, On weakly square free words, Bull. EATCS 21 (1983) 49–57.
182
Preface / Theoretical Computer Science 340 (2005) 179 – 185
[27] A. Restivo, C. Reutenauer, On cancellation properties of languages which are supports of ration power series, J. Comput. System Sci. 29(2) (1984) 153–159. [28] A. de Luca, A. Restivo, A finiteness condition for finitely generated semigroups, Semigroup Forum 28(1–3) (1984) 123–134. [29] A. Restivo, C. Reutenauer, On the Burnside problem for semigroups, J. Algebra 89(1) (1984) 102–104. [30] A. de Luca, A. Restivo, Representations of integers and language theory, in: M. Chytil, V. Koubek (Eds.), MFCS, Lecture Notes in Computer Science, Vol. 176, Springer, Berlin, 1984, pp. 407–415. [31] A. Restivo, C. Reutenauer, Cancellation, pumping and permutation in formal languages, in: J. Paredaens (Ed.), ICALP, Lecture Notes in Computer Science, Vol. 172, Springer, Berlin, 1984, pp. 414–422. [32] A. Restivo, S. Salemi, Overlap-free words on two symbols, in: M. Nivat, D. Perrin (Eds.), Automata on Infinite Words, Lecture Notes in Computer Science, Vol. 192, Springer, Berlin, 1984, pp. 198–206. [33] A. Restivo, Rational languages and the Burnside problem, Theoret. Comput. Sci. 40 (1985) 13–30. [34] C. de Felice, A. Restivo, Some results on finite maximal codes, ITA 19(4) (1985) 383–403. [35] A. Restivo, S. Salemi, Some decision results on nonrepetitive words, Series. F, Vol. 12, NATO Adv. Sci. Inst., Springer, Berlin, 1985, pp. 289–295. [36] A. de Luca, A. Restivo, Star-free sets of integers, Theoret. Comput. Sci. 43 (1986) 265–275. [37] A. de Luca, A. Restivo, On a generalization of a conjecture of Ehrenfeucht, Bull. EATCS 30 (1986) 84–90. [38] A. Restivo, Codes and automata, in: J.-E. Pin (Ed.), Formal Properties of Finite Automata and Applications, Lecture Notes in Computer Science, Vol. 386, Springer, Berlin, 1988, pp. 186–198. [39] A. Restivo, Permutation properties and the Fibonacci semigroup, Semigroup Forum 38(3) (1989) 337–345. [40] A. Restivo, Finitely generated sofic systems, Theoret. Comput. Sci. 65(2) (1989) 265–270. [41] A. Restivo, S. Salemi, T. Sportelli, Completing codes, ITA 23(2) (1989) 135–147. [42] A. Restivo, A note on multiset decipherable codes, IEEE Transactions on Information Theory 35(3) (1989) 662. [43] A. Restivo, Coding sequences with constraints, in: R. Capocelli (Ed.), Sequences, Springer, New York, 1990, pp. 530–540. [44] A. Restivo, Codes and local constraints, Theoret. Comput. Sci. 72(1) (1990) 55–64. [45] A. Restivo, Codes with constraint, in: M.P. Schutzenberger, M. Lothaire (Eds.), Mots, Langue, raisonnement, calcul, Hermes, 1990, pp. 358–366. [46] G. Guaiana, A. Restivo, S. Salemi, Complete subgraphs of bipartite graphs and applications to trace languages, ITA 24 (1990) 409–418. [47] G. Guaiana, A. Restivo, S. Salemi, On aperiodic trace languages, in: C. Choffrut, M. Jantzen (Eds.), STACS, Lecture Notes in Computer Science, Vol. 480, Springer, Berlin, 1991, pp. 76–88.
Preface / Theoretical Computer Science 340 (2005) 179 – 185
183
[48] G. Guaiana, A. Restivo, S. Salemi, Star-free trace languages, Theoret. Comput. Sci. 97(2) (1992) 301–311. [49] A. Restivo, A note on renewal systems, Theoret. Comput. Sci. 94(2) (1992) 367–371. [50] D. Giammarresi, A. Restivo, Recognizable picture languages, IJPRAI 6(2,3) (1992) 241–256. [51] R. Montalbano, A. Restivo, The star height one problem for irreducible automata, in: R. Capocelli et al. (Eds.), Sequences II, Springer, New York, 1993, pp. 457–469. [52] D. Giammarresi, A. Restivo, S. Seibert, W. Thomas, Monadic second-order logic over pictures and recognizability by tiling systems, in: P. Enjalbert, E.W. Mayr, K.W. Wagner (Eds.), STACS, Lecture Notes in Computer Science, Vol. 775, Springer, Berlin, 1994, pp. 365–375. [53] R. Montalbano, A. Restivo, Antonio on the star height of rational languages, Internat. J. Algebra Comput. 4(3) (1994) 427–441. [54] D. Giammarresi, S. Mantaci, F. Mignosi, A. Restivo, A periodicity theorem for trees, in: B. Pehrson, I. Simon (Eds.), Technology and Foundations—Information Processing ’94, Volume 1, Proceedings of the IFIP 13th World Computer Congress Hamburg, Germany, 28 August–2 September, 1994. North-Holland, Amsterdam, 1994, pp. 473–478. [55] M. Anselmo, A. Restivo, Factorizing languages, in: B. Pehrson, I. Simon (Eds.), Technology and Foundations—Information Processing ’94, Volume 1, Proceedings of the IFIP 13th World Computer Congress Hamburg, Germany, 28 August–2 September, 1994. North-Holland, Amsterdam, 1994, pp. 445–450. [56] F. Mignosi, A. Restivo, S. Salemi, A periodicity theorem on words and applications, in: J. Wiedermann, P. Hájek (Eds.), MFCS, Lecture Notes in Computer Science, Vol. 969, Springer, Berlin, 1995, pp. 337–348. [57] D. Giammarresi, A. Restivo, S. Seibert, W. Thomas, Monadic second-order logic over rectangular pictures and recognizability by tiling systems, Inform. Comput. 125(1) (1996) 32–45. [58] D. Giammarresi, A. Restivo, Two-dimensional finite state recognizability, Fund. Inform. 25(3) (1996) 399–422. [59] M. Anselmo, A. Restivo, On languages factorizing the free monoid, Internat. J. Algebra Comput. 6(4) (1996) 413–427. [60] M.-P. Béal, F. Mignosi, A. Restivo, Minimal forbidden words and symbolic dynamics, in: C. Puech, R. Reischuk (Eds.), STACS, Lecture Notes in Computer Science, Vol. 1046, Springer, Berlin, 1996, pp. 555–566. [61] D. Giammarresi, S. Mantaci, F. Mignosi, A. Restivo, Congruences, automata and periodicities, in: J. Almeida, P.V. Silva, G.M.S. Gomes (Eds.), Semigroups, Automata and Languages, World Scientific, River Edge, NJ, 1996, pp. 125–135. [62] S. Mantaci, A. Restivo, Equations on trees, in: W. Penczek, A. Szalas (Eds.), MFCS, Lecture Notes in Computer Science, Vol. 1113, Springer, Berlin, 1996, pp. 443–456. [63] M. Anselmo, C. De Felice, A. Restivo, On some factorization problems, Bull. Belg. Math. Soc. Simon Stevin 4(1) (1997) 25–43. [64] D. Giammarresi, A. Restivo, Two-dimensional languages, in: G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages, Vol. 3, Springer, Berlin, 1997, pp. 215–267.
184
Preface / Theoretical Computer Science 340 (2005) 179 – 185
[65] D. Giammarresi, S. Mantaci, F. Mignosi, A. Restivo, Periodicities on trees, Theoret. Comput. Sci. 205(1–2) (1998) 145–181. [66] F. Mignosi, A. Restivo, S. Salemi, Periodicity and the golden ratio, Theoret. Comput. Sci. 204(1–2) (1998) 153–167. [67] M. Crochemore, F. Mignosi, A. Restivo, Automata and forbidden words, Inform. Process. Lett. 67(3) (1998) 111–117. [68] M. Crochemore, F. Mignosi, A. Restivo, Minimal forbidden words and factor automata, in: L. Brim, J. Gruska, J. Zlatuska (Eds.), MFCS, Lecture Notes in Computer Science, Vol. 1450, Springer, Berlin, 1998, pp. 665–673. [69] M.G. Castelli, F. Mignosi, A. Restivo, Fine and Wilf’s theorem for three periods and a generalization of Sturmian words, Theoret. Comput. Sci. 218(1) (1999) 83–94. [70] F. Mignosi, A. Restivo, On negative informations in language theory, Aust. Comput. Sci. Commun. 21(3) (1999) 60–72. [71] S. Mantaci, A. Restivo, On the defect theorem for trees, Publ. Math. Debrecen 54 (1999) 923–932. [72] D. Giammarresi, A. Restivo, Extending formal language hierarchies to higher dimensions, ACM Comput. Surv. 31(3es) (1999) 12. [73] F. Mignosi, A. Restivo, M. Sciortino, Forbidden factors in finite and infinite words, in: J. Karhumäki, H.A. Maurer, G. Paun, G. Rozenberg (Eds.), Jewels are Forever, Springer, Berlin, 1999, pp. 339–350. [74] M. Crochemore, F. Mignosi, A. Restivo, S. Salemi, Text compression using antidictionaries, in: J. Wiedermann, P. van Emde Boas, M. Nielsen (Eds.), ICALP Lecture Notes in Computer Science, Vol. 1644, Springer, Berlin, pp. 261–270. [75] M.-P. Béal, F. Mignosi, A. Restivo, M. Sciortino, Forbidden words in symbolic dynamics, Adv. Appl. Math. 25(2) (2000) 163–193. [76] J.-P. Duval, F. Mignosi, A. Restivo, Recurrence and periodicity in infinite words from local periods, Theoret. Comput. Sci. 262(1) (2001) 269–284. [77] S. Mantaci, A. Restivo, Codes and equations on trees, Theoret. Comput. Sci. 255(1–2) (2001) 483–509. [78] F. Mignosi, A. Restivo, M. Sciortino, Forbidden factors and fragment assembly, ITA, 35(6) (2001) 565–577. [79] F. Mignosi, A. Restivo, M. Sciortino, Forbidden factors and fragment assembly, in: W. Kuich, G. Rozenberg, A. Salomaa (Eds.), Developments in Language Theory 2001, Lecture Notes in Computer Science, Vol. 2295, Springer, Berlin, 2002, pp. 349–358. [80] A. Restivo, S. Salemi, Words and patterns, in: Developments in Language Theory 2001, Lecture Notes in Computer Science, Vol. 2295, Springer, Berlin, 2002, pp. 117–129. [81] A. Restivo, S.R. Della Rocca, L. Roversi (Eds.), Theoret. Comput. Sci. Proceedings of the Seventh Italian Conference, ICTCS 2001, Torino, Italy, 4–6 October, 2001, Lecture Notes in Computer Science, Vol. 2202, Springer, Berlin, 2001. [82] A. Restivo, P.V. Silva, On the lattice of prefix codes, Theoret. Comput. Sci. 289(1) (2002) 755–782. [83] F. Mignosi, A. Restivo, M. Sciortino, Words and forbidden factors, Theoret. Comput. Sci. 273(1–2) (2002) 99–117. [84] F. Mignosi, A. Restivo, Vol. 90, Chapter Periodicity, in: M. Lothaire (Ed.), Algebraic Combinatorics on Words, Cambridge University Press, Cambridge, 2002.
Preface / Theoretical Computer Science 340 (2005) 179 – 185
185
[85] A. Restivo, S. Salemi, Binary patterns in infinite binary words, in: W. Brauer, H. Ehrig, J. Karhumäki, A. Salomaa (Eds.), Formal and Natural Computing, Lecture Notes in Computer Science, Vol. 2300, Springer, Berlin, 2002, pp. 107–118. [86] F. Mignosi, A. Restivo, P.V. Silva, On Fine and Wilf’s theorem for bidimensional words, Theoret. Comput. Sci. 292(1) (2003) 245–262. [87] M.-P. Béal, M. Crochemore, F. Mignosi,A. Restivo, M. Sciortino, Computing forbidden words of regular languages, Fund. Inform. 56(1–2) (2003) 121–135. [88] S. Mantaci, A. Restivo, M. Sciortino, Burrows-Wheeler transform and Sturmian words, Inform. Process. Lett. 86(5) (2003) 241–246. [89] A. Restivo, P.V. Silva, Periodicity vectors for labelled trees, Discrete Appl. Math. 126(2–3) (2003) 241–260. [90] A. Gabriele, F. Mignosi, A. Restivo, M. Sciortino, Indexing structures for approximate string matching. in: R. Petreschi, G. Persiano, R. Silvestri (Eds.), CIAC, Lecture Notes in Computer Science, Vol. 2653, Springer, Berlin, 2003, pp. 140–151. [91] G. Castiglione, A. Restivo, Reconstruction of I-convex polyominoes, Electron. Notes in Discrete Math. 12 (2003). [92] G. Guaiana, A. Restivo, S. Salemi, On the trace product and some families of languages closed under partial commutations, J. Automat. Lang. Comb. 9(1) (2004) 61–79. [93] G. Castiglione, A. Restivo, S. Salemi, Patterns in words and languages, Discrete Appl. Math. 144(3) (2004) 237–246. [94] G. Castiglione, A. Restivo, Ordering and convex polyominoes, in: M. Margenstern (Ed.), MCU 2004, Lecture Notes in Computer Science, Vol. 3354, Springer, Berlin, 2004. [95] F. Burderi, A. Restivo, Varieties of codes and Kraft inequality, in: V. Diekert, B. Durand (Eds.), STACS 2005, Lecture Notes in Computer Science, Vol. 3404, Springer, Berlin, 2005.
Theoretical Computer Science 340 (2005) 186 – 187 www.elsevier.com/locate/tcs
Editorial
From Antonio’s former students It was December 2004: Antonio’s 60th birthday was approaching and we, as his former students, were wishing very much to dedicate him one page in this volume. Hence, during the Christmas’ holidays, we planned a top secret reunion at the Department of Mathematics in Palermo. We all agreed on one thing: we wished to contribute with a special preface, that would focus on some of Antonio’s aspects that only we, his students, are probably fortunate enough to know. We wished to tell about his kind attitude that cannot be separated from his outstanding scientific profile. Perhaps this is what makes Antonio a “milestone” for us (this is incredible... Everyone used the same term to “define” him!): Antonio looks at everybody in front of him with extreme attention to the person and to all his aspects and qualities. This is the way Antonio himself uses to tell us about his “maestro” and friend M.P. Schützenberger or about his best times at the Istituto di Cibernetica in Arco Felice, telling us many funny stories with his peculiar sense of humor and acting capabilities. We all feel that being his students is a great privilege. But, how can we tell people about all the times that Antonio surprises us and provides us with renewed enthusiasm for our research? We all remember the many times when some of us got stuck on a research problem and Antonio would say: “There should be something on this subject in some LITP technical report back in 1987”. Then he looked at several stacks of papers on his desk or his shelves and said: “It should be in this stack”. Then, he started going through this stack of papers and magically took one paper out of it: needless to say, it contained exactly the solution to the problem! Or when, in the biology laboratories, looking at shelves displaying jars with strange insects, seeds or leaves preserved with formalin, we felt a bit uncomfortable with our theorems and counterexamples. Then Antonio used to say: “We should put our examples in a jar, with some labels like Example of language with property X or Thue-Morse word, disproving conjecture Y, so as to find them when needed!”. Finally, when the top secret meeting in that December afternoon in Palermo was over, we realized that we had spent most of the time just telling each other our respective nice memories and stories about working with Antonio. We all really had a great time, but we were still left with the problem of writing all those memories in a way that would be really suited to Antonio... Indeed, he does not like “commemorations” at all.
0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.023
Editorial / Theoretical Computer Science 340 (2005) 186 – 187
187
After a while, we all agreed that the best thing would be to write in the simplest way what we all felt: Many thanks Antonio for everything and our hearty wishes for your birthday!!! Marcella Anselmo Marina Madonia Giuseppina Rindone
Dora Giammarresi Sabrina Mantaci Marinella Sciortino
Giovanna Guaiana Filippo Mignosi
Theoretical Computer Science 340 (2005) 188 – 203 www.elsevier.com/locate/tcs
Connections between subwords and certain matrix mappings夡 Arto Salomaa Turku Centre for Computer Science, Academy of Finland, Lemminkäisenkatu 14, 20520 Turku, Finland
Abstract Parikh matrices recently introduced have turned out to be a powerful tool in the arithmetizing of the theory of words. In particular, many inequalities between (scattered) subword occurrences have been obtained as consequences of the properties of the matrices. This paper continues the investigation of Parikh matrices and subword occurrences. In particular, we study certain inequalities, as well as information about subword occurrences sufficient to determine the whole word uniquely. Some algebraic considerations, facts about forbidden subwords, as well as some open problems are also included. © 2005 Elsevier B.V. All rights reserved. Keywords: Parikh matrix; Subword; Scattered subword; Number of subwords; Inference from subsequences; Forbidden subword
1. Introduction The purpose of this paper is to investigate the number of occurrences of a word u as a subword in a word w, in symbols, |w|u . For us the term subword means that w, as a sequence of letters, contains u as a subsequence. More formally, we begin with the following fundamental 夡 The paper is dedicated to Antonio Restivo on the occasion of his 60th birthday. I have been fortunate to meet Antonio every now and then through many decades. I have always found him as a young colleague and friend with very bright ideas. Antonio has also been involved in successful cooperation with the Turku research group. I wish him all the best in the years to come both in science and life. E-mail address: asalomaa@utu.fi.
0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.024
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
189
Definition 1. A word u is a subword of a word w if there exist words x1 , . . . , xn and y0 , . . . , yn , some of them possibly empty, such that u = x1 . . . xn
and
w = y0 x1 y1 . . . xn yn .
The word u is a factor of w if there are words x and y such that w = xuy. If the word x (resp. y) is empty, then u is also called a prefix (resp. suffix) of w. Throughout this paper, we understand subwords and factors in this way. In classical language theory, [13], our subwords are usually called “scattered subwords”, whereas our factors are called “subwords”. The notation used throughout the article is |w|u , the number of occurrences of the word u as a subword of the word w. Two occurrences are considered different if they differ by at least one position of some letter. (Formally an occurrence can be viewed as a vector of length |u| whose components indicate the positions of the different letters of u in w.) Clearly, |w|u = 0 if |w| < |u|. We also make the convention that, for any w and the empty word , |w| = 1. In [14] the number |w|u is denoted as a “binomial coefficient” w |w|u = . u If w and u are words over a one-letter alphabet, w = ai ,
u = aj ,
then |w|u equals the ordinary binomial coefficient: |w|u = ji . Our convention concerning the empty word reduces to the fact that 0i = 1. (The convention is made also in [3,14].) Assume that is an alphabet containing the letters a and b. A little reflection shows that, for any word w, (|w|a ) × (|w|b ) = |w|ab + |w|ba . This simple equation can be viewed as a general fact about occurrences of subwords. It is also an instance about the linearization of subword histories investigated in [10]. A slight variation of the equation immediately leads to difficulties. No explicit characterization is known for the relation between (|w|u , |w|v ) and (|w|uv , |w|vu ), where u, v, w are arbitrary words. (In general, we use small letters from the beginning of the English alphabet to denote letters of the formal alphabet.) A general problem along these lines is the following. What numbers |w|u suffice to determine the word w uniquely? For instance, a word w ∈ {a, b}∗ is uniquely determined by the values |w|a = |w|b = 4, |w|ab = 15.
190
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
Indeed, w = a 3 bab3 . On the other hand, a word w ∈ {a, b}∗ of length 4 is not uniquely determined by the values |w|u , |u| 2. Either one of the words abba and baab can be chosen as w, and still the equations |w|a = |w|b = |w|ab = |w|ba = 2, |w|aa = |w|bb = 1 are satisfied. A powerful tool for such problems is the notion of a Parikh matrix. The rest of this paper deals with this notion. The Parikh matrix associated to a word w tells the numbers |w|u for certain specific words u. The original notion of a Parikh matrix was introduced in [9]. When dealing with the extended notion, [17], one has more leeway in the choice of the words u.
2. Parikh matrices Parikh mappings (vectors) introduced in [12] express properties of words as numerical properties of vectors yielding some fundamental language-theoretic consequences, [13,5]. Much information is lost in the transition from a word to a vector. A sharpening of the Parikh mapping, where more information is preserved than in the original Parikh mapping, was introduced in [9]. The new mapping uses upper triangular square matrices, with nonnegative integer entries, 1’s on the main diagonal and 0’s below it. Two words with the same Parikh matrix always have the same Parikh vector, but two words with the same Parikh vector have in general different Parikh matrices. Thus, the Parikh matrix gives more information about a word than a Parikh vector. The set of all triangular matrices described above is denoted by M, and the subset of all matrices of dimension k 1 is denoted by Mk . We are now ready to introduce the original notion of a Parikh matrix mapping. Definition 2. Let = {a1 , . . . , ak } be an alphabet. The Parikh matrix mapping, denoted k , is the morphism:
k : ∗ → Mk+1 , defined by the condition: if k (aq ) = (mi,j )1 i,j (k+1) , then for each 1 i (k + 1), mi,i = 1, mq,q+1 = 1, all other elements of the matrix k (aq ) being 0. Observe that when defining the Parikh matrix mapping we have, similarly as when defining the Parikh vector, in mind a specific ordering of the alphabet. Knowledge of the Parikh matrices for different orderings of the alphabet will increase our knowledge of the word in question. If we consider letters without numerical indices, we assume the alphabetic ordering in the definition of Parikh matrices. The Parikh matrix mapping is not injective even for the alphabet {a, b}. For instance, consider the matrices 1 4 6 1 5 8 0 1 3 and 0 1 3 . 0 0 1 0 0 1
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
191
Then the five words baabaab, baaabba, abbaaab, abababa, aabbbaa are exactly the ones having the first matrix as the Parikh matrix. Similarly, the six words aababbaa, aabbaaba, abaababa, baaaabba, ababaaab, baaabaab are exactly the ones having the second matrix as the Parikh matrix. This example becomes clearer in view of the following theorem, [9], where the entries of the Parikh matrix are characterized. For the alphabet = {a1 , . . . , ak }, we denote by ai,j the word ai ai+1 . . . aj , where 1 i j k. Theorem 1. Consider = {a1 , . . . , ak } and w ∈ ∗ . The matrix k (w) = (mi,j )1 i,j (k+1) , has the following properties: • mi,j = 0, for all 1 j < i (k + 1), • mi,i = 1, for all 1 i (k + 1), • mi,j +1 = |w|ai,j , for all 1 i j k. By the second diagonal (and similarly the third diagonal, etc.) of a matrix in Mk+1 , we mean the diagonal of length k immediately above the main diagonal. (The diagonals from the third on are shorter.) Theorem 1 tells that the second diagonal of the Parikh matrix of w gives the Parikh vector of w. The next diagonals give information about the order of letters in w by indicating the numbers |w|u for certain specific words u. Properties of Parikh matrices, notably the unambiguity of Parikh matrix mappings, have been investigated in [4,7–10,15,16]. For any word w over the alphabet {a, b, c, d}, Theorem 1 implies that 1 |w|a |w|ab |w|abc |w|abcd 0 1 |w|b |w|bc |w|bcd 0 0 1 |w|c |w|cd 4 (w) = . 0 0 0 1 |w|d 0 0 0 0 1 The problem of deciding whether or not a given matrix is a Parikh matrix is discussed in [8]. No nice general criterion is known. However, the following theorem, [8], characterizes exhaustively the entries in the second and third diagonals of a Parikh matrix. Theorem 2. Arbitrary nonnegative integers may appear on the second diagonal of a Parikh matrix. Arbitrary integers mi,i+2 , 1 i k − 1, satisfying the condition 0 mi,i+2 mi,i+1 mi+1,i+2 (but no others) may appear on the third diagonal of a (k + 1)-dimensional Parikh matrix. Theorem 2 gives a complete characterization of Parikh matrices over binary alphabets, since in this case no further diagonals are present. In the general case, starting with arbitrary second and third diagonals satisfying the conditions of Theorem 2, the matrix can be completed to a Parikh matrix in at least one way.
192
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
We will now introduce the generalized notion of a Parikh matrix due to [17]. We first recall the definition of the “Kronecker delta”. For letters a and b,
a,b =
1 if a = b, 0 if a = b.
Definition 3. Let u = b1 . . . bk be a word, where each bi , 1 i k, is a letter of the alphabet . The Parikh matrix mapping with respect to u, denoted u , is the morphism:
u : ∗ → Mk+1 , defined, for a ∈ , by the condition: if u (a) = Mu (a) = (mi,j )1 i,j (k+1) , then for each 1 i (k + 1), mi,i = 1, and for each 1 i k, mi,i+1 = a,bi , all other elements of the matrix Mu (a) being 0. Matrices of the form u (w), w ∈ ∗ , are referred to as generalized Parikh matrices. Thus, the Parikh matrix Mu (w) associated to a word w is obtained by multiplying the matrices Mu (a) associated to the letters a of w, in the order in which the letters appear in w. The above definition implies that if a letter a does not occur in u, then the matrix Mu (a) is the identity matrix. For instance, if u = baac, then
1 0 Mu (a) = 0 0 0
0 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 . 0 1
1 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 , 0 1
Similarly,
1 0 Mu (b) = 0 0 0
1 0 Mu (c) = 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 . 1 1
In the original definition of a Parikh matrix, [9], the word u was chosen to be u = a1 . . . ak , for the alphabet = {a1 , . . . , ak }. In the general setup, the essential contents of Theorem 1 can be formulated as follows. For 1 i j k, denote Ui,j = bi . . . bj . Denote the entries of the matrix Mu (w) by mi,j . Theorem 3. For all i and j , 1 i j k, we have mi,1+j = |w|Ui,j .
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
193
Going back to our example u = baac, we infer from Theorem 3 that, for any word w, 1 |w|b |w|ba |w|baa |w|baac 0 1 |w|a |w|aa |w|aac 0 0 1 |w|a |w|ac Mu (w) = . 0 0 0 1 |w|c 0 0 0 0 1 For w = a 3 c3 bac2 ac we get 1 1 2 0 1 5 Mu (w) = 0 0 1 0 0 0 0 0 0
1 1 10 31 5 22 . 1 6 0 1
3. Matrix-deducible inequalities We begin with the following theorem. It concerns the occurrences of subwords of a certain general type. We consider decompositions xyz, and the occurrences of xyz, y, xy, and yz as subwords in an arbitrary w. Theorem 4. The inequality |w|xyz |w|y |w|xy |w|yz holds for arbitrary words w, x, y, z. Theorem 4 is due to [10]. A direct combinatorial proof is given also in [15]. The result can be obtained also using the following lemma, [10,17]. As in the preceding section, we denote by Mu (w) an arbitrary generalized Parikh matrix. Lemma 1. The value of any minor of the matrix Mu (w) is a nonnegative integer. The inequality presented in Theorem 4 is referred to as the Cauchy inequality for words. It can be claimed to be a fundamental property of words, because of its generality and because it reduces to equality in a great variety of cases. The choice for the name of the inequality is motivated by the resemblance to the well-known algebraic Cauchy inequality for real numbers and also by the methods used in the proof. The reader is referred to [10] for further details. No general theory exists concerning the cases when the Cauchy inequality actually reduces to an equality. We now present some considerations in this direction. We begin with a simple example. Consider the words w = a i1 bj1 ck1 ,
x = a i2 ,
y = bj2 ,
z = ck2 . (As usual, a, b, c stand for letters.) Clearly, |w|y = jj21 . Straightforward calculations show that 2 j1 k1 i1 = |w|xy |w|yz . |w|y |w|xyz = i2 j2 k2
194
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
For instance, the setup w = a 4 b4 c4 ,
x = a,
y = b,
z = c2
yields the value 384 for both sides of the equation. In general, if w = x1 y1 z1 ,
|w|x = |x1 |x = m,
|w|y = |y1 |y = n,
|w|z = |z1 |z = p,
then both sides of the Cauchy inequality equal mn2p and, thus, the inequality is not proper. Consider words over a one-letter alphabet. If the words w, x, y, z are of lengths n, i, j, k, respectively, then the inequality assumes the form n n n n , i+j j +k j i+j +k which is easily verified to be true. Here we have an equality exactly in case i = 0 or k = 0. Assume that y = a i bj a k ,
x = a i1 ,
z = a k1
and w = a i+i1 +i bj +j a k+k1 +k . Then again it is easy to verify that the inequality is not proper. More general results can be obtained using the linearization of subword histories presented in [10]. Consider the equation (|w|a ) × (|w|b ) = |w|ab + |w|ba mentioned in Section 1, valid for any word w and letters a and b. According to the terminology introduced in [10], we speak of the subword history a × b − ab − ba in the word w, defined by the equation SH(w, a × b − ab − ba) = (|w|a ) × (|w|b ) − |w|ab − |w|ba . Thus, our simple equation tells us that, for any word w, SH(w, a × b − ab − ba) = 0. Secondly, our equation can be written in the form SH(w, a × b) = SH(w, ab + ba). In other words, independently of w, the subword history a × b assumes the same value as the subword history ab + ba in w. In such a case we say that the two subword histories are equivalent. Our equation shows also how a particular subword history involving the operation × possesses an equivalent linear subword history, that is, an equivalent subword history not involving the operation ×. It was established in [10] that this holds true in general: the operation × can be eliminated from all subword histories. The proof uses the
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
shuffle u
v of two words u and v. By definition, u
u0 v0 u1 v1 . . . uk vk ,
195
v consists of all words
where k 0, ui , vi ∈ ∗ for 0 i k, and
u = u0 . . . uk , v = v0 . . . vk . It is fairly straightforward to prove
that if u and v are words over disjoint alphabets, then the subword histories u × v and x∈u v x are equivalent. This result forms the basis of the general linearization technique: for arbitrary u and v, one first provides the letters of v with primes, forcing the two words to be over disjoint alphabets. One then forms the shuffle, arguing at the same time with “reduced” words and multiplicities. For instance, 2abba + abab + baba + 2baab + aba + bab is a linear subword history equivalent to ab × ba. The following example is more sophisticated. Consider the special case A = (ab) × (aabb) (aab) × (abb) = B. of the Cauchy inequality. The equivalent linear subword histories are in this case: A=aba2 b2 +4a 2 bab2 +9a 3 b3 +a 2 b2 ab+abab2 +a 2 bab+6a 2 b3 +6a 3 b2 +4a 2 b2 , the linear subword history equivalent to B being obtained by adding a 2 bab2 +a 2 b2 ab+aba2 b2 +ababab+ab2 a 2 b+2abab2 +a 2 bab+ab2 ab+abab to A. This gives the following conclusion. (The result can be inferred without reference to Theorem 4.) For any word w, we have |w|ab |w|aabb |w|aab |w|abb . The equality holds exactly in case w does not contain the subword abab (and the right side is nonzero). The same argument is applicable for more general words. Consider the inequality |w|xyz |w|y |w|xy |w|yz , where x = a m , y = ab, z = bn , m, n 1. By analyzing the linear subword histories arising from the two sides of the inequality, we see that every term on the left side gives rise to a unique term on the right side and, moreover, the eventual additional terms on the right side all possess the subword abab. Thus, we obtain the following result. Theorem 5. The inequality |w|ab |w|a m bn |w|a m b |w|abn ,
m, n 2,
holds for all words w and is strict exactly in case w contains the subword abab (and the right side is nonzero). Numerous inequalities can be deduced from Lemma 1, by Theorem 1 or Theorem 3. The following general result is along these lines.
196
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
Theorem 6. Let k 1 and let w, arbitrary minor of the matrix 1 |w|x1 |w|x1 x2 0 1 |w|x2 .. . M= .. . 0 ...
x1 , . . . , xk be arbitrary words. Further, let Mdet be an ... |w|x1 ...xk ... |w|x2 ...xk .. . .. . |w|xk ... 0 1
.
Then Mdet 0. For instance, the subsequent inequalities are obtained by Theorem 6. The letters u, w, x, y, z, y1 , . . . , yn stand for arbitrary words. A suitable combination of the inequalities gives (partial) results about the cases when the inequality is strict. However, a general theory is missing. |w|xy |w|y |w|xyz |w|y1 . . . |w|yn |w|xy1 ...yn z |w|x |w|yz + |w|xy |w|z
|w|x |w|y , |w|xy |w|yz , (Cauchy inequality), |w|xy1 |w|y1 y2 . . . |w|yn z , |w|xyz + |w|x |w|y |w|z ,
|w|yz |w|xyzu + |w|xy |w|z |w|yzu + |w|y |w|xyz |w|zu |w|xy |w|yz |w|zu + |w|y |w|z |w|xyzu + |w|xyz |w|yzu , |w|x |w|y |w|zu + |w|x |w|yz |w|u + |w|xy |w|z |w|u + |w|xyzu |w|x |w|yzu + |w|xy |w|zu + |w|xyz |w|u + |w|x |w|y |w|z |w|u .
4. Sufficient conditions for complete inference A very central problem concerning words, also important in numerous applications, is to find some elements (factors, subwords, etc.) of words that characterize the word so that, instead of the word itself, it suffices to investigate the elements. For instance, one might be able to characterize a word in terms of some specific factors or subwords. Here the characterization can be total or partial: the elements considered may determine the word uniquely or only to a certain extent. A characterization in terms of factors, optimal in a specific sense, was given in [2]. Here we consider characterizations in terms of subwords. A general problem is the following. What numbers |w|u suffice to determine the word w uniquely? In addressing the general problem, one should specify a class of subwords u such that the values |w|u , where u ranges over this class, determine w uniquely. Such a class could consist of all words of at most a given length. Indeed, a notion often mentioned but not much investigated in the literature, [1,6,13,15], is that of a t-spectrum. For a fixed t 1, the t-spectrum of a word w tells all the values |w|u , where |u| t. Following the notation of
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
197
formal power series, [5], the t-spectrum of a word w in ∗ can be viewed as a polynomial in N0 < ∗ > of degree t. For instance, the polynomial aa + bb + 2ab + 2ba + 2a + 2b is the 2-spectrum of the word abba, as well as of the word baab. In general, one can define the function (t) as the maximal length such that any word of length (t) is uniquely determined by its t-spectrum. See [15] for other details. The function (t) is discussed in detail in [3], where the original formulation of the problems is credited to L.O. Kalashnik. For instance, the two different words abbaaab, baaabba (resp. ab2 a 3 ba2 b2 a, ba3 bab2 a 3 b) have the same 3-spectrum (resp. 4-spectrum), and are both of length 7 (resp. 12), [6]. This shows that
(3) 6, (4) 11. Perhaps one should not always consider subwords of the same length and take all of them. Sometimes very few words (of different lengths) determine the word uniquely. Consider words w over the alphabet {a, b}. We will now show how w can be uniquely inferred from certain values |w|u . A good choice for the words u is the sequence abi , i = 0, 1, 2, . . . . Indeed, as shown in the following Lemma, the word w can be uniquely inferred from its Parikh vector (r, s) and the numbers |w|abi , 1 i min(r, s). Lemma 2. Assume that w and w are words over the alphabet {a, b} with the same Parikh vector (r, s) and that |w|abi = |w |abi ,
1 i min(r, s).
Then w = w . Proof. Recall that the Parikh vector of a word w is the vector (|w|a , |w|b ). Notice that under our hypotheses one has |w|abi = |w |abi , 1 i r. Indeed, this is trivial if r s while if s < r, then |w|abi = |w |abi = 0 for s + 1 i r. Thus, in order to prove the statement, it is sufficient to show that the numbers r, s and |w|abi ,
1 i r,
determine the word w uniquely. Consider the r occurrences of the letter a in w, and denote by xi , 1 i r, the number of occurrences of b to the right of a particular occurrence of a, when the occurrences of a are counted from left to right. Thus, s x1 x2 . . . xr 0.
(1)
198
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
Denote |w|abi = i , 1 i r. We obtain the following system of equations: r
xi = j , j = 1, . . . , r. j i=1 (This follows because, for instance, each subword occurrence of ab2 in w is obtained by taking the ith occurrence of a, for some i where 1 i r, and an arbitrary pair of the xi occurrences of b to the right of this a.) When the binomial coefficients are written out as polynomials, the system of equations takes the form r
i=1
j
xi = Pj (1 , . . . , j ),
j = 1, . . . , r,
where each Pj is a linear polynomial with positive integer coefficients. (The latter can be given explicitly but this is irrelevant for our purposes.) For instance, we obtain for r = 4 : x1 + x2 + x3 + x4 = 1 , x12 + x22 + x32 + x42 = 22 + 1 , x13 + x23 + x33 + x43 = 63 + 62 + 1 , x14 + x24 + x34 + x44 = 244 + 363 + 142 + 1 . It is well known that this system has a unique unordered solution (on the complex field) which is given by the roots of a suitable polynomial of degree r. This is, indeed, a straightforward consequence of Newton–Girard formulas relating the coefficients of a polynomial and the sums of the powers of its roots. We derive that there is at most one ordered solution (x1 , . . . , xr ) where xi , 1 i r, are integers satisfying (1). Finally, the word w is uniquely inferred from the numbers xi and s. For instance, the values |w|a = 4, |w|b = 11, |w|ab4 = 128
|w|ab = 18,
|w|ab2 = 48,
|w|ab3 = 92,
yield the (unique) word w = b2 ab5 a 2 b3 ab. This concludes the proof.
Lemma 3. The statement of Lemma 2 holds true if the sequence abi , 1 i min(r, s), is replaced by any of the three sequences a i b,
bai ,
bi a,
1 i min(r, s).
Proof. The claim concerning the sequence ba i follows from Lemma 2, by interchanging the letters a and b. Consider the sequence a i b. Clearly, |w|a i b = |mi(w)|ba i , where mi(w) is the mirror image of w. Thus, mi(w) and, therefore, also w is uniquely determined by the given numerical values. Finally, the claim concerning bi a follows again by interchanging a and b. Theorem 7. For any integer l, a word w of length l over the alphabet {a, b} can be uniquely inferred from at most [l/2] + 2 specific values |w|u .
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
199
Proof. The result follows directly from Lemma 2 (or from Lemma 3), because min(r, s) [l/2]. For instance, the values |w|a ,
|w|b , |w|ab , |w|ab2
determine uniquely a word w of length 5. The result is optimal in the sense that no three among the values suffice for the same purpose. The 5002 values |w|a ,
|w|b ,
|w|abi ,
1 i 5000,
determine uniquely a word w of length 104 . The 12-spectrum of a word consists of somewhat more values but, according to [3], only words of length less that 600 are uniquely determined by it. To infer uniquely words of length 104 , the 18-spectrum is needed, [3]. In the consideration of spectra, attention may be restricted to binary alphabets, [3]. The situation is different if one just wants to have a “good” set of values |w|u for the inference of w. If the alphabet is bigger than binary, one may consider the letters pairwise or try some direct approach. In any case, one has to extend the results such as Lemmas 2 and 3. Some results about the injectivity of Parikh matrix mappings have been presented in [4,8,16]. The above considerations can be used to establish an injectivity result for generalized Parikh matrix mappings. We base our discussion on Lemma 2; Lemma 3 yields analogous results. Consider the generalized Parikh matrix mapping (over the alphabet {a, b})
= u ,
where u = abt , t 1.
Thus, the matrices (w) are (t + 2)-dimensional. In the matrix (a) the only nonzero entry above the main diagonal is the entry (1, 2), whereas in the matrix (b) all entries (j, j + 1), 2 j t + 1, equal 1. By Theorem 3, we have for an arbitrary word w: |w|abt 1 |w|a |w|ab . . . 0 1 |w|b ... |w|bt . . .. .. . (w) = .. .. . . |w|b 0 ... ... 0 1 Observe also that, for any word w, the value |w|b determines uniquely all values |w|bi , i 1. Hence, the following result is a consequence of Lemma 2 and Theorem 3. Theorem 8. If the equation (w) = (w ) holds for different words w and w , then |w| = |w | > 2t. Theorem 8 gives a numerical characterization of binary words in terms of matrices. It can be extended to arbitrary words by considering the letters pairwise. However, this method is not very efficient. It is likely that there are better direct ways for the characterization.
200
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
5. Forbidden subwords Forbidden factors of words and infinite words have been widely investigated. A forbidden factor of a word w is simply a word that does not occur as a factor of w. Forbidden factors are sometimes of fundamental importance in determining the structure of the word itself. A word u is a minimal forbidden factor of a word w if u is a forbidden factor of w but all proper factors of u are factors of w. This notion has relevant connections with automata theory, text compression and symbolic dynamics. The reader is referred to [11] and the references given therein. Analogous notions can be defined for subwords as well. Definition 4. A word u is a forbidden subword of w if |w|u = 0. A forbidden subword u of w is minimal if all proper factors v of u satisfy |w|v > 0. The purpose of this section is only to point out a direct connection between (minimal) forbidden subwords and generalized Parikh matrices. We hope to return to forbidden subwords in another contribution. Theorem 9. A word u is a forbidden subword of a word w if and only if the entry in the upper right corner of the generalized Parikh matrix Mu (w) equals 0. A forbidden subword u of w is minimal exactly in case all other entries above the main diagonal in Mu (w) are positive. Theorem 9 follows by the definitions and Theorem 3. For instance, consider w = baababb, Then
1 0 Mu (w) = 0 0 0
u = abba.
3 1 0 0 0
8 4 1 0 0
7 6 4 1 0
0 1 4 , 3 1
showing that u is a minimal forbidden subword of w. Observe that u is a minimal forbidden subword of w also under the following modified definition: A forbidden subword u of w is minimal if all proper subwords of u are also subwords of w. Minimality under this modified sense cannot be directly characterized by generalized Parikh matrices. A transposition in w, resulting in w = baabbab, gives the matrix 1 3 7 6 2 0 1 4 6 3 Mu (w) = 0 0 1 4 5 0 0 0 1 3 0 0 0 0 1 and, thus, u is not forbidden.
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
201
The defining condition for a forbidden subword, |w|u = 0, concerns estimations of the number |w|u . The inequalities discussed in Section 3 yield readily such estimations. For instance, the following result is a consequence of Theorem 4. Lemma 4. For any words w, u, x, y, z, where u = xyz, we have |w|u
|w|xy |w|yz . |w|y
6. Conclusion. Open problems Various algebraic considerations concerning Parikh matrices have been presented in the literature, see for instance [7]. Parikh matrices are not closed under the ordinary addition of matrices. A special operation was introduced for matrices in Mk in [7]. The entries above entries in the main diagonal in the matrix M1 M2 are obtained from the corresponding M1 and M2 by addition. (Thus, the main diagonal of the matrix M1 M2 consists of 1’s.) If we are dealing with binary alphabets, then Theorem 2 implies that the “sum” M1 M2 of two Parikh matricesM1 and M2 is again a Parikh matrix. The same conclusion hold for the “product” M1 M2 of two Parikh matrices M1 and M2 , defined by entry-wise multiplication. Indeed, if in both M1 and M2 the only element of the third diagonal is within the bounds allowed in Theorem 2, the same holds true with respect to the corresponding element in M1 M2 . Thus, we obtain the following result. Theorem 10. Parikh matrices over the alphabet {a, b} constitute a commutative semiring with identity, with respect to the operators and . If the alphabet consists of three or more letters, then M1 M2 is not necessarily a Parikh matrix for Parikh matrices M1 and M2 . As pointed out in [7], the matrix M1 M2 is not a Parikh matrix if M1 and M2 are the Parikh matrices resulting from the words abc and b, respectively. As regards the operation , it is not easy to find similar examples. Indeed, it is an open problem whether or not the set of Parikh matrices is closed under . The matrices satisfying the property of Lemma 1 are closed under . (In other words, if every minor of the matrices M1 and M2 is a nonnegative integer, the same holds true for the matrix M1 M2 .) However, not every matrix (in M) having this property is a Parikh matrix, [10,8]. Problems concerning the operation belong to the more general problem area concerning suitable algebraic operations for Parikh matrices. For instance, would the Kronecker product of matrices suit for some characterizations? Properly chosen algebraic operations might contribute significantly to the general characterization and injectivity problems of Parikh matrices, [4,10,8,16]. We conclude by mentioning some other open problems. Finding numerical values, such as in Lemmas 2 and 3, from which a word can be uniquely inferred is a problem area of considerable practical significance, [3,6,15]. What is a minimal or otherwise optimal set of such values? Our considerations above deal with binary alphabets. In the general case one can of course consider the letters pairwise, but a more direct approach is called for.
202
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
A number of open problems relate Parikh matrices with languages. Given a language L ⊆ ∗ , we denote by M(L) the set of Parikh matrices associated to the words in L. Is the equation M(L1 ) = M(L2 ) decidable when L1 and L2 come from a specific language family? This problem is open even for regular languages. Related problems are mentioned in [8]. One can also specify an alphabet and some values |w|u , and study the set of words w, where each of these values is met. For instance, the regular language b∗ (a 3 b+ab3 +abab)a ∗ results from the value |w|ab = 3, whereas the language (ba 3 b + abab)a ∗ results from the combination of the values |w|ab = 3 and |w|b = 2. The combination of the values |w|aba = 1 and |w|babab6 = 5 yields the unique word b5 abab6 . The conditions |w|a = |w|b = |w|ab = i,
for some i 1,
lead to a rather involved noncontext-free language. From finitely many conditions always a regular language results. Thus, if we fix values for arbitrary entries in a (generalized) Parikh matrix, then the set of all those words whose Parikh matrix has the fixed values in the corresponding entries is regular. Infinite languages are obtained by leaving open some entries in the second diagonal. Subword histories were considered above in Section 3. The equality problem, that is, the problem of deciding whether two subword histories assume the same value for all words, was settled in [10]. The corresponding inequality problem is open: given two subword histories SH 1 and SH 2 , is the value of SH 1 for an arbitrary word w less than or equal to that of SH 2 ? For instance, baab bab + baaab because |w|baab |w|bab + |w|baaab holds for all w. In the general case it is not even known whether the problem is decidable. The case of one-letter alphabets is easy to settle. By [10], the attention may be restricted to linear subword histories. One can also show that the inequality u v holds between two “monomial” subword histories u and v only in case u = v. Acknowledgements The author is grateful to the referee for useful suggestions.
References [1] [2] [3] [4]
J. Berstel, J. Karhumäki, Combinatorics on words—a tutorial, EATCS Bull. 79 (2003) 178–228. A. Carpi, A. De Luca, Words and special factors, Theoret. Comput. Sci. 259 (2001) 145–182. M. Dudik, L.J. Schulman, Reconstruction from subsequences, J. Combin. Theory A 103 (2002) 337–348. S. Fossé, G. Richomme, Some characterizations of Parikh matrix equivalent binary words, Inform. Proc. Lett. 92 (2004) 77–82. [5] W. Kuich, A. Salomaa, Semirings Automata Languages, Springer, Berlin, Heidelberg, New York, 1986.
A. Salomaa / Theoretical Computer Science 340 (2005) 188 – 203
203
[6] J. Ma˘nuch, Characterization of a word by its subwords, in: G. Rozenberg, W. Thomas (Eds.), Developments in Language Theory, World Scientific Publ. Co., Singapore, 2000, pp. 210–219. [7] A. Mateescu, Algebraic aspects of Parikh matrices, in: J. Karhumäki, H. Maurer, G. P˘aun, G. Rozenberg (Eds.), Theory is Forever, Springer, Berlin, 2004, pp. 170–180. [8] A. Mateescu, A. Salomaa, Matrix indicators for subword occurrences and ambiguity, Int. J. Found. Comput. Sci. 15 (2004) 277–292. [9] A. Mateescu, A. Salomaa, K. Salomaa, S. Yu, A sharpening of the Parikh mapping, Theoret. Inform. Appl. 35 (2001) 551–564. [10] A. Mateescu, A. Salomaa, S. Yu, Subword histories and Parikh matrices, J. Comput. Systems Sci. 68 (2004) 1–21. [11] F. Mignosi, A. Restivo, M. Sciortino, Forbidden factors in finite and infinite words, in: J. Karhumäki, H. Maurer, G. P˘aun, G. Rozenberg (Eds.), Jewels are Forever, Springer, Berlin, 1999, pp. 339–350. [12] R.J. Parikh, On context-free languages, J. Assoc. Comput. Mach. 13 (1966) 570–581. [13] G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages 1–3, Springer, Berlin, Heidelberg, New York, 1997. [14] J. Sakarovitch, I. Simon, Subwords, in: M. Lothaire (Ed.), Combinatorics on Words, Addison-Wesley, Reading, MA, 1983, pp. 105–142. [15] A. Salomaa, Counting (scattered) subwords, EATCS Bull. 81 (2003) 165–179. [16] A. Salomaa, On the injectivity of Parikh matrix mappings, Fund. Inform. 64 (2005) 391–404. [17] T.-F. Serb˘ ¸ anu¸ta˘ , Extending Parikh matrices, Theoret. Comput. Sci. 310 (2004) 233–246.
Theoretical Computer Science 340 (2005) 204 – 219 www.elsevier.com/locate/tcs
Words derivated from Sturmian words Isabel M. Araújoa,1 , Véronique Bruyèreb,∗ a Departamento de Matemática, Universidade de Évora Rua Romão Ramalho, 59, 7000-671 Évora, Portugal b Institut d’Informatique, Université de Mons-Hainaut, Le Pentagone av. du Champ de Mars,
6, 7000 Mons, Belgium
Abstract A return word of a factor of a Sturmian word starts at an occurrence of that factor and ends exactly before its next occurrence. Derivated words encode the unique decomposition of a word in terms of return words. Vuillon has proved that each factor of a Sturmian word has exactly two return words. We determine these two return words, as well as their first occurrence, for the prefixes of characteristic Sturmian words. We then characterize words derivated from a characteristic Sturmian word and give their precise form. Finally, we apply our results to obtain a new proof of the characterization of characteristic Sturmian words which are fixed points of morphisms. © 2005 Elsevier B.V. All rights reserved. Keywords: Combinatorics on words; Sturmian words; Return words
1. Introduction The concepts of return words and derivated words were introduced by Durand in [9]. Given a Sturmian word x, a return word of a factor w of x, is a word that starts at an occurrence of w in x and ends exactly before the next occurrence of w. Derivated words encode the unique decomposition of a word in terms of its return words. In [14], Vuillon characterized Sturmian words in terms of their return words by showing that an infinite word is Sturmian if and only if each non-empty factor w of x has exactly ∗ Corresponding author.
E-mail addresses:
[email protected] (I.M. Araújo),
[email protected] (V. Bruyère). 1 Also at Centro de Álgebra da Universidade de Lisboa, Avenida Professor Gama Pinto, 2, 1649-003 Lisboa,
Portugal. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.020
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
205
two distinct return words. In [2], the authors considered the shortest of those return words and its first occurrence. That permitted to answer negatively a question posed by Michaux and Villemaire in [13]. In this paper, we are interested in both return words as well as in the associated derivated word. Thus, in Section 2, we introduce the classes of Sturmian words and characteristic Sturmian words. In Section 3, we give the exact form of the return words of prefixes of characteristic Sturmian words together with their first occurrence. That allows us to fully characterize derivated words of characteristic Sturmian words, which we do in Section 4. Finally, in Section 5, we apply our results to obtain an alternative proof for the characterization of characteristic Sturmian words which are fixed points of morphisms given in [8]. 2. Sturmian words An infinite word x is Sturmian if the number of distinct factors of length n is exactly n+1. The function px : N → N such that px (n) is the number of distinct factors of x of length n is called the complexity of the infinite word x. It is well known that any non-ultimately periodic word satisfies px (n) n + 1, for all n ∈ N; in this sense Sturmian words are words of minimal complexity among infinite non-ultimately periodic words. It is clear from the definition of Sturmian word that any Sturmian word is necessarily binary. Moreover, all words considered in this paper are binary. There is a vast amount of literature on Sturmian words and their study is an active area of research. Both Chapter 2 in [12] and the survey [4] are comprehensive introductions to Sturmian words and contain many references to recent works. Allouche and Shallit’s recent book [1] also contains two chapters on the subject. We now define the subclass of characteristic Sturmian words. For an irrational ∈]0, 1[ we define a sequence (tn )n of finite words by t0 = 0,
t1 = 0a1 1,
an tn = tn−1 tn−2
(n 2),
where [0, a1 + 1, a2 , . . .] is the continued fraction expansion of (a1 0 and ai 1 for i 2). It is also usual to consider t−1 = 1, which permits to write t1 = t0a1 t−1 . We then define the infinite word f = lim tn n→∞
which is called the characteristic Sturmian word of slope . The sequence (tn )n is called the associated standard sequence of f . To each characteristic Sturmian word we may associate the sequence (qn )n of the lengths of the words tn of the above given sequence. Clearly (qn )n is given by q0 = 1,
q1 = a1 + 1,
qn = an qn−1 + qn−2
(n 2).
Any characteristic Sturmian word is indeed a Sturmian word. This fact is a consequence of the study of Sturmian words as mechanical words (see [12, Chapter 2]). It can also be proved within this context (see [12, Proposition 2.1.18]), that every Sturmian word has the same set of factors as a well chosen characteristic Sturmian word. Notice that any tn is a
206
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
prefix of both tm , for m n 1, and of f . On the other hand, if a1 = 0, then t0 = 0 is not a prefix of neither tn , for n 1, nor f . A pair of finite words (u, v) is standard if there is a finite sequence of pairs of words (0, 1) = (u0 , v0 ), (u1 , v1 ), . . . , (uk , vk ) = (u, v) such that for each i ∈ {1, . . . , k}, either ui = vi−1 ui−1 and vi = vi−1 , or ui = ui−1 and vi = ui−1 vi−1 . An unordered standard pair is a set {u, v} such that either (u, v) or (v, u) is a standard pair. A word of a standard pair is called a standard word. Any standard word is primitive (see [12, Proposition 2.2.3]), any word in a standard sequence (tn )n is a standard word and every standard word occurs in some standard sequence (see [12, Section 2.2.2]). A factor u of a word x is left (respectively right) special if 0u and 1u (respectively u0 and u1) are factors of x; it is bispecial if it is both left and right special. It is easy to see that a word x is Sturmian if and only if it has only one left (respectively right) special factor of each length. For a characteristic Sturmian word f , the set of left special factors is its set of prefixes, and its set of right special factors is the set of reversal of prefixes (see [12, Section 2.1.3]). Moreover, the bispecial factors of a characteristic Sturmian word f are the prefixes of f which are palindromes. The next lemma lists some useful facts about characteristic Sturmian words. For a finite word w of length greater than or equal to 2, we denote by c(w) the word obtained from w by swapping its last two letters. For a non-empty word w, we denote by w the word obtained from w by deleting its last letter. We say that a factor u of w is a strict factor of w if u is neither a prefix, nor a suffix, of w. Lemma 1. With the above notation, for any n ∈ N, (a) tn tn−1 = c(tn−1 tn ) and tn tn−1 = tn−1 tn , (b) tn tn−1 is not a strict factor, nor a suffix, of tn tn−1 tn , (c) the prefixes of f which are palindromes are the prefixes of length aqn + qn−1 − 2, with 1 a an+1 . Proof. A proof of (a) appears in [1], statement (b) is an easy consequence of [2, Lemma 3.8(iv)] and (c) can be found in [6]. 3. Return words Given a non-empty factor w of a Sturmian word x = x0 x1 . . . (where each xi is a letter of x), an integer i is said to be an occurrence of w in x if xi xi+1 . . . xi+|w|−1 = w. For adjacent occurrences i, j , i < j , of w in x the word xi xi+1 . . . xj −1 is said to be a return word of w in x (or, more precisely, the return word of the occurrence i of w in x). That is, a return word of w in x is a word that starts at an occurrence of w in x
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
207
and ends exactly before the next occurrence of w. Note that a return word of w always has w as a prefix or is a prefix of w. The latter happens when two occurrences of w overlap. Return words were first defined by Durand in [9]. Example 2. Consider the characteristic Sturmian word f , where has continued fraction expansion [0, 3, 2]. According to the definition of the sequence (tn )n , in this case we have t0 = 0, t1 = 001 and t2 = 0010010. Moreover, the word 00100100010010001001000100100100010010 is a prefix of f . Let us look for the return words of the factor w = 001. Occurrences of that factor are underlined. The words u = 001 and v = 0010 are the two return words of 001 that we find in that prefix of f . 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0. u
v
u
v
u
v
u
u
v
(1)
u
In [14], Vuillon shows that an infinite binary word x is Sturmian if and only if each nonempty factor of x has exactly two return words. In [2] we studied the shortest of those return words and its first occurrence. That study has permitted, in particular, to answer negatively a question posed by Michaux and Villemaire in [13]. In the next proposition we recall this result from [2] (see Fig. 1). Proposition 3 (Araújo and Bruyère [2, Proposition 3.2]). Let n 2. With the above notation, the shortest return word of a prefix w of f of length in the interval In =]qn + qn−1 − 2, qn+1 + qn − 2] is tn , and its first occurrence as a return word of w is 0 if |w| qn+1 − 2, an+2 qn+1 otherwise. We are now also interested in the other return word of a prefix of a characteristic Sturmian word. The next proposition gives its form and its first occurrence (see Fig. 2). Proposition 4. Let n 2 and i ∈ {1, . . . , an+1 }. With the above notation, the longest return word of a prefix w of f of length in the interval In,i =]iqn + qn−1 − 2, (i + 1)qn + qn−1 − 2] is tni tn−1 , and its first occurrence as a return word of w is (an+1 − i)qn . Remark 5. The interval In considered in Proposition 3 is the union of the intervals In,i , with i ∈ {1, . . . , an+1 }, considered in Proposition 4. In particular, it is clear that qn+1 −2 = an+1 qn + qn−1 − 2. Also, notice that in Proposition 4, when i = an+1 , the longest return word of w is tn+1 and its first occurrence is 0. In order to prove Proposition 4 we start by proving two lemmas. The first one gives us a special decomposition of a prefix of f . The second lemma points out a strategy to prove Proposition 4. Lemma 6. For n 0 and i ∈ {1, . . . , an+1 }, tn+1 tni tn−1 is a prefix of f .
208
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
Fig. 1. The shortest return word of a prefix of f and its first occurrence.
Fig. 2. The longest return word of a prefix of f and its first occurrence.
Proof. Let n 0 and i ∈ {1, . . . , an+1 }. We have that a
a
a
n+3 n+2 n+3 tn+3 = tn+2 tn+1 = tn+1 tn tn+2
−1
tn+1
is a prefix of f . If an+2 > 1, it follows that a
tn+1 tn+1 = tn+1 tn n+1 tn−1 is a prefix of f . Thus tn+1 tni tn−1 is a prefix of f . If, on the other hand, an+2 = 1, we see a that tn+1 tn tn+1 = tn+1 tn tn n+1 tn−1 is a prefix of f , and therefore so is tn+1 tni tn−1 . Lemma 7. Let n 0 and i ∈ {1, . . . , an+1 }. The occurrences of the prefixes of f , with lengths in the interval In,i =]iqn + qn−1 − 2, (i + 1)qn + qn−1 − 2], coincide. Moreover, if w and w are two such prefixes, and j is an occurrence of w and w in f , then a word u is a return word for the occurrence j of w if and only if it is a return word for the occurrence j of w . Proof. For the first part of the proof, it is enough to show that given w = x0 . . . xk−1 and w = x0 . . . xk , with k, k + 1 ∈ In,i , an occurrence of w is an occurrence of w in f . Notice that k < (i + 1)qn + qn−1 − 2. Hence, by Lemma 1(c), w is a prefix of f which is not a palindrome. Therefore w is not bispecial and, in particular, it is not right special (recall that w, being a prefix of f , is a left special factor). Thus, the only factor of f of length k + 1, which begins by w, is w . Therefore, any occurrence of w in f is an occurrence of w in f .
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
209
Fig. 3. Illustration of occurrences of tni tn in ](an+1 − i)qn , qn+1 [.
The second statement follows immediately from the first one and the definition of return word. Proof of Proposition 4. Let n 2 and i ∈ {1, . . . , an+1 }. By Lemma 7, it is enough to prove the result for the prefix of length iqn + qn−1 of f , tni tn−1 . Notice that this length a −i belongs to the interval In,i , since n 2. By Lemma 6, tn+1 tni tn−1 = tn n+1 tni tn−1 tni tn−1 is i a prefix of f . Thus both (an+1 − i)qn and qn+1 are occurrences of tn tn−1 in f . Moreover, there is no occurrence of tni tn−1 between (an+1 − i)qn and qn+1 . Indeed, if we suppose otherwise, there are two cases to be considered: (a) tni tn−1 occurs at a position in the interval ](an+1 − i)qn , an+1 qn ], (b) tni tn−1 occurs at a position in the interval ]an+1 qn , qn+1 [. The two cases are illustrated in Fig. 3 in which the first line represents the prefix tn+1 tn = a −i tn n+1 tni tn−1 tn of f , and the other lines represent the beginning of occurrences of tni tn−1 as described in cases (a) and (b) (keeping in mind that tn−1 is a prefix of tn ). Case (a) implies that tn tn−1 is a strict factor, or a suffix, of tn tn−1 tn , contradicting Lemma 1(b). In case (b) we obtain tn as a strict factor, or a suffix, of tn tn−1 which contradicts the primitivity of tn . We therefore conclude that tni tn−1 is a return word of tni tn−1 in f . We shall now determine the first occurrence of tni tn−1 as a return word of tni tn−1 in f . By the first part of the proof we already know that this first occurrence is bounded by (an+1 −i)qn . Now, if i = an+1 , then (an+1 −i)qn = 0 and therefore, in this case, 0 is the first occurrence of tni tn−1 as a return word of tni tn−1 in f . Suppose now that i < an+1 . Observing a the prefix tn+1 = tn n+1 tn−1 of f , we see that 0, qn , . . . , (an+1 − i)qn are occurrences of tni tn−1 . Therefore, the only return word that appears before position (an+1 − i)qn is tn , the shortest return word. We conclude that the first occurrence of tni tn−1 as a return word of tni tn−1 in f is (an+1 − i)qn . Propositions 3 and 4 are actually valid for n 0, though we have proved them only for n 2. The proofs for smaller values of n have to be made separately and are rather technical; they appear in an appendix at the end of this paper. Example 8. Let f and w = 001 be as in Example 2. Thus |w| = 3 and hence |w| ∈ ]q1 + q0 − 2, 2q1 + q0 − 2] = [3, 5]. Therefore we are in the case n = 1, i = 1 and the return words of w in f are indeed the words t1 = 001, t1 t0 = 0010, found in Example 2. Moreover, applying Propositions 3 and 4, we have that the first occurrence of t1 as a return word is at position 0, while the first occurrence of t1 t0 as a return word is at position (a2 − i)q1 = 3, as observed in Example 2.
210
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219 a
n+1 Now, for n 0, consider the interval In = ∪i=1 In,i as in Propositions 3 and 4. We may define In+1,0 = In,an+1 , and
Jn =
a
−1
n+1 In,i if n > 0, ∪ i=0 an+1 −1 ∪ i=1 In,i if n = 0.
Notice that Jn corresponds to shifting In to the left. From Propositions 3 and 4, we have that a the set of return words of a prefix w with length in In,an+1 = In+1,0 is {tn , tn n+1 tn−1 }, which 0 can also be written as {tn+1 , tn+1 tn }. Thus, combining Propositions 3 and 4, we obtain Proposition 9. Let n 1 and i ∈ {0, . . . , an+1 − 1} or n = 0 and i ∈ {1, . . . , an+1 − 1}. Let w be a prefix of f of length in In,i . Then the return words of w in f are tn and tni tn−1 . Moreover, the first occurrence of tn as a return word of w is 0, and the first occurrence of tni tn−1 as a return word of w is (an+1 − i)qn . The change of indexes from Propositions 3 and 4 to Proposition 9 will be very useful in the proofs of the results in the remaining of the paper. Therefore, we will refer to Proposition 9 whenever we make use of the return words of a prefix of a characteristic Sturmian word. Remark 10. Notice that working with characteristic Sturmian words is not a restriction since every Sturmian word has the same set of factors of a well-chosen characteristic Sturmian word. In Proposition 9, we study the return words of the prefixes of f . Since the prefixes of a characteristic Sturmian word coincide with the left special factors of any Sturmian word with the same set of factors, Proposition 9 actually gives us the form of the return words of the left special factors of a Sturmian word. Remark 11. In [14], Vuillon uses factor graphs of a Sturmian word x to study the return words of x. Factor graphs are efficient tools to study the factors of Sturmian words (for definition and applications see, for instance, [3,6,10]); they are formed by two cycles, intersecting each other in either one vertex or on a simple path. Vuillon, while proving that an infinite word is Sturmian if and only if each factor has exactly two return words, shows that the form of the return words of x depends on the labels of the above-mentioned cycles.
4. Derivated words Let us now introduce the concept of derivated word proposed by Durand in [9]. Let x be a Sturmian word, let w be a prefix of x and let u, v be the two return words of w. Then x can be written in a unique way as a concatenation of the words u and v. Suppose, without loss of generality, that u appears before v in that concatenation. Denote by (x) the first letter of x. Thus we define a bijection : {u, v} → {0, 1} by putting (u) = (x) and (v) = 1 − (x). In this way, if x = z1 z2 . . ., with zi ∈ {u, v}, we define Dw (x) = (z1 )(z2 ) · · · .
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
211
The word Dw (x) is called the derivated word of x with respect to w. The derivated word Dw (x) is a renaming by 0 and 1 of the occurrences of u and v in the decomposition of x in terms of its return words. This definition is better understood with an example. Example 12. Once again let f be the characteristic Sturmian word of slope = [0, 3, 2], and consider the return words of the prefix w = 001. The two return words of w in f are u = 001 and v = 0010. Thus we set (u) = (f ) = 0 and (v) = 1 − (f ) = 1. Thus, from (1), we see that the derivated word of f with respect to 001 starts with 0 1 0 1 0 1 0 0 1 0. Remark 13. Note that the images (u) and (v) were chosen so that any derivated word of x starts with the same letter as x. Remark 14. If two prefixes w, w of x have the same return words u and v then their derivated word is the same. Thus, we may call Dw (x) = Dw (x) the derivated word of x with respect to the return words u and v. Proposition 9 from above describes some prefix of the derivated word of f with respect to its prefix w. With the notation of the proposition, Dw (f ) has a prefix (u)an+1 −i (v). In the next proposition we determine the precise form of the whole derivated word Dw (f ). Its proof uses Proposition 9. Proposition 15. Let f be a characteristic Sturmian word of slope , where is given by its continued fraction expansion [0, a1 + 1, a2 , . . .]. For a prefix w of f whose return words are tn , tni tn−1 (n 1, i ∈ {0, . . . , an+1 − 1} or n = 0, i ∈ {1, . . . , an+1 − 1}), the derivated word Dw (f ) of f is the characteristic Sturmian word of slope • [0, an+1 + 1 − i, an+2 , an+3 , . . .] if a1 > 0; and • [0, 1, an+1 − i, an+2 , an+3 , . . .] if a1 = 0. In order to prove Proposition 15 we need two lemmas. The first lemma, which can be found in [9], is based on the unicity of the decomposition of a Sturmian word with respect to the return words of some prefix of it. Lemma 16 (Durand [9]). Let x be an infinite Sturmian word, w a prefix of x and let u, v be the two return words of w, such that u appears before v in the decomposition of x. Let be the morphism obtained by extending the mapping (x) → u and 1 − (x) → v. Then (a) (Dw (x)) = x and (b) if d is a word such that (d) = x then d = Dw (x). We denote by E the morphism 0 → 1, 1 → 0. Notice that E 2 is the identity mapping. The next lemma relates a characteristic Sturmian word f and its image E(f ), with respect to their associated standard sequences and their derivated words. Lemma 17. Let f be the characteristic Sturmian word of slope , where has continued fraction expansion [0, a1 + 1, a2 , . . .].
212
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
(a) E(f ) = f1− and 1 − has continued fraction expansion • [0, 1, a1 , a2 , . . .] if a1 > 0 and • [0, a2 + 1, a3 , . . .] if a1 = 0. (b) If (tn )n and (sn )n are the standard sequences associated to f and f1− , respectively, then • if a1 > 0 then E(tn ) = sn+1 for all n 0 and • if a1 = 0 then E(tn ) = sn−1 for all n 1. (c) Let n 1 and i ∈ {0, . . . , an+1 − 1} or n = 0 and i ∈ {1, . . . , an+1 − 1}. Then d is derivated from f with respect to the return words tn , tni tn−1 if and only if E(d) is derivated from f1− with respect to the return words E(tn ), E(tni tn−1 ). If a1 > 0, this is also true for n = 0. Proof. (a) The fact that E(f ) = f1− is proved in [12, Corollary 2.2.20]. The form of the continued fraction of 1 − comes from the definition of continued fractions. (b) Suppose first that a1 > 0. Then the continued fraction of 1 − is [0, 1, a1 , a2 , . . .]. Moreover, (sn )n , the standard sequence associated to f1− is given by s0 = 0,
s1 = 1,
a
n−1 sn = sn−1 sn−2
(n 2).
We prove that E(tn ) = sn+1 , for all n 0, by induction on n. For 0 and 1 we have E(t0 ) = 1 = s1 ,
E(t1 ) = E(0a1 1) = 1a1 0 = s1a1 s0 = s2 .
Now, let n 2 and suppose that the claim is true for n − 1 and n − 2. Then an E(tn ) = E(tn−1 tn−2 ) = snan sn−1 = sn+1
which completes the induction. Suppose now that a1 = 0. Since E(f1− ) = f , and in the continued fraction of 1 − the first non-zero entry is strictly greater than 1, we can use the first case to conclude that, for all n 0, E(sn ) = tn+1 . Thus E(tn ) = sn−1 , for all n 1, as desired. (c) Clearly, by Proposition 9 and by (b), if tn and tni tn−1 are the return words of some prefix w of f , then E(tn ) and E(tni tn−1 ) are the return words of the prefix E(w) of f1− . The definition of E permits us to conclude that d is derivated of f if and only if E(d) is derivated from f1− . Remark 18. Lemma 17(c) tells us, in particular, that for a prefix w of f , E(Dw (f )) = DE(w) (E(f )) = DE(w) (f1− ). Proof of Proposition 15. Suppose first that a1 > 0 and let d = Dw (f ). Notice that f begins by 0, and thus d also begins by 0. Thus, by Proposition 9, 0an+1 −i 1 is a prefix of d. Let be the morphism 0 → tn ,
1 → tni tn−1 .
We define a sequence of finite words (rm )m by setting r0 = 0,
r1 = 0an+1 −i 1,
a
m+n rm = rm−1 rm−2
(m 2).
(2)
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
213
Let us see that (rm ) = tm+n , for all m 0. We use induction on m. For m = 0 and m = 1 we have:
(r0 ) = tn , a
−i
a
(r1 ) = tn n+1 tni tn−1 = tn n+1 tn−1 = tn+1 . Suppose now that m 2 and that the claim is true for m − 1 and m − 2. Then a
a
m+n m+n (rm ) = (rm−1 rm−2 ) = tm+n−1 tm+n−2 = tm+n .
Now, if we let d = lim rm , we obtain (d ) = f and hence, by Lemma 16, d = d . Thus, by (2), d is the characteristic Sturmian word whose slope has continued fraction expansion [0, an+1 + 1 − i, an+2 , an+3 , . . .]. Now let a1 = 0. By Lemma 17, the derivated word of f with respect to the return words tn , tni tn−1 is the image by E of the derivated word d of E(f ) = f1− with respect to the return words E(tn ) and E(tni tn−1 ). The continued fraction expansion of 1 − is [0, a2 + 1, a3 , . . .] i sn−2 . Thus, by the first part of the proof, the slope of and E(tn ) = sn−1 , E(tni tn−1 ) = sn−1 d has the continued fraction expansion
[0, an+1 + 1 − i, an+2 , an+3 , . . .]. Therefore E(d) is the characteristic Sturmian word whose slope has the continued fraction expansion [0, 1, an+1 − i, an+2 , an+3 , . . .].
Example 19. Let f be as in Example 12. It is easy to see that f has exactly five derivated words: they are the characteristic Sturmian words whose slope is [0, 2, 2, 3],
[0, 3, 3, 2],
[0, 2, 3],
[0, 4, 2, 3]
and
[0, 3, 2].
The next result relates Proposition 15 and [9, Theorem 2.5]. We start by introducing some definitions with respect to morphisms. A morphism is non-trivial if it is neither the identity nor E, and it is non-erasing if the image of each letter is non-empty. Given a morphism , we say that a word x is a fixed point of , if (x) = x. Moreover, an infinite word x is morphic if there exists a non-erasing morphism , such that (a) = as with a ∈ {0, 1}, s = ε, and x = (a) (in particular, x is a fixed point of ). The infinite word x is called substitutive if it is the image by a literal morphism (i.e. the image of a letter is a letter) of a morphic word. Theorem 20. For a characteristic Sturmian word f , the following conditions are equivalent: (a) the continued fraction of is ultimately periodic,
214
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
(b) the set of all derivated words (with respect to prefixes of f ) of f is finite, (c) f is substitutive. Proof. The equivalence of (b) and (c) is [9, Theorem 2.5]. Let us now prove that (a) and (b) are equivalent. We consider first the case a1 > 0. Suppose that the set of all derivated words of f is finite. Thus, applying Proposition 15, there exist m, n, i and j, with m < n, such that the derivated word of f with respect to j i t tm , tm m−1 and the derivated word of f with respect to tn , tn tn−1 coincide, that is, the continued fraction expansions [0, am+1 + 1 − i, am+2 , am+3 , . . .]
and
[0, an+1 + 1 − j, an+2 , an+3 , . . .]
are equal. Therefore am+k = an+k , for all k 2, and [0, a1 + 1, a2 , a3 , . . .] = [0, a1 + 1, . . . , am+1 , am+2 , . . . , an+1 ] is ultimately periodic. Conversely, suppose that [0, a1 + 1, a2 , a3 , . . .] is ultimately periodic. It is clear from Proposition 15 that there are only finitely many derivated words from f . The equivalence of (a) and (b) for a1 = 0 is proved similarly.
5. An application As an application of the previous results, we obtain a new proof for Theorem 21 in terms of return words and derivated words. This theorem was first proved by Crisp et al. in [8]. Both Berstel and Séébold in [5] and Komatsu and van der Poorten in [11] have presented alternative proofs. This theorem states three equivalences like in Theorem 20, in the case where is a Sturm number, that is, its continued fraction expansion is of one of the following types: (i) [0, a1 + 1, a2 , . . . , an ], with an a1 1, (ii) [0, 1, a1 , a2 , . . . , an ], with an a1 . It is easy to see that is a Sturm number of type (i) if and only if 1 − is a Sturm number of type (ii). The main ingredients of our proof of Theorem 21 are Proposition 15 and the fact that if a characteristic Sturmian word is a fixed point of a morphism , then {(0), (1)} is a unordered standard pair (see [12, Proposition 2.3.11, Theorem 2.3.12] for a proof of this result). Theorem 21. For a characteristic Sturmian word f , the following conditions are equivalent: (a) is a Sturm number, (b) there exists a non-empty prefix w of f such that Dw (f ) = f , (c) f is a fixed point of a (non-erasing, non-trivial) morphism. Proof. [(a)⇒(b)] Suppose first that is a Sturm number of the form [0, a1 + 1, a2 , . . . , an ], i t where an a1 1. Consider the pair of words tn−1 , tn−1 n−2 , where i = an − a1 . We i t have 0 i an − 1, and thus tn−1 , tn−1 are the return words of some prefix of f . n−2
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
215
By Proposition 15, the derivated word of f with respect to those return words is the characteristic Sturmian word whose slope has the continued fraction expansion [0, an−1+1 + 1 − (an − a1 ), an−1+2 , an−1+3 , . . . , an−1+n ] = [0, a1 + 1, an+1 , an+2 , . . . , a2n−1 ] = [0, a1 + 1, a2 , . . . , an ] which is exactly the continued fraction expansion of . Therefore f is derivated from itself. Suppose now that is a Sturm number of the form [0, 1, a1 , a2 , . . . , an ], with an a1 . Then, by Lemma 17, the continued fraction expansion of 1 − is a Sturm number of the other form. Now, applying the first part of the proof we have that f1− is a derivated word of itself. Thus, E(f1− ) = f is also a derivated word of itself (see Remark 18). [(b)⇒(a)] Suppose that f starts by 0 and that the continued fraction expansion of is [0, a1 + 1, a2 . . .]
(3)
(in particular a1 1). Since f is a derivated word from itself, by Proposition 15, there exist m, i, with m > 0, such that the continued fraction expansion of is [0, am+1 + 1 − i, am+2 , am+3 , . . .].
(4)
Thus, a1 + 1 = am+1 + 1 − i, a2 = am+2 , a3 = am+3 , etc. That is, the continued fraction expansion of is [0, a1 + 1, a2 , . . . , am+1 ] and am+1 = a1 + i. Thus am+1 a1 . Therefore is a Sturm number. Suppose now that f starts with 1. Since f is a derivated word from f , E(f ) = f1− is also a derivated word of itself. Thus 1 − is a Sturm number and hence is also a Sturm number. [(b)⇒(c)] There exists a non-empty prefix w of f such that f = Dw (f ). Let u and v be the return words of w, and let (f ) denote the first letter of f . Hence, by Lemma 16, the morphism , defined by
((f )) = u, (1 − (f )) = v, verifies (f ) = f . [(c)⇒(b)] Let be a morphism such that (f ) = f . We want to show that (0), (1) are the return words of a non-empty prefix w of f . It will follow that Dw (f ) = f . Since has a fixed point which is a characteristic word, by [12, Proposition 2.3.11 and Theorem 2.3.12], {((0), (1)} is an unordered standard pair. In particular (0) and (1) are primitive words. Moreover, this pair is different from {0, 1} since is non-trivial. Claim. Any unordered standard pair, different from {0, 1}, is either {0, 0k 1}, {1, 1k 0}, or {u, uk u }, for some word u, some non-empty prefix u of u and k 1. Proof of Claim. The proof is by induction on the way standard pairs (u, v) are constructed. For the base case, the standard pairs different from (0, 1) are (10, 1) and (0, 01) which verify the claim. It is easy to check that if (u, v) verifies the claim, then the next pairs (vu, v) and (u, uv) also verify the claim.
216
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
Fig. 4. Occurrences i and i + |u| of w in f .
We start by considering the case |(0)| < |(1)|. Suppose first that (0) = u and (1) = uk u , with u a non-empty prefix of u and k 1. The word uk u is a prefix of f since 0a1 1 is a prefix of f , and (0a1 1) = ua1 +k u is a prefix of (f ) = f . Let us show that (0), (1) are the return words of w = uk u in f . The word 01 is clearly a factor of f (otherwise f would be ultimately periodic). Hence (01) = uk+1 u is also a factor of f . Therefore there is an occurrence i of w in f , with i 0, such that i + |u| is also an occurrence of w. The situation is represented in Fig. 4. There is no occurrence of w between i and i + |u| for otherwise u would be a strict factor of uu, contradicting its primitivity. Therefore (0) = u is a return word of w in f . As for the other return word, observe that there exists l 0 such that 10l 1 is a factor of f (otherwise f would be ultimately periodic). Thus (10l 1), and in particular uk u uk u = ww, are factors of f . Thus there are two occurrences j and j + |w| of w in f , for some j 0. There is no intermediate occurrence of w since w = (1) is primitive. It follows that (1) = uk u is the other return word of w in f . Suppose now that
(0) = 0 and (1) = 0k 1 and consider the prefix w = 0k of f . The proof is similar to the previous one. Thanks to the factor (01) of f , we verify that 0 = (0) is a return word of w in f . Thanks to the factor (10l 1) of f , we verify that 0k 1 = (1) is the other return word of w in f . The case (0) = 1 and (1) = 1k 0 is similar. Finally, if |(0)| > |(1)| the proof is analogous. Remark 22. In Theorem 21, statement (c) may be substituted by “f is a morphic word”. Indeed, a characteristic Sturmian word is morphic if and only if it is the fixed point of a (non-erasing, non-trivial) morphism. In order to prove this claim, let be a non-erasing, non-trivial morphism, and let f be a characteristic Sturmian word such that (f ) = f . Suppose, without loss of generality, that the first letter of f is 0. Then (0) = 0w, for some word w. Notice that w cannot be the empty word. Indeed, on one hand, it follows from the proof of Theorem 21 that both (0) and (1) should start by the same letter (in this case, 0). On the other hand if k is the first occurrence of 1 in f , that is 0k 1 is a prefix of f , then
(0k 1) = 0k (1). Since f is a fixed point of it follows that the first letter of (1) is 1, which is a contradiction. Thus w is non-empty and by [12, Theorem 1.2.8] (0) is the only fixed point of that starts with 0. Hence f = (0), and f is a morphic word.
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
217
Example 23. By Theorem 21, the word f from Example 19 is a morphic word since it is a derivated word of itself.
Acknowledgments The first author acknowledges the support of Fundação para a Ciência e a Tecnologia (Grant no. SFRH/BPD/11489/2002), and of the Centro de Álgebra da Universidade de Lisboa. Her participation in this work is partly part of the project POCTI Fundamental and Applied Algebra of Fundação para a Ciência e a Tecnologia and FEDER. She would also like to thank the hospitality of the Institut d’Informatique of the Université de Mons-Hainaut.
Appendix In this appendix we present the proofs of Propositions 3 and 4 for n ∈ {0, 1}. We start by the case n = 0, given by the following: Proposition 24. Let n = 0 and i ∈ {1, . . . , a1 }. Let w = 0i be the prefix of f of length in ]iq0 + q−1 − 2, (i + 1)q0 + q−1 − 2] = {i}. The shortest return word of w is t0 = 0, and its first occurrence is 0 if i < a1 , a2 q1 if i = a1 . The longest return word of w is t0i t−1 = 0i 1, and its first occurrence is (a1 − i)q0 . Proof. If a1 = 0 then the interval {1, . . . , a1 } is empty; thus we may assume that a1 > 0. Notice that (0a1 1)a2 0a1 +1 is a prefix of f . Studying this prefix it is clear that the two return words of w = 0i , are t0 = 0 and t0i t−1 = 0i 1. Moreover, the first occurrence of 0 as a return word of w is 0 if i = a1 and a2 q1 otherwise, while the first occurrence of 0i 1 is a1 − i = (a1 − i)q0 . The next proposition is Proposition 9 in the case n = 1. Proposition 25. Let n = 1 and i ∈ {1, . . . , a2 }. Let w be a prefix of f of length in the interval ]iq1 + q0 − 2, (i + 1)q1 + q0 − 2] = [iq1 , (i + 1)q1 − 1]. The shortest return word of w is t1 , and its first occurrence is 0 if i < a2 , a3 q2 if i = a2 . The longest return word of w is t1i t0 , and its first occurrence is (a2 − i)q1 .
218
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
Fig. 5. Illustration of an occurrence of t1i in ]a3 q2 , q3 [.
Proof. By Lemma 7, for each interval [iq1 , (i + 1)q1 − 1], it is enough to determine the return words for the prefix of w = t1i of f (notice that |w| ∈ [iq1 , (i + 1)q1 − 1]). It is easy to see that t2a3 t1i+1 is a prefix of f and t2a3 t1i+1 = t2a3 t1i t1 = t2a3 t1 t1i . Thus, a3 q2 and q3 are occurrences of t1i in f . Moreover, there is no occurrence of t1i in ]a3 q2 , q3 [. Indeed, if t1i occurred in that interval, we would obtain a situation as shown in Fig. 5 (the top line represents the prefix t2a3 t1 t1 of f , and the bottom line represents the beginning of an occurrence of t1i in ]a3 q2 , q3 [). We would hence have t1 as a strict factor of t1 t1 , contradicting the primitivity of t1 . Hence t1 is a return word of w in f . Now, by Lemma 6, t2 t1i t0 = t1a2 −i t1i t0 t1i t0 is also a prefix of f . Thus, both (a2 − i)q1 and q2 are occurrences of t1i in f . Moreover, there is no occurrence of t1i between (a2 − i)q1 and q2 . Indeed, remember that t1 = 0a1 1 and t0 = 0. Therefore t1i t0 is the longest return word of w in f . We now locate the first occurrence of the two return words of w. Let i < a2 . Since t2 = t1a2 t0 is a prefix of f , we see that 0, q1 , . . . , (a2 − i)q1 are occurrences of w = t1i in f . Therefore the shortest return word t1 occurs at position 0, and the first occurrence of the longest return word t1i t0 is greater than or equal to (a2 − i)q1 . Since we have already seen that (a2 − i)q1 is indeed an occurrence of the return word t1i t0 , we conclude that it is its first occurrence. Let now i = a2 . From the above we have that the first occurrence of the shortest return word t1 is bounded by a3 q2 . Let us see that t1 cannot appear before as a return word of w = t1a2 . It will also follow that the first occurrence of the longest return word t1a2 t0 = t2 is 0. Any occurrence of t1 as a return word of w corresponds to an occurrence of t1 w = t1a2 +1 . Now, if a1 = 0, then t1 = 1 and t2 = 1a2 0. Hence, considering the prefix t2a3 t1a2 +1 of f , it is clear that the first occurrence of t1 w in f is a3 q2 . On the other hand, if a1 > 0, then t2 is a prefix of t1 w. Thus, any occurrence of t1 w smaller than a3 q2 is of the form kq2 , with k ∈ {0, . . . , a3 − 1}, since t2 is primitive. Keeping in mind that t1 is a prefix of t2 , it follows that t1 = t0 t1 (see Fig. 6), which is not possible since t0 = 0 and t1 = 0a1 1.
I.M. Araújo, V. Bruyère / Theoretical Computer Science 340 (2005) 204 – 219
219
a
Fig. 6. Illustration of occurrences of t1 as a return word of t1 2 before a3 q2 .
References [1] J.P.Allouche, J. Shallit,Automatic Sequences—Theory,Applications, Generalizations, Cambridge University Press, Cambridge, 2003. [2] I.M. Araújo, V. Bruyère, Sturmian words and a criterium by Michaux–Villemaire. Theoret. Comput. Sci., in press, doi:10.1016/j.tcs.2005.01.010 (Appeared in Proc. Fourth Internat. Conf. on Words, Turku, Finland, 2003, pp. 83–94.) [3] P. Arnoux, G. Rauzy, Représentation géométrique de suites de complexité 2n + 1, Bull. Soc. Math. France 119 (2) (1991) 199–215. [4] J. Berstel, Recent results in Sturmian words, in: Developments in Language Theory, Vol. II, Magdeburg, 1995, World Science Publishing, River Edge, NJ, 1996, pp. 13–24. [5] J. Berstel, P. Séébold, Morphismes de Sturm, Bull. Belg. Math. Soc. Simon Stevin 1 (2) (1994) 175–189 (Journées Montoises, Mons, 1992.). [6] V. Berthé, Fréquences des facteurs des suites sturmiennes, Theoret. Comput. Sci. 165 (1996) 295–309. [8] D. Crisp, W. Moran, A. Pollington, P. Shiue, Substitution invariant cutting sequences, J. Théor. Nombres Bordeaux 5 (1) (1993) 123–137. [9] F. Durand, A characterization of substitutive sequences using return words, Discrete Math. 179 (1998) 89–101. [10] I. Fagnot, L. Vuillon, Generalized balances in Sturmian words, Discrete Appl. Math. 121 (1–3) (2002) 83–101. [11] T. Komatsu, A.J. van der Poorten, Substitution invariant Beatty sequences, Japan J. Math. (N.S.) 22 (2) (1996) 349–354. [12] M. Lothaire, Algebraic Combinatoric on Words, Encyclopedia of Mathematics and its Applications, Cambridge University Press, Cambridge, 2002. [13] C. Michaux, R. Villemaire, Presburger arithmetic and recognizability of sets of natural numbers by automata: new proofs of Cobham’s and Semenov’s theorems, Ann. Pure Appl. Logic 77 (1996) 251–277. [14] L. Vuillon, A characterization of Sturmian words by return words, European J. Combin. 22 (2) (2001) 263–275.
Theoretical Computer Science 340 (2005) 220 – 239 www.elsevier.com/locate/tcs
Codes of central Sturmian words夡 Arturo Carpia, c,∗ , Aldo de Lucab, c a Dipartimento di Matematica e Informatica dell’Università di Perugia, via Vanvitelli 1, 06123 Perugia, Italy b Dipartimento di Matematica e Applicazioni, Università di Napoli “Federico II”, via Cintia, Monte S. Angelo,
80126 Napoli, Italy c Istituto di Cibernetica del C. N. R. “E. Caianiello”, Pozzuoli (NA), Italy
Abstract A central Sturmian word, or simply central word, is a word having two coprime periods p and q and length equal to p + q − 2. We consider sets of central words which are codes. Some general properties of central codes are shown. In particular, we prove that a non-trivial maximal central code is infinite. Moreover, it is not maximal as a code. A central code is called prefix central code if it is a prefix code. We prove that a central code is a prefix (resp., maximal prefix) central code if and only if the set of its ‘generating words’ is a prefix (resp., maximal prefix) code. A suitable arithmetization of the theory is obtained by considering the bijection , called ratio of periods, from the set of all central words to the set of all positive irreducible fractions defined as: () = 1/1 and (w) = p/q (resp., (w) = q/p) if w begins with the letter a (resp., letter b), p is the minimal period of w, and q = |w| − p + 2. We prove that a central code X is prefix (resp., maximal prefix) if and only if (X) is an independent (resp., independent and full) set of fractions. Finally, two interesting classes of prefix central codes are considered. One is the class of Farey codes which are naturally associated with the Farey series; we prove that Farey codes are maximal prefix central codes. The other is given by uniform central codes. A noteworthy property related to the number of occurrences of the letter a in the words of a maximal uniform central code is proved. © 2005 Elsevier B.V. All rights reserved. Keywords: Sturmian word; Code; Central word
夡 The work for this paper has been supported by the Italian Ministry of Education under Project COFIN 2003 Linguaggi Formali e Automi: metodi, modelli e applicazioni.
∗ Corresponding author. Dipartimento di Matematica e Informatica dell’Università di Perugia, via Vanvitelli 1,
06123 Perugia, Italy. E-mail addresses:
[email protected] (A. Carpi),
[email protected] (A. de Luca). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.021
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
221
1. Introduction Sturmian words are infinite sequences of symbols taken from a finite alphabet which are not eventually periodic and have the minimal possible value for the subword complexity, i.e., for any integer n 0 the number of the subwords of length n of any Sturmian word is equal to n + 1. Sturmian words are of great interest both from the theoretical and applicative point of view, so that there exists a large literature on the subject. We refer to the recent overviews on Sturmian words by Berstel and Séébold [4, Chapter 2] and by Allouche and Shallit [1, Chapters 9–10]. A geometrical definition of a Sturmian word is the following: consider the sequence of the cuts (cutting sequence) in a squared-lattice made by a ray having a slope which is an irrational number. A horizontal cut is denoted by the letter b, a vertical cut by a and a cut with a corner by ab or ba. Sturmian words represented by a ray starting from the origin are usually called standard or characteristic. The most famous Sturmian word is the Fibonacci word f = abaababaabaababaababaabaababaabaab · · · , which is the limit of the sequence of words (fn )n 0 , inductively defined as f0 = b, f1 = a, and fn+1 = fn fn−1 for n 1 . Standard Sturmian words can be equivalently defined in the following way which is a natural generalization of the definition of the Fibonacci word. Let c0 , c1 , . . . , cn , . . . be any sequence of integers such that c0 0 and ci > 0 for i > 0. We define, inductively, the sequence of words (sn )n 0 , where c
s0 = b, s1 = a, and sn+1 = snn−1 sn−1 for n 1 . The sequence (sn )n 0 converges to a limit s which is an infinite standard Sturmian word. Any standard Sturmian word is obtained in this way. We shall denote by Stand the set of all the words sn , n 0 of any standard sequence (sn )n 0 . Any word of Stand is called finite standard Sturmian word, or generalized Fibonacci word. In the study of combinatorial properties of Sturmian words a very important role is played by the set PER of all palindromic prefixes of all standard Sturmian words. The words of PER have been called central Sturmian words, or simply central words, in [4]. It has been proved in [6] that a word is central if and only if it has two coprime periods p and q and length equal to p + q − 2. In this paper, we consider sets of central words which are codes, i.e., bases of free submonoids of {a, b}∗ . There are several motivations for this research. From the theoretical point of view central codes have interesting combinatorial properties. In particular, a suitable arithmetization of the theory can be given. Moreover, the words of a central code are palindromes which satisfy some strong constraints which can be useful for the applications (coding with constraints [10], error correcting codes). Finally, we believe that these codes can be of some interest in discrete geometry (for instance to represent polygonals in a discrete plane). In Section 4 some general properties of central codes are shown. In particular, we prove that a non-trivial maximal central code X is PER-complete, i.e., any central word is a factor
222
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
of a word of X ∗ . As a consequence of this proposition and of some technical lemmas, we prove that a non-trivial maximal central code is infinite. Moreover, it is not maximal as a code. In Section 5, we consider prefix central codes, i.e., central codes such that no word of the code is a prefix of another word of the code. We prove that a central code is a prefix (resp., maximal prefix) central code if and only if the set of its ‘generating words’ is a prefix (resp., maximal prefix) code. A suitable arithmetization of the theory is obtained by considering the bijection , called ratio of periods, from the set of all central words to the set I of all positive irreducible fractions defined as: () = 11 and (w) = p/q (resp., (w) = q/p) if w begins with the letter a (resp., letter b), p is the minimal period of w, and q = |w| − p + 2. A suitable derivation relation on the set I is introduced. A subset H of I is called independent if no fraction of the set can be derived from another one. A subset H of I is called full if for any element p/q of I either from p/q one can derive an element of H or there exists an element of H from which one can derive p/q. We prove that a central code X is prefix (resp., maximal prefix) if and only if (X) is an independent (resp., independent and full) set of fractions. In Section 6, we consider for any positive integer n the set n of all central words w having minimal period p, q = |w| − p + 2 n + 1, and |w| n. One can prove that for each n, n is a maximal prefix central code called the Farey code of order n since it is naturally associated with the Farey series of order n. Finally, in Section 7, we consider the class of uniform central codes. A central code is uniform of order n if all the words of the code have length equal to n. For any n the maximal uniform central code of order n is given by Un = PER ∩ {a, b}n . The following noteworthy property, related to the number of occurrences |w|a of the letter a in a word w of a maximal uniform central code Un , is proved: for any k, 0 k n there exists a (unique) word w ∈ Un such that |w|a = k if and only if gcd(n + 2, k + 1) = 1. 2. Preliminaries Let A be a finite non-empty set, or alphabet, and A∗ the free monoid generated by A. The elements of A are usually called letters and those of A∗ words. The identity element of A∗ is called empty word and denoted by . We set A+ = A∗ \ {}. A word w ∈ A+ can be written uniquely as a sequence of letters as w = w1 w2 · · · wn , with wi ∈ A, 1 i n, n > 0. The integer n is called the length of w and denoted |w|. The length of is 0. For any w ∈ A∗ and a ∈ A, |w|a denotes the number of occurrences of the letter a in w. Let w ∈ A∗ . The word u is a factor (or subword) of w if there exist words p, q such that w = puq. A factor u of w is called proper if u = w. If w = uq, for some word q (resp., w = pu, for some word p), then u is called a prefix (resp., a suffix) of w. For any w ∈ A∗ , we denote by Fact w, the sets of its factors. For any X ⊆ A∗ , we set Fact X = Fact u. u∈X
An element of Fact X will be also called a factor of X.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
223
A set X is called dense if any word of A∗ is a factor of X. A set which is not dense is called thin. If X is a finite set we denote by (X) the maximal length of the words of X. Any word of A∗ of length greater than (X) is not a factor of X, so that X is thin. Let Y ⊆ A∗ . A set X is called Y-complete if Y ⊆ Fact X ∗ . A set X which is A∗ -complete, i.e., such that X∗ is dense, is called simply complete. Let p be a positive integer. A word w = w1 · · · wn , wi ∈ A, 1 i n, has period p if the following condition is satisfied: for all 1 i, j n, if i ≡ j (mod p), then wi = wj . From the definition one has that any integer q |w| is a period of w. As is well known, a word w has a period p |w| if and only if there exist words u, v, s such that w = us = sv ,
|u| = |v| = p .
We shall denote by w the minimal period of w. We can uniquely represent w as w = rkr , where |r| = w , k 1, and r is a proper prefix of r. We shall call r the fractional root or, simply, root of w. Let w = w1 · · · wn , wi ∈ A, 1 i n. The reversal of w is the word w ∼ = wn · · · w1 . One defines also ∼ = . A word is called palindrome if it is equal to its reversal. A code X over a given alphabet A is the base of a free submonoid of A∗ , i.e., any nonempty word of X∗ can be uniquely factorized by words of X (cf. [3]). A code X over A is prefix (resp., suffix) if no word of X is a prefix (resp., suffix) of another word of X. A code is biprefix if it is both prefix and suffix. A code X over the alphabet A is maximal if it is not properly included in another code on the same alphabet. As is well known any maximal code is complete. Conversely, a thin and complete code is maximal. A prefix code is a maximal prefix code if it is not properly included in another prefix code on the same alphabet. The following two lemmas will be useful in the sequel. Lemma 1. Let X be a code over the alphabet A and w ∈ A∗ be a word having root . If ∈ Fact X∗ , then X ∪ {w} is a code. Proof. Suppose that Y = X ∪ {w} is not a code. There would exist h, k > 0 and words y1 , . . . , yh , y1 , . . . , yk ∈ Y such that y1 = y1 and y1 · · · yh = y1 · · · yk . Since X is a code and w does not belong to Fact X ∗ , one easily derives that w has to occur in both sides of the previous equation, i.e., there exist minimal positive integers i and j such that w = yi = yj . Setting u = y1 · · · yi−1 and v = y1 · · · yj −1 , one has uw = vw with u, v ∈ X∗ , u = v, and , ∈ Y ∗ .
224
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
With no loss of generality, we can assume |u| > |v|. Then one has u = v , w = w , ∈ A+ . From this latter equation one obtains
w = w with ∈ A+ . This equation shows that || is a period of w and then of w, so that || ||. Thus, is a prefix of and, consequently a factor of u = v . Hence ∈ Fact X ∗ , which is a contradiction. Lemma 2. Let X be a prefix code over the alphabet A and w ∈ A∗ be a word such that wA∗ ∩ X ∗ = ∅. Then Y = X ∪ {w} is a code. Proof. Suppose that Y is not a code. There would exist h, k > 0 and words y1 , . . . , yh , y1 , . . . , yk ∈ Y such that y1 = y1 and y1 · · · yh = y1 · · · yk . Since X is prefix one has y1 = w or y1 = w. Without loss of generality, we may suppose that y1 = w. Since wA∗ ∩ X∗ = ∅ there exists j 2 such that y1 , . . . , yj −1 ∈ X and yj = w. Hence, one has y1 · · · yj −1 = u ∈ X+ and uw = wv,
with v ∈ A∗ .
Let n be a positive integer such that |un | |w|. One has un w = wv n so that un = w for a suitable ∈ A∗ . Thus, wA∗ ∩ X ∗ = ∅, which is a contradiction. 3. Central words In the study of combinatorial properties of Sturmian words a crucial role is played by the set PER of all finite words w having two periods p and q such that gcd(p, q) = 1 and |w| = p + q − 2. We assume that ∈ PER (this is formally coherent with the definition if one takes p = q = 1) The set PER was introduced in [6] where its main properties were studied. In particular, it has been proved that PER is equal to the set of the palindromic prefixes of all standard Sturmian words. The words of PER have been called central in [4]. As is well known, central words are in a two-letter alphabet {a, b} that, in the sequel, will be denoted by A. The set PER has remarkable structural properties. The set of all finite factors of all Sturmian words equals the set of factors of PER. Moreover, the set Stand of all finite standard Sturmian words is given by Stand = A ∪ PER{ab, ba} .
(1)
Thus, any finite standard Sturmian word which is not a single letter is obtained by appending ab or ba to a central word. The following useful characterization of central words is a slight generalization of a statement proved in [5] (see also [8]). We report the proof for the sake of completeness.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
225
Proposition 3. A word w is central if and only if w is a power of a single letter of A or it satisfies the equation: w = w1 abw2 = w2 baw1
(2)
with w1 , w2 ∈ A∗ . Moreover, in this latter case, w1 and w2 are central words, p = |w1 |+2 and q = |w2 | + 2 are coprime periods of w, and min{p, q} is the minimal period of w. Proof. In view of the results of [5, Lemma 4], it is sufficient to prove that any word w satisfying Eq. (2) is a central word. Indeed, in such a case, w has the two periods p = |w1 ab| and q = |w2 ba|, and |w| = p + q − 2. Moreover, gcd(p, q) = 1. In fact, suppose that gcd(p, q) = d 2. By the theorem of Fine and Wilf (see, e.g., [9]) the word w will have the period d. Thus, w1 ab = zp/d and w2 ba = zq/d , where z is the prefix of w of length d. We reach a contradiction since from the first equation the last letter of z has to be b, while from the second equation it has to be a. Since p and q are coprime, the word w is central. Finally, we observe that since w is palindrome, w1 and w2 are palindromes and prefixes of a central word, so that they are central words. The following corollary will be useful in the sequel. Corollary 4. If w ∈ PER has the factor x n with x ∈ A and n > 0, then x n−1 is a prefix (and suffix) of w. Proof. We can assume, with no loss of generality, that x = a. If w is a power of a letter, the statement is trivially true. If, on the contrary, w is not a power of a letter, then by Proposition 3, w = w1 abw2 = w2 baw1 with w1 , w2 ∈ PER. The word a n is a factor of w2 or of w1 or a prefix of aw1 . In the first two cases, by making induction on the length of |w|, we can assume that w2 or w1 has the prefix a n−1 ; in the third case, w1 has the prefix a n−1 . Thus, in all cases, a n−1 is a prefix of w. For any word w we denote by w (−) the shortest palindrome having the suffix w. The word w(−) is called the palindromic left-closure of w. For any set of words X, we set X(−) = {w (−) | w ∈ X}. The following lemmas were proved in [5]. Lemma 5. For any w ∈ PER, one has (aw)(−) , (bw)(−) ∈ PER. More precisely, if w = w1 abw2 = w2 baw1 , then (aw)(−) = w2 baw1 abw2 ,
(bw)(−) = w1 abw2 baw1 .
If w = x n with {x, y} = A, then (xw)(−) = x n+1 , (yw)(−) = x n yx n . Lemma 6. Let u, w ∈ PER and x ∈ A. If ux is a prefix of w, then also (xu)(−) is a prefix of w.
226
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
By Proposition 3 and Lemma 5 one easily derives that if u = (xw)(−) with w ∈ PER and x ∈ A, then |u| = u + |w| .
(3)
The following method to generate central words was introduced in [5]. By the preceding lemma, we can define the map
: A∗ → PER as follows: () = and for all v ∈ A∗ , x ∈ A,
(vx) = (x (v))(−) . The map : A∗ → PER is a bijection. The word v is called the generating word of (v). One has that for all v, u ∈ A∗
(vu) ∈ A∗ (v) ∩ (v)A∗ .
(4)
Example 7. Let w = abba. One has
(a) = a ,
(ab) = aba ,
(abb) = ababa ,
(abba) = ababaababa . As usually, one can extend to the subsets of A∗ by setting, for all X ⊆ A∗ , (X) = { (x) | x ∈ X}. In particular, one has (aA∗ ) = PERa and (bA∗ ) = PERb , where PERa = PER ∩ aA∗
and PERb = PER ∩ bA∗ .
Let I be the set of all irreducible positive fractions. We consider the map : PER → I, called the ratio of periods, defined as follows: let w ∈ PER \ {ε}, p be the minimal period of w, and q = |w| + 2 − p. We set
(w) = p/q if w ∈ PERa ,
(w) = q/p if w ∈ PERb .
Moreover,
(ε) =
1 1
.
As is well known [5] the map is a bijection. We recall that for all w ∈ PER, the numbers |w|a + 1 and |w|b + 1 are coprime. Moreover the function : PER → I defined, for any w ∈ PER, by
(w) =
|w|b + 1 |w|a + 1
is a bijection [2], called slope. Since and are both bijections, the values of each of them is determined from the other.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
227
We introduce in I the binary relation ⇒ defined as follows: for p/q, r/s ∈ I, one sets r p ⇒ q s
if
p q , r ∈ {p, q} , s = p + q ,
or
p q , s ∈ {p, q} , r = p + q .
One easily verifies that the graph of this relation is a complete binary tree with root 11 . We denote by ⇒∗ the reflexive and transitive closure of ⇒. For instance, one has 21 ⇒ 23 ⇒ 2 5 1 ∗ 5 5 ⇒ 7 , so that 2 ⇒ 7 . From Lemma 5 one derives that for any w, w ∈ PER one has
(w) ⇒ (w ) if and only if w = (xw)(−) , with x ∈ A .
(5)
We say that a subset H of I is independent if for any pair of fractions p/q, r/s ∈ H such that p/q ⇒∗ r/s one has p/q = r/s. A subset H of I is full if for any fraction p/q ∈ I there exists a fraction r/s ∈ H such that p/q ⇒∗ r/s or r/s ⇒∗ p/q. One introduce the Farey map Fa = ◦ . Thus for any x ∈ A∗ one has Fa(x) = ( (x)) ∈ I. Since and are bijections, also Fa will be so. Lemma 8. Let x, x ∈ A∗ . One has that Fa(x) ⇒∗ Fa(x ) if and only if x is a prefix of x . Proof. It is sufficient to prove that for any pair of words x, x ∈ A∗ , one has Fa(x) ⇒ Fa(x ) if and only if x ∈ xA. We suppose that x ∈ aA∗ (the case where x ∈ bA∗ or x = ε can be dealt with similarly). We set Fa(x) = p/q. Therefore, by Eq. (5), {Fa(xa), Fa(xb)} =
q p , p+q p+q
.
Thus, p/q ⇒ Fa(x ) if and only if Fa(x ) ∈ {Fa(xa), Fa(xb)}. Since Fa is a bijection, this last condition is equivalent to x ∈ xA. Corollary 9. A set X ⊆ A+ is a prefix code if and only if Fa(X) is an independent set. Proof. Let x and x be two distinct elements of X. By the previous lemma, x is a proper prefix of x if and only if Fa(x) ⇒∗ Fa(x ). This implies that X is a prefix code if and only if Fa(X) is an independent set. Corollary 10. A prefix code X ⊆ A∗ is maximal if and only if Fa(X) is a full set. Proof. A prefix code X is maximal if and only if for any word w ∈ A∗ there exists a word x ∈ X such that either w is a prefix of x or x is a prefix of w. By Lemma 8 this occurs if and only if Fa(w) ⇒∗ Fa(x) or Fa(x) ⇒∗ Fa(w). This implies that X is a maximal prefix code if and only if Fa(X) is a full set.
228
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
4. Central codes In this section we shall consider sets of central words which are codes. These codes, which are in a two-letter alphabet, will be called Sturmian central codes or, simply, central codes. For instance the sets X1 = {a, b}, X2 = {b, aa, aba}, X3 = {aa, aabaa, babbab}, and X4 = {b2 } ∪ (ab)∗ a are central codes. Proposition 11. A central code is thin. Proof. This is a consequence of the fact that the set PER is thin. Indeed, for instance, as is well known, the word aabb is not a factor of any Sturmian word. A central code is maximal if it is not properly included in another central code. By using a classical argument based on the Zorn property, which is satisfied by the family of central codes, one easily derives that any central code is included in a maximal central code. Proposition 12. A maximal central code is PER-complete. Proof. Let X be a maximal central code. By contradiction, suppose that there exists a word f ∈ PER such that f ∈ Fact X ∗ . Let p be the minimal period of f and q = |f | − p + 2. If v is the generating word of f, by Eqs. (5) and (4) one derives that there exist letters x, y ∈ A such that g = (vxy) ∈ PER has minimal period p + q and prefix f. Thus, f is a prefix of the root of g, so that ∈ Fact X∗ . By Lemma 1, X ∪ {g} should be a code which is central, contradicting the maximality of X as central code. Now, we shall prove (cf. Corollary 18) that the unique finite maximal central code is A. We need some preliminary technical lemmas. Lemma 13. Let X be a central code and u ∈ A∗ . The following statements hold: (1) If baau ∈ X∗ , then b ∈ X and aau ∈ X ∗ . (2) If X = A and aba 3 u ∈ X∗ , then aba ∈ X and aau ∈ X ∗ . Proof. If baau ∈ X∗ , there exist v ∈ X∗ and x ∈ X such that baau = xv . By Corollary 4 no central word has the prefix baa so that x is necessarily a proper prefix of baa. Hence, since X is a central code, x = b and v = aau ∈ X∗ . If aba 3 u ∈ X∗ , there exist v ∈ X∗ and x ∈ X such that aba 3 u = xv . By Corollary 4 no central word has the prefix aba 3 so that x is necessarily a proper prefix of aba 3 , i.e., x = aba or a. In the first case, v = aau ∈ X ∗ . In the second case, v = ba 3 u so that, by Statement 1 one has b ∈ X, i.e., X = A.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
229
Lemma 14. Let X be a finite PER-complete central code. Then a ∈ X or b ∈ X. Proof. Consider the word w = (aab)n aaa(baa)n with 3n (X). As one easily verifies, w = (a 2 bn a), so that w ∈ PER. Since X is PERcomplete, there exist words , ∈ A∗ such that w ∈ X ∗ . We have to distinguish three cases: (1) (aab)n a, aa(baa)n ∈ X∗ , (2) (aab)n aa, a(baa)n ∈ X∗ , (3) (aab)n = u, (baa)n = v with x = uaaav ∈ X, , ∈ X∗ , u, v ∈ A∗ . Let us consider Case 1. If a ∈ X, then the statement is true. Thus suppose a ∈ X. Since (X) 3n one derives that the first factor in the X-factorization of aa(baa)n , which has to be a palindrome, has the form aa(baa)i with 0 i < n. This implies that (baa)n−i ∈ X∗ . By Lemma 13 one derives b ∈ X. Case 2 can be dealt with symmetrically. Now let us consider Case 3. As x ∈ PER has the factor aaa, by Corollary 4 it must have the suffix aa. Since (baa)n = v and |v| < (X) 3n, one derives v = (baa)i with 0 i < n. This implies that = (baa)n−i ∈ X ∗ . By Lemma 13 one obtains again b ∈ X. Lemma 15. Let X be a finite PER-complete central code. Then one has b ∈ X or aba ∈ X. Symmetrically, one has a ∈ X or bab ∈ X. Proof. Consider the word w = (aaab)n aaa with 4(n − 1) (X). As one easily verifies, w = (a 3 bn ), so that w ∈ PER. Since X is PER-complete, there exist words , ∈ A∗ such that w ∈ X ∗ . Since (X) 4(n − 1), one has
(aaab)i a p , a q (baaa)j ∈ X∗ with i, j 1, i + j = n, p, q 0, and p + q = 3. We distinguish three cases, according to the values of q. Case q = 0. As (baaa)j ∈ X∗ , by Lemma 13 it follows that b ∈ X. Case q = 1. If X = A, then trivially, b ∈ X. If, on the contrary, X = A, since a(baaa)j ∈ X∗ , by Lemma 13 one derives aba ∈ X. Case q > 1. Since p = 3 − q 1 and a p (baaa)i ∼ ∈ X ∗ , one reaches the result by a similar argument. Lemma 16. Let X be a finite PER-complete central code. Then there exist h, k 0 such that (ab)h a, (ba)k b ∈ X.
230
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
Proof. Consider the word w = (ab)n a with n such that |w| = 2n + 1 3(X). As one easily verifies, w = (abn ), so that w ∈ PER. Since X is PER-complete, there exist words , ∈ A∗ such that w ∈ X ∗ . Since |w| 3(X), one derives that w has a factor in X 2 , i.e., w = xy , with x, y ∈ X and , ∈ A∗ . We shall suppose | | even (the opposite case is similarly dealt with). One has
= (ab)i ,
xy = (ab)n−i a,
0i < n .
As x is a palindrome, one obtains x = (ab)h a,
y = (ba)n−i−h ,
0h < n − i
and, similarly, y = (ba)k b,
= a(ba)n−i−h−k−1 ,
which concludes the proof.
0k < n − i − h ,
Proposition 17. Let X be a finite PER-complete central code. Then X = A. Proof. If a, b ∈ X, then X = A and the statement holds true. Let us then suppose that b ∈ X. By Lemma 14, one has a ∈ X and, by Lemma 15, aba ∈ X. Moreover, by Lemma 16, there exists k > 0 such that (ba)k b ∈ X. This yields a contradiction as the word (ab)k+2 a has two distinct X-factorizations, namely, (a) ((ba)k b) (aba) = (aba) ((ba)k b) (a) .
By the previous proposition and Proposition 12 it follows: Corollary 18. Let X be a finite maximal central code. Then X = A. The following proposition gives an example of an infinite maximal central code. The proof, which is rather technical, is reported in the appendix. Proposition 19. The set X = PER \ D, where D= ((ab)i a)∗ ∪ ((ba)i b)∗ , i 0
is a maximal central code. Proposition 20. There exists a PER-complete central code which is not a maximal central code.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
231
Proof. Let X = PER \ D be the maximal central code considered in Proposition 19 and set Y = X \ {aabaa} . Since the word aabaa is a factor of aabaabaa ∈ Y , one has Fact X = Fact Y . Let us prove that for any z ∈ D one has z ∈ Fact X. We can assume with no loss of generality that z = ((ab)i a)j , with i, j 0. Moreover, we can suppose j 2 since (ab)i a is a factor of ((ab)i a)2 . As one easily verifies, (bz)(−) = ((ab)i a)j ba((ab)i a)j −1 ∈ PER \ D = X , so that z ∈ Fact X. Thus D ⊆ Fact X. Since PER = X ∪ D, it follows PER ⊆ Fact X = Fact Y . Therefore, in view of the previous proposition, Y is a PER-complete code which is not a maximal central code. Lemma 21. The pairs (b2 , a 2 ) and (a 2 , b2 ) are synchronizing pairs of any central code X, i.e., for all u, v ∈ A∗ , ub2 a 2 v ∈ X∗ ⇒ ub2 , a 2 v ∈ X∗ ,
ua 2 b2 v ∈ X∗ ⇒ ua 2 , b2 v ∈ X∗ .
Proof. Since b2 a 2 is not a factor of PER, if ub2 a 2 v ∈ X∗ , then one of the following three cases occurs: ub, ba 2 v ∈ X∗ , ub2 , a 2 v ∈ X∗ , ub2 a, av ∈ X ∗ .
(6) (7) (8)
If Eq. (6) holds, then by Lemma 13 one has b, a 2 v ∈ X ∗ so that Eq. (7) is satisfied. If Eq. (8) holds, one obtains ab2 u∼ ∈ X ∗ so that by Lemma 13 one obtains a ∈ X and b2 u∼ ∈ X∗ . Hence, ub2 ∈ X∗ so that Eq. (7) is satisfied again. This proves that (b2 , a 2 ) is a synchronizing pair. In a symmetric way one proves that also (a 2 , b2 ) is a synchronizing pair. Proposition 22. A central code X = A is not complete. Proof. Let X be a complete central code. We consider the word a 2 b2 a 3 b3 a 2 b2 . There exist u, v ∈ A∗ such that ua 2 b2 a 3 b3 a 2 b2 v ∈ X∗ . By the preceding lemma, one derives b2 , b3 , a 2 , a 3 ∈ X∗ . Since X is a code, it follows a, b ∈ X∗ , i.e., X = A. As any maximal code is complete, by the previous proposition, one derives that a central code X = A is not maximal as code.
232
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
5. Prefix central codes In this section, we shall consider central codes which are prefix codes. Since the words of such codes are palindromes, one has that a prefix central code is also a suffix code and then a biprefix code. For instance, the set X = {a, bab, bb} is a prefix central code. Proposition 23. A central code Y is prefix if and only if Y = (X), with X a prefix code. Proof. Let Y = (X). If X is a prefix code, then, as proved in [5], Y is a prefix code. Conversely, suppose that X is not a prefix code. Then there exist x1 , x2 ∈ X and ∈ A+ such that x1 = x2 . By Eq. (4), (x1 ) = (x2 ) = (x2 ) for a suitable ∈ A+ . Hence, Y is not a prefix code. We call pre-code of a prefix central code Y the prefix code X such that Y = (X). For instance, the pre-code of {a, bab, bb} is the prefix code {a, ba, bb} and the pre-code of the prefix central code {aba, bb, babab, babbab} is the prefix code {ab, bb, baa, bab}. The pre-code of the prefix central code {a n ba n | n 0} is the prefix code a ∗ b. For any X ⊆ A∗ and all n > 1 we set n (X) = ( n−1 (X)), where 1 (X) = (X). From Proposition 23 one derives the following: Corollary 24. If X is a prefix code, then for all n 1, n (X) is a prefix central code. Proposition 23 shows that the property of being a prefix code is preserved by and −1 . On the contrary, the property of being a code is not, in general, preserved by or −1 , as shown by the following example. Example 25. The set X = {ab, ba, abbb} is a code whereas the set (X) = {aba, bab, abababa} is not a code. Conversely, the set X = {a, ab, bab} is not a code whereas
(X) = {a, aba, babbab} is a code. Proposition 26. A central code Y is prefix if and only if (Y ) is an independent set. Proof. By Proposition 23, Y is prefix if and only if Y = (X), with X a prefix code. By Corollary 9, this occurs if and only if Fa(X) = (Y ) is an independent set. A prefix central code is a maximal prefix central code if it is not properly included in another prefix central code. Proposition 27. A prefix central code X is a maximal prefix central code if and only if for all w ∈ PER, wA∗ ∩ XA∗ = ∅. Proof. If there exists w ∈ PER such that wA∗ ∩ XA∗ = ∅, then X ∪ {w} is a prefix central code properly containing X, so that X is not a maximal prefix central code.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
233
If X is not a maximal prefix central code, there exists at least one word w ∈ PER such that w is not a prefix of any word of X and no word of X is a prefix of w. This implies that wA∗ ∩ XA∗ = ∅. Proposition 28. A prefix central code is a maximal prefix central code if and only if its pre-code is a maximal prefix code. Proof. Let Y be a maximal prefix central code and X be its pre-code. By Proposition 23, X is a prefix code. Suppose that X is properly included in a prefix code X over A. Since is a bijection, Y = (X) ⊂ (X ). By Proposition 23, (X ) is a prefix central code which properly contains Y, which contradicts the maximality of Y as prefix central code. Conversely, suppose that the pre-code X of the prefix central code Y is a maximal prefix code. If Y is properly included in another prefix central code Y one would have X ⊂
−1 (Y ). By Proposition 23, −1 (Y ) is a prefix code, so that we reach a contradiction with the maximality of X. Proposition 29. A central code Y is a maximal prefix central code if and only if (Y ) is an independent and full set. Proof. By Propositions 23 and 28, Y is a maximal prefix central code if and only if Y =
(X), with X a maximal prefix code. By Corollaries 9 and 10, this occurs if and only if Fa(X) = (Y ) is an independent and full set. Remark 30. We observe that a maximal prefix central code X = A is not maximal as prefix code. Indeed, as is well known, any maximal prefix code is right-complete, i.e., for any w ∈ A∗ , wA∗ ∩ X ∗ = ∅, whereas by Proposition 22 a prefix central code X = A is not even complete. By Corollary 18, a finite maximal prefix central code X = A cannot be maximal as central code. More generally, we shall see (cf. Corollary 32) that any non-trivial maximal central code cannot be prefix. Proposition 31. Let X = A be a prefix central code. There exists w ∈ PER such that wA∗ ∩ X ∗ = ∅. Proof. Let x ∈ X. Without loss of generality, we may suppose that the first letter of x is a. There exists a word u ∈ A∗ such that y = xbaau ∈ PER. Indeed, by Eq. (1), xba is a finite standard Sturmian word so that z = xbaxba is a prefix of a standard Sturmian word; since xbaa is a prefix of z, it is a prefix of a word of PER. If yA∗ ∩ X ∗ = ∅, the statement is proved. Let us then suppose that yA∗ ∩ X ∗ = ∅. Thus there exists v ∈ A∗ such that yv = xbaauv ∈ X∗ . Since X is a prefix code, one has baauv ∈ X ∗ and by Lemma 13, b ∈ X. Now, let us consider the word bbabb = (bba) ∈ PER. If bbabbA∗ ∩ X ∗ = ∅, the statement is proved. Suppose that bbabbA∗ ∩ X ∗ = ∅. Since b ∈ X and X is a prefix code, it follows that abbA∗ ∩ X ∗ = ∅. By Lemma 13 one obtains a ∈ X, i.e., X = A, which is a contradiction. By Lemma 2 and Proposition 31 one derives the following:
234
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
Corollary 32. A prefix central code X = A is not a maximal central code. 6. Farey codes For any positive integer n, we consider the set p Fn = ∈ I 1p q n . q As is well known, by ordering the elements of Fn in an increasing way, one obtains the Farey series of order n (cf. [7]). Now, set p Gn = ∈ Fn+1 p + q − 2 n q and
n,a = {s ∈ PERa | (s) ∈ Gn } ,
n,b = {s ∈ PERb | (s)−1 ∈ Gn } .
The set n = n,a ∪ n,b is a prefix central code [5] called the Farey code of order n. The words of n,b are obtained from those of n,a by interchanging the letter a with b. The pre-codes of n,a , n,b , and n will be respectively denoted by Fn,a , Fn,b , and Fn . The prefix code Fn = Fn,a ∪ Fn,b will be called the Farey pre-code of order n. Example 33. In the following table, we report the elements of G6 with the corresponding words of the prefix code 6,a and their lengths. In the last column, are reported the elements of the pre-code F6,a . 1 6 aaaaaa 7 aaaaaa 2 7 3 7 4 7 3 5 5 7 4 5 5 6 6 7
abababa
7 abbb
aabaabaa
8 aabb
aabaaabaa
9 aaba
abaaba
6 aba
ababaababa 10 abba aaabaaa
7 aaab
aaaabaaaa
9 aaaab
aaaaabaaaaa 11 aaaaab
Some interesting properties of Farey codes have been proved in [5]. We limit ourselves to recall that for all n > 0, Card n =
n+1 i=1
(i) ,
where is the totient Euler’s function.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
235
Proposition 34. For all n 1, the Farey code of order n is a maximal prefix central code. Proof. We shall prove that the set (n ) is independent and full, so that the result will follow from Proposition 29. One has that (n ) = {p/q | p/q ∈ Gn or q/p ∈ Gn }. First, we prove the independence. Let p/q and r/s be distinct elements of (n ) such that p/q ⇒∗ r/s. We suppose p < q (the case where p > q is similarly dealt with). There exists a sequence of irreducible fractions pi /qi , i = 1, . . . , m, such that pm r p1 p ⇒ ··· ⇒ = . ⇒ q q1 qm s Hence, q1 = p + q n + 2, so that s = qm q1 n + 2 and r < s. This contradicts the assumption that r/s ∈ (n ). Now, we prove the fullness of (n ). Let r/s be an element of I. We suppose r < s (the cases where r > s or r = s = 1 are similarly dealt with). First we consider the case that s n + 2. There exists a sequence of irreducible fractions pi /qi , i = 1, . . . , m, such that pm r p1 1 ⇒ ··· ⇒ = . ⇒ 1 q1 qm s Let k be the minimal integer such that qk n + 2. One has qk−1 n + 1 and pk−1 + qk−1 = qk n + 2, so that pk−1 /qk−1 ∈ Gn and pk−1 /qk−1 ⇒∗ r/s. Now, we consider the case that s < n + 2. Let k be the minimal integer such that kr + s n + 2. One has (k − 1)r + s n + 1 so that r/((k − 1)r + s) ∈ Gn and r/s ⇒∗ r/((k − 1)r + s). As a consequence of Proposition 23 one has: Proposition 35. For all n 1, the Farey pre-code of order n is a maximal prefix code. The following proposition gives an equivalent definition for Farey codes. Proposition 36. For any n > 0 one has
n = {w ∈ PER | n |w| n + w − 1} . Proof. First we suppose w ∈ PERa and set (w) = p/q, so that p = w and q = |w| − w + 2. One has w ∈ n,a if and only if p/q ∈ Fn+1 and p + q − 2 = |w| n. Since p/q ∈ Fn+1 if and only if q = |w| − w + 2 n + 1, one derives that w ∈ n,a if and only if n |w| n + w − 1. If w ∈ PERb , by a similar argument one obtains that w ∈ n,b if and only if n |w| n+ w − 1. From this the assertion follows. From Proposition 36 one derives immediately that for all n > 0,
n+1 \ n = {w ∈ PER | |w| = n + w }
(9)
236
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
and
n \ n+1 = Un ,
(10)
where Un = PER ∩ An . The following proposition shows a relation between Farey codes of consecutive orders. Proposition 37. For any n > 0 one has
n+1 = (n \ Un ) ∪ (AUn )(−) . Proof. From Eqs. (9) and (10) one derives
n+1 = (n \ Un ) ∪ {w ∈ PER | |w| = n + w } . Thus it is sufficient to prove that (AUn )(−) = {w ∈ PER | |w| = n + w } .
(11)
Let us suppose w = (xv)(−) , with x ∈ A and v ∈ Un . Then w ∈ PER and by Eq. (3), |w| = w + n. This proves the inclusion “⊆”. Conversely, suppose that w ∈ PER and |w| = n + w . Let u ∈ PER and x ∈ A be such that w = (xu)(−) . Since by Eq. (3), |w| = |u| + w , one derives |u| = n so that u ∈ Un and w ∈ (AUn )(−) . This proves the inclusion “⊇”. Example 38. Consider the case n = 5. One has
5,a = {a 5 , ababa, aba 2 ba, a 2 ba 2 , a 3 ba 3 , a 4 ba 4 } and U5,a = U5 ∩ aA∗ = {a 5 , ababa, a 2 ba 2 } . Moreover, (AU5,a )(−) = {a 6 , a 5 ba 5 , ababa 2 baba, abababa, a 2 ba 3 ba 2 , a 2 ba 2 ba 2 } . The set 6,a is given in Example 33. As one easily verifies, 6,a = (5,a \ U5,a ) ∪ (AU5,a )(−) . In a similar way, setting U5,b = U5 ∩ bA∗ one obtains 6,b = (5,b \ U5,b ) ∪ (AU5,b )(−) so that 6 = (5 \ U5 ) ∪ (AU5 )(−) . 7. Uniform central codes Let n be a positive integer. A central code X is uniform of order n if X ⊆ An . In this case X ⊆ Un so that Un is the maximal uniform central code of order n. As is well known [6], for any n, Card Un = (n + 2).
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
237
For instance, one has U5 = {aaaaa, aabaa, ababa, babab, bbabb, bbbbb} , U7 = {aaaaaaa, aaabaaa, abababa, bababab, bbbabbb, bbbbbbb} . From Eqs. (9) and (11) one derives the following noteworthy relation between maximal uniform codes and Farey codes:
n+1 \ n = (AUn )(−)
for all n > 0 .
Proposition 39. Let n > 0 and 0 k n. There exists a (unique) word w ∈ Un such that |w|a = k if and only if gcd(n + 2, k + 1) = 1. Proof. We recall that the slope of a central word is a bijection of PER onto I. Thus, if w ∈ Un and |w|a = k, then
(w) =
n−k+1 |w|b + 1 = |w|a + 1 k+1
(12)
with gcd(n − k + 1, k + 1) = gcd(n + 2, k + 1) = 1. Conversely, if gcd(n − k + 1, k + 1) = gcd(n + 2, k + 1) = 1, then, since is a bijection, there exists a word w ∈ PER satisfying Eq. (12), so that |w| = n and |w|a = k. From the previous proposition, one derives the following: Corollary 40. There exists a (unique) word w ∈ Un such that |w|a = k for all k, 0 k n if and only if n + 2 is a prime. Example 41. In the case n = 7, the set of numbers which are coprime with 9 is {1, 2, 4, 5, 7, 8}. Hence, for w ∈ U7 we have |w|a ∈ {0, 1, 3, 4, 6, 7}. In the case n = 5, since n+2 = 7 is prime, {|w|a | w ∈ U5 } = {0, 1, 2, 3, 4, 5}. Appendix
Proof of Proposition 19. One easily verifies that D = (ab∗ a ∗ ∪ ba ∗ b∗ ∪ ) .
(A.1)
From the rational identity A∗ \ (ab∗ a ∗ ∪ ba ∗ b∗ ∪ ) = ab∗ a + bA∗ ∪ ba ∗ b+ aA∗ one derives X = (ab∗ a + bA∗ ∪ ba ∗ b+ aA∗ ) . Let us prove that X is a code. By contradiction, suppose that one has x1 · · · xm = x1 · · · xn ,
|x1 | < |x1 |
(A.2)
with x1 , . . . , xm , x1 , . . . , xn ∈ X, m, n > 0. One has m 2. Moreover we may suppose without loss of generality that x2 ∈ PERa . Thus, x2 has a prefix
(abi a j b) = (a(ba)i )j +1 ba(a(ba)i )j ,
i 0, j 1 .
238
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
From Eq. (A.2) one derives x1 (a(ba)i )j +1 baa = x1 · · · xn ,
(A.3)
for a suitable ∈ A∗ . Hence, x1 has the prefix x1 a. By Lemma 6, x1 has the prefix (ax1 )(−) . By Lemma 5, (ax1 )(−) has the form x1 abs = sbax1 , with s ∈ PER. Now let y be the longest prefix of x1 of the form y = x1 abz = zbax1
with z ∈ PER .
(A.4)
By Proposition 3, y ∈ PER. We set x1 = y with ∈ A∗ . By Eq. (A.3) one gets i > 0 and a(ba)i−1 (a(ba)i )j baa = zx2 · · · xn .
(A.5)
Since z is palindrome one has to consider the following cases: Case 1: z = . By Eq. (A.4) one has y = x1 ab = bax1 so that x1 = (ba)p b, p 0. Thus x1 ∈ D which is a contradiction. Case 2: z = a(ba)h , 0 h i − 1. By Eq. (A.4) one has y = x1 a(ba)h+1 = a(ba)h+1 x1 so that x1 = (a(ba)h+1 )p , p 0. Thus x1 ∈ D which is a contradiction. Case 3: z = a(ba)i−1 (a(ba)i )k a(ba)i−1 , 0 k j − 1. By Eq. (A.5) one gets ba(a(ba)i )j −k−1 baa = x2 · · · xn .
(A.6)
If = , then the first letter of is b. Thus, x1 = y has the prefix yb and consequently the prefix (by)(−) . By Lemma 5 it follows that (by)(−) = (bx1 abz)(−) = x1 abzbax1 = x1 aby = ybax1 . This contradicts the maximality of y. If = , by Eq. (A.6) one derives that x2 has the prefix baa or babaa (according to whether k < j − 1 or k = j − 1). This is a contradiction as by Corollary 4 no central word has such prefixes. Case 4: z has the prefix a(ba)i−1 (a(ba)i )j b. Set u = a(ba)i−1 (a(ba)i )j −1 a(ba)i−1 ∈ PER. Since ub is a prefix of z, also (bu)(−) should be a prefix of z. By Lemma 5 one has (bu)(−) = a(ba)i−1 (a(ba)i )j a(ba)i−1 . Thus, z has the prefix a(ba)i−1 (a(ba)i )j a, which is a contradiction. This proves that X is a central code. To prove that X is a maximal central code one has to show that for all y ∈ D, X ∪ {y} is not a central code. In view of Eq. (A.1) it is sufficient to consider the case that y = (abi a j ), with i, j 0 (the case y = (ba i bj ) is similarly dealt with). One easily checks that in this case y (abi ab)y = (abi a j +2 b) which proves the assertion since (abi ab), (abi a j +2 b) ∈ X. References [1] [2] [3] [4]
J.-P. Allouche, J. Shallit, Automatic Sequences, Cambridge University Press, Cambridge, UK, 2003. J. Berstel, A. de Luca, Sturmian words, Lyndon words and trees, Theoret. Comput. Sci. 178 (1997) 171–203. J. Berstel, D. Perrin, Theory of Codes, Academic Press, New York, 1985. J. Berstel, P. Séébold, Sturmian words, in: M. Lothaire (Ed.), Algebraic Combinatorics on Words, Cambridge University Press, Cambridge, UK, 2002, pp. 45–110. [5] A. de Luca, Sturmian words: structure, combinatorics, and their arithmetics, Theoret. Comput. Sci. 183 (1997) 45–82. [6] A. de Luca, F. Mignosi, On some combinatorial properties of Sturmian words, Theoret. Comput. Sci. 136 (1994) 361–385.
A. Carpi, A. de Luca / Theoretical Computer Science 340 (2005) 220 – 239
239
[7] G.H. Hardy, E.M. Wright, An Introduction to the Theory of Numbers, Clarendon, Oxford University Press, Oxford, UK, 1968. [8] L. Ilie, W. Plandowski, Two-variable word equations, Theoret. Inform. Appl. 34 (2000) 467–501. [9] M. Lothaire, Combinatorics on Words, Addison-Wesley, Reading, MA, 1983; M. Lothaire, Combinatorics on Words, second ed., Cambridge University Press, Cambridge, UK, 1997. [10] A. Restivo, Codes and local constraints, Theoret. Comput. Sci. 72 (1990) 55–64.
Theoretical Computer Science 340 (2005) 240 – 256 www.elsevier.com/locate/tcs
An enhanced property of factorizing codes Clelia De Felice1 Dipartimento di Informatica e Applicazioni, Università di Salerno, 84081 Baronissi (SA), Italy
Abstract The investigation of the factorizing codes C, i.e., codes satisfying Schützenberger’s factorization conjecture, has been carried out from different viewpoints, one of them being the description of structural properties of the words in C. In this framework, we can now improve an already published result. More precisely, given a factorizing code C over a two-letter alphabet A = {a, b}, it was proved by De Felice that the words in the set C1 = C ∩ a ∗ ba ∗ could be arranged over a matrix related to special factorizations of the cyclic groups. We now prove that, in addition, these matrices can be recursively constructed starting with those corresponding to prefix/suffix codes. © 2005 Elsevier B.V. All rights reserved. Keywords: Variable length codes; Formal languages; Factorizations of cyclic groups
1. Introduction In this paper, a subset C of a free monoid A∗ is a (variable-length) code if each word in A∗ has at most one factorization into words of C, i.e., C is the base of a free submonoid of A∗ [1]. This algebraic approach was initiated by Schützenberger in [24] and subsequently developed mainly by his school. The theory of codes is rich in significant results, which have been obtained by using several different methods (combinatorial, probabilistic, algebraic) and tools from automata, formal power series and semigroup theory.
E-mail address:
[email protected]. 1 Partially supported by MIUR Project “Linguaggi Formali e Automi: Metodi, Modelli e Applicazioni” (2003)
and by 60 % Project “Linguaggi formali e codici: modelli e caratterizzazioni strutturali” (University of Salerno, 2004). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.022
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
241
Nevertheless some basic problems are still open. One of the most difficult of these, the factorization conjecture, was proposed by Schützenberger as follows: given a finite maximal code C, there would be finite subsets P, S of A∗ such that C − 1 = P (A − 1)S, with X denoting the characteristic polynomial of X [1,2,5]. We refer to Section 2 for all the known results concerning this conjecture. Any code C which satisfies the above equality is finite, maximal, and is called a factorizing code, whereas a finite maximal code is a maximal object in the class of finite codes for the order of set inclusion. For example, finite biprefix maximal codes are factorizing [1]. This note deals with the investigation of the class of the factorizing codes C. This research line has been carried out from different viewpoints, one of them being the description of structural properties of the words in C. Continuing the investigation initiated in [9], here we enhance a property of the sets C1 ⊆ a ∗ ba ∗ such that C1 = C ∩ a ∗ ba ∗ for a factorizing code C over a two-letter alphabet A = {a, b}. Precisely, we already know that C1 satisfies the property reported below: Property 1.1. The words in C1 can be arranged over a matrix C1 = (a rp,q ba vp,q )1 p m,1 q such that for each row Rp = {rp,q | q ∈ {1, . . . , }} and each column Tq = {vp,q | p ∈ {1, . . . , m}} in this matrix, (Rp , Tq ) is a Hajós factorization of Zn . We recall that a pair (R, T ) of subsets of N is a factorization of Zn if for each z ∈ {0, . . . , n − 1} there exists a unique pair (r, t), with r ∈ R and t ∈ T , such that r + t = z (mod n). The general structure of the pairs (R, T ) is still unknown but two simple families of these pairs can be recursively constructed: Krasner factorizations and Hajós factorizations (see Section 4 for precise definitions). The latter factorizations seem to have an important role in the description of the structure of factorizing codes (see [6–9]). In this paper we prove, that for each factorizing code C, an arrangement of C1 = C ∩ a ∗ ba ∗ satisfying Property 1.1 can be recursively constructed by a natural two-dimensional generalization of Hajós method. This improved version of the result given in [9] is interesting in its own right but it has additional appeal since, as conjectured in [12], given a set C1 satisfying this property, there would exist a factorizing code C such that C1 = C ∩ a ∗ ba ∗ . As we have already said, we take into account codes over a two-letter alphabet but, as done in [9], extending the results presented here to alphabets of larger size should not be difficult. This paper is organized as follows. Section 2 contains all the basic definitions and results concerning codes. Section 3 summarizes the contents of the subsequent sections and outlines the main result. In Section 4 we have gathered basics on the factorizations of cyclic groups and in Sections 5, 6 we have collected intermediate results, subsequently used in Section 7 to show the above-mentioned property of the factorizing codes.
2. Basics Given a finite alphabet A, let A∗ be the free monoid generated by it. We denote by 1 the empty word and we set A+ = A∗ \ 1.
242
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
A subset C of A∗ is a code if C ∗ is a free submonoid of A∗ of base C. In other words, C is a code if, for any c1 , . . . , ch , c1 , . . . , ck ∈ C, we have: c1 , . . . , ch = c1 , . . . , ck ⇒ h = k,
∀i ∈ {1, . . . , h},
ci = ci .
Examples of codes can be easily constructed by considering, for instance, the class of the prefix codes, C being prefix if C ∩ CA+ = ∅. A more complex class is that of maximal codes. A code C is maximal over A if C is not a proper subset of another code over A. As one of Schützenberger’s basic theorems shows, a finite code C is maximal if and only if C is complete, that is C ∗ ∩ A∗ wA∗ = ∅, for any w ∈ A∗ [1]. The class of codes which we consider in this paper is that of the factorizing codes, introduced by Schützenberger. The definition of such codes is given in terms of polynomials. Here, we denote ZA the ring of the noncommutative polynomials in variables A and coefficients in the ring Z of the integers and NA the semiring of the noncommutative polynomials in variables A and coefficients in the semiring N of the nonnegative integers [2]. P 0 means P ∈ NA. As usual, the value of P ∈ ZA on w ∈ A∗ is denoted by (P , w) and is referred to as the coefficient of w in P. The characteristic polynomial of a finite language X ⊆ A∗ , denoted X, is the polynomial X = x∈X x. Henceforth, we will at times identify X with its characteristic polynomial even if this is not stated explicitly. A (finite) code C over A is factorizing if there exist two finite subsets P, S of A∗ such that: C − 1 = P (A − 1)S.
(1)
For instance, a finite maximal prefix code C is factorizing, by taking S = {1} and P equal to the set of the proper prefixes of the words in C [1]. If C is a factorizing code then C is a finite maximal code [1]. However it is not known whether every finite maximal code is factorizing. This problem is known as the factorization conjecture [1,2,25]. Conjecture 2.1. (Schützenberger). Any finite maximal code is factorizing. Some partial results are known and are mentioned below. The first examples of families of factorizing codes can be found in [3,4]. Subsequently, Reutenauer obtained the result that was closest to a solution of the conjecture [2,21,22]. He proved that Eq. (1) holds for any finite maximal code C if we substitute P , S with P , S ∈ ZA. Results concerning problems which are closely connected to the factorization conjecture can be found in [17,18]. Another class of results has been obtained by considering finite maximal codes over a two-letter alphabet A = {a, b} having a constraint on the number of the occurrences of the letter b in each word. More precisely, consider a finite maximal code C over A such that each word in C has a maximum of m occurrences of the letter b. C is also named an m-code. If m is less than or equal to three, then C is factorizing [7,13,19]. Moreover, C is also factorizing if bm ∈ C and m is a prime number or m = 4 [26]. For m 3, the structure of the m-codes has also been described and is related to the solutions to some inequalities which are, in turn, related to the factorizations of the cyclic groups [6,7,19]. Furthermore, other results which relate words in a finite maximal code to the factorizations of the cyclic groups can be found in [16,20].
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
243
3. Outline of the results The aim of this paper is to prove that, for a given factorizing code C, words in C ∩ a ∗ ba ∗ , i.e., words in C having one occurrence of b s satisfy a special property. In Section 1, we introduced factorizations of cyclic groups. A special class of these is the so-called Hajós factorizations. There exist at least two recursive definitions of this class of factorizations and they are recalled in Section 4. In this note we will introduce a two-dimensional extension of Hajós factorizations such that they still admit a recursive construction. More precisely, we consider a sequence (R1 , T1 ), . . . , (Rm , Tm ) of Hajós factorizations and we consider matrices with integer entries in which each row is one of the Rj ’s. Obviously, several matrices exist with this property but one of them exists, named good arrangement of R1 , . . . , Rm , which can be obtained starting with simpler good arrangements and by a natural two-dimensional extension of Hajós method (Section 5). Finally, we introduce the crossed two-dimensional Hajós factorizations. Namely, given a sequence (R1 , T1 ), . . . , (Rm , Tm ) of Hajós factorizations, we consider matrices having pairs (r, v) of integers as elements and r ∈ Rj , v ∈ Ti . We focus our attention on arrangements such that a recursive algorithm exists constructing them. Once again these are called good arrangements (Section 7). We prove that, for a given factorizing code C, words in C ∩ a ∗ ba ∗ , i.e., words in C with one occurrence of b s, can be canonically associated with a matrix which is a good arrangement of a crossed two-dimensional Hajós factorization.
4. Hajós factorizations and their recursive constructions In [14], Hajós gave a method, slightly corrected later by Sands in [23], for the construction of a class of factorizations of an abelian group (G, +) which are of special interest in the construction of factorizing codes. As done in [8], we report this method for the cyclic group Zn of order n (Definition 4.1). The corresponding factorizations will be named Hajós factorizations. The operation ◦ also intervenes: for subsets S = {s1 , . . . , sq }, T of Zn , S ◦ T denotes the family of subsets of Zn having the form {si + ti | i ∈ {1, . . . , q}}, where {t1 , . . . , tq } is any multiset of elements of T having the same cardinality as S. Furthermore, it is convenient to translate the definitions in a polynomial form. For a polynomial in Na, the notation a H = n∈N (H, n)a n will be used with H ∈ N1, i.e., with H being a finite multiset of nonnegative integers. Therefore, if H1 , H2 , . . . , Hk ∈ N1, the expression a H1 ba H2 , . . . , a Hk is a notation for the product of the formal power series a H1 , b, a H2 , . . . , a Hk . For instance, a {2,3} ba {1,5} = a 2 ba + a 2 ba 5 + a 3 ba + a 3 ba 5 . Computation rules are also defined: a M+L = a M a L , a M∪L = a M + a L , a M◦L = a M ◦ a L , a ∅ = 0, a 0 = 1. Finally, let X1 , X2 ⊆ N, let n ∈ N. The equation X1 = X2 (mod n) means that for each x1 ∈ X1 a unique x2 ∈ X2 exists with x1 = x2 (mod n) and for each x2 ∈ X2 a unique x1 ∈ X1 exists with x1 = x2 (mod n). Definition 4.1. Let R, T be subsets of N. (R, T ) is a Hajós factorization of Zn if and only if there exists a chain of divisors of n: k0 = 1 | k1 | k2 | . . . | ks = n,
(2)
244
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
such that: aR ∈ T
a ∈
a − 1 a k1 − 1 ◦ a−1 a−1 a − 1 a k1 − 1 · a−1 a−1
·
a k2 − 1 a k1 − 1
a k2 − 1 ◦ k a 1 −1
an − 1 , a ks−1 − 1
(3)
an − 1 · ... ◦ ... k . a s−1 − 1
(4)
◦ ... · ...
Furthermore we have R, T ⊆ {0, . . . , n − 1}. Observing the definition of the Hajós factorizations we can obtain a recursive construction of them with ease. This recursive construction, which will be widely used in this paper, was first given in [16] as a direct result, then it was proved in [11] for the sake of completeness, and now it is illustrated in Proposition 4.1. Proposition 4.1 (Lam [16]). Let R, T ⊆ {0, . . . , n−1} and suppose that (R, T ) is a Hajós factorization of Zn with respect to the chain k0 = 1 | k1 | k2 | . . . | ks = n of divisors of n. Then either (R, T ) = (R1 , T1 ) or (R, T ) = (T1 , R1 ), where (R1 , T1 ) satisfies one of the two following conditions: (1) There exists t ∈ {0, . . . , n−1} such that R1 = {0, . . . , n−1} and T1 = {t}. Furthermore, s = 1. (2) R1 = R (1) + {0, 1, . . . , g − 1}h, T1 = T (1) ◦ {0, 1, . . . , g − 1}h, (R (1) , T (1) ) being a Hajós factorization of Zh , g, h ∈ N, n = gh, R (1) , T (1) ⊆ {0, . . . , h − 1}. The chain of divisors defining (R (1) , T (1) ) is k0 = 1 | k1 | k2 | . . . | ks−1 = h. Theorem 4.1 is one of the results which allow us to link factorizing codes and Hajós factorizations of Zn . In Theorem 4.1 a crucial role is played by particular factorizations defined as follows. Starting with the chain of divisors of n in Eq. (2), let us consider the two polynomials a I and a J defined by: aI =
(a kj − 1) , kj −1 − 1) (a j even,1 j s
aJ =
(a kj − 1) . kj −1 − 1) (a j odd,1 j s
(5)
The two polynomials above have been considered by Krasner and Ranulac in [15] and are the simplest examples of Hajós factorizations of Zn . In the same paper they proved that a pair (I, J ) satisfies Eqs. (5) if and only if (I, J ) satisfies the following property: for any z ∈ {0, . . . , n − 1} there exists a unique (i, j ), with i ∈ I and j ∈ J , such that i + j = z, i.e., a I a J = (a n − 1)/(a − 1). (I, J ) is called a Krasner factorization. Theorem 4.1 (De Felice [8]). For R, T ⊆ {0, . . . , n − 1} the following conditions are equivalent: (1) (R, T ) is a Hajós factorization of Zn . (2) There exists a Krasner factorization (I, J ) of Zn such that (I, T ), (R, J ) are (Hajós) factorizations of Zn .
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
245
(3) There exist L, M ⊆ N and a Krasner factorization (I, J ) of Zn such that: a R = a I (1 + a M (a − 1)),
a T = a J (1 + a L (a − 1)).
(6)
Furthermore, (2) ⇔ (3) also holds for R, T ⊆ N. As stated in Theorem 4.1, the equivalence between conditions (2) and (3) still holds under the more general hypothesis that R, T are arbitrary subsets of N (not necessarily with max R < n, max T < n). In order to keep this general framework, in the next part of this paper, for R, T ⊆ N, we will say that (R, T ) is a Hajós factorization of Zn if (R(n) , T(n) ) satisfies the conditions contained in Definition 4.1 where, for a subset X of N and n ∈ N, we denote X(n) the subset of {0, . . . , n − 1} such that X(n) = X (mod n). This is equivalent, as Lemma 4.1 below shows, to defining Hajós factorizations of Zn as those pairs satisfying Eqs. (6). The recursive construction of the solutions of Eqs. (6), given in [6] allowed us to obtain another recursive construction of the Hajós factorizations, given in [8]. Lemma 4.1 (De Felice [10]). Let (I, J ) be a Krasner factorization of Zn . Let R, R , M be subsets of N such that a R = a I (1 + a M (a − 1)) and a R = a R(n) . Then, M ⊆ N exists such that a R = a I (1 + a M (a − 1)) and I + max M + 1 ⊆ {0, . . . , n − 1}. Furthermore, if we set R = {r1 , . . . , rq }, R = {r1 + 1 n, . . . , rq + q n}, for 1 , . . . , q 0, and if we set a H = a r1 +{0,n,...,(1 −1)n} + · · · + a rq +{0,n,...,(q −1)n} then we have a disjoint union M = M ∪ M with M ⊆ N, a M = a J a H and a R = a R + a I (a − 1)a M . It is worthy of note that there is a relationship between Krasner factorizations and Hajós factorizations which goes beyond the observation that the former are simple examples of the latter. Firstly, Theorem 4.1 points out that, for each Hajós factorization (R, T ), we can associate a Krasner factorization (I, J ) with (R, T ), called a Krasner companion factorization of (R, T ) in [16]. Secondly, given a Hajós factorization (R, T ) of Zn such that (R(n) , T(n) ) is defined by Eqs. (3), (4), a Krasner companion factorization (I, J ) is naturally associated with (R, T ): in order to get (I, J ) we have to erase from Eq. (3) polynomials Pj = (a kj − 1)/(a kj −1 − 1) with j odd, and from Eq. (4) polynomials Pj with j even [8]. (I, J ) will be called the Krasner companion factorization of (R, T ) with respect to the chain of divisors of n given in Eq. (2). Proposition 4.2 shows how these two notions are related to each other. Proposition 4.2. Each Krasner companion factorization (I, J ) of (R, T ) is a Krasner companion factorization of (R, T ) with respect to a chain of divisors of n which defines (R, T ). Proof. Let (I, J ) be a Krasner companion factorization of (R, T ), i.e., suppose that (R, T ) satisfies Eqs. (6). Since (I, J ) is also a Krasner companion factorization of (R(n) , T(n) ), we can suppose that R, T ⊆ {0, . . . , n − 1}. We prove the statement by induction on the length s of the chain k0 = 1 | k1 | k2 | . . . | ks = n of divisors of n which defines (I, J ). If s = 1 and (I, J ) = ({0}, {0, . . . , n − 1}) then a R = 1 + a M (a − 1), a T = [(a n − 1)/(a − 1)] + a L (a n − 1), and (R, T ) satisfies condition (1) in Proposition 4.1 (see also
246
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
[6]). Thus, (I, J ) is a Krasner companion factorization of (R, T ) with respect to the chain k0 = 1 | k1 = n which defines (R, T ). Suppose s > 1. By using Eqs. (5), there exist g, h ∈ N such that n = gh and I = I (1) + {0, 1, . . . , g − 1}h, J = J (1) , (I (1) , J (1) ) being a Krasner factorization of Zh defined by k0 = 1 | k1 | k2 | . . . | ks−1 = h. Since R ⊆ {0, . . . , n−1} and a R = a I (1+a M (a −1)) 0, we have max I + max M + 1 < n which implies max I1 + max M + 1 < h. Thus, for each (1) (1) t ∈ N, we have (a I (1 + a M (a − 1)), a t ) = 0 if t h, otherwise (a I (1 + a M (a − 1)), (1) (1) a t ) = (a I (1 + a M (a − 1)), a t ). Consequently, we have a R = a I (1 + a M (a − 1)) 0, (1) R = R + {0, 1, . . . , g − 1}h (see also [10,12]). In addition, by using Lemma 4.1 we (1) also have a T(h) = a J (1 + a L (a − 1)) 0. Thus, by Theorem 4.1, (a R , a T(h) ) is a Hajós factorization of Zh having (I (1) , J ) as a Krasner companion factorization, where (I (1) , J ) is defined by the chain k0 = 1 | k1 | k2 | . . . | ks−1 . By induction hypothesis, (I (1) , J ) is a (1) Krasner companion factorization of (a R , a T(h) ) with respect to this chain which defines (1) (a R , a T(h) ). Since R = R (1) + {0, 1, . . . , g − 1}h, T = T(h) ◦ {0, 1, . . . , g − 1}h, we conclude that (I, J ) is a Krasner companion factorization of (R, T ) with respect to the chain k0 = 1 | k1 | k2 | . . . | ks = n of divisors of n which defines (R, T ). Let us consider Hajós factorizations (R1 , T1 ), . . . , (Rm , Tm ) having the same Krasner companion factorization (I, J ). In the next part of this paper, all the elements denoted by the same symbol R with different indices will refer to the same element in the Krasner pair, i.e., the statement “(R1 , T1 ), . . . , (Rm , Tm ) have (I, J ) as Krasner companion factorization” will mean (Ri , J ) and (I, Ti ) are factorizations of Zn , i ∈ {1, . . . , m}. Furthermore, by using Proposition 4.2, we can conclude that (R1 , T1 ), . . . , (Rm , Tm ) can be defined by the same chain of divisors and have the same Krasner companion factorization (I, J ) with respect to this chain of divisors. 5. Two-dimensional Hajós factorizations In the next part of this paper, matrices with entries in A∗ or in N will also be considered and A = (ap,q )1 p m, 1 q will be an alternative notation for the matrix of size m × : a ... a 1,1
a2,1 A= .. . am,1
... .. . ...
1,
a2, .. . .
am,
Given a matrix A = (ap,q )1 p m, 1 q with entries in N and a positive integer n, n 2, ) we denote A(n) = (ap,q 1 p m, 1 q , where, for each p, q, 1 p m, 1 q , we n−1. We also denote h+A = (b have ap,q = ap,q (mod n), 0 ap,q p,q )1 p m, 1 q , where, for each p, q, 1 p m, 1 q , we have bp,q = h + ap,q and nA ∪ B = (ap,q )1 p m, 1 q 2 , where B = (ap,q )1 p m, +1 q 2 . Finally, i=1 Ai = A ) ∪ A . ( n−1 i n i=1 Given X, with X ⊆ A∗ (resp. X ⊆ N) an arrangement of X will be an arrangement of the elements of X in a matrix with entries in A∗ (resp. N) and size |X|. We now define
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
247
special arrangements of Hajós factorizations by a natural two-dimensional extension of Hajós method. Definition 5.1. Let (R1 , T1 ), . . . , (Rm , Tm ) be Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization. An arrangement D = (rp,q )1 p m, 1 q l of m p=1 Rp having the Rp ’s as rows is a good arrangement of (R1 , . . . , Rm ) (with respect to the rows) if D can be recursively constructed using the following three rules. (1) D is a good arrangement of m p=1 Rp (with respect to the rows) if D(n) is a good m arrangement of p=1 (Rp )(n) (with respect to the rows). (2) Suppose that (Rp , Tp ) satisfies condition (1) in Proposition 4.1, for all p ∈ {1, . . . , m}. If Rp = {rp } with rp ∈ {0, . . . , n − 1}, then D is the matrix with only one column having rp as the pth entry. If Rp = {rp,0 , . . . , rp,n−1 } with rp,i = i, then D = (rp,j )1 p m, 0 j n−1 . (3) Suppose that (Rp , Tp ) satisfies condition (2) in Proposition 4.1, for all p ∈ {1, . . . , m}, (1) (1) i.e., either Rp = Rp + {0, h, . . . , (g − 1)h)} or Rp = Rp ◦ {0, h, . . . , (g − 1)h)}. Let g−1 (1) D(1) be a good arrangement of m p=1 Rp . In the first case, we set D = k=0 (kh + D(1) ). In the second case, D is obtained by taking D(1) and then substituting in it each (1) (1) (1) rp,q ∈ Rp with the corresponding rp,q + p,q h ∈ Rp . Let (R1 , T1 ), . . . , (Rm , Tm ) be Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization. It goes without saying that we can consider arrangements of m p=1 Rp having the R ’s as columns and therefore, we can give a dual notion of a good arrangement p of m to the columns. This arrangement will be the transpose matrix of p=1 Rp with respect a good arrangement of m p=1 Rp with respect to the rows. Example 5.1. It is easy to see that ({0}, {0, 1}), ({1}, {1, 2}) and ({2}, {2, 3}) are Hajós factorizations of Z2 having ({0}, {0, 1}) as a Krasner companion factorization. According to Definition 5.1, D1 is a good arrangement whereas D2 is not a good arrangement, where we set: D1 =
0 2 2
1 1 , 3
D2 =
0 1 2
1 2 . 3
Indeed, (D1 )(2) satisfies condition (2) in Definition 5.1 whereas (D2 )(2) does not satisfy the same condition (2). As another example, ({0, 2, 4}, {0, 1, 6, 7}), ({0, 2, 4}, {1, 2, 8, 19}) and ({0, 2, 4}, {2, 3, 8, 9}) are Hajós factorizations of Z12 having ({0, 2, 4}, {0, 1, 6, 7}) as a Krasner companion factorization. According to Definition 5.1, D3 is a good arrangement whereas D4 is not a good arrangement, where we set: D3 =
0 2 2
1 1 3
6 8 8
7 19 , 9
D4 =
0 8 8
1 19 9
6 2 2
7 1 . 3
248
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
Indeed, (D3 )(12) satisfies condition (3) in Definition 5.1 since we have (D3 )(12) = 1k=0 (1) (1) (6k + (D3 )(12) ), where (D3 )(12) = D1 is a good arrangement. On the contrary, D4 is not a good arrangement since, in view of Proposition 5.1, there exists a unique good arrangement of {0, 1, 6, 7} ∪ {1, 2, 8, 19} ∪ {2, 3, 8, 9} and that is D3 . Note that for each column Wq = (r1,q , r2,q , r3,q ) of D3 , 1 q 4, an ordered sequence Iq = (i1,q , i2,q , i3,q ) of elements of {0, 2, 4} exists satisfying: r1,q + i1,q = r2,q + i2,q = r3,q + i3,q = nq (mod 12). Indeed, we have 0 + 2 = 2 + 0 = 2 + 0 = 2 (mod 12), 1 + 2 = 1 + 2 = 3 + 0 = 3 (mod 12), 6 + 2 = 8 + 0 = 8 + 0 = 8 (mod 12), 7 + 2 = 19 + 2 = 9 + 0 = 9 (mod 12). In Proposition 6.1, we will prove that each good arrangement satisfies this special property. Proposition 5.1. Let (R1 , T1 ), . . . , (Rm , Tm ) be Hajós factorizations of Zn having (I, J ) as ma Krasner companion factorization. There exists a (unique) good arrangement D of p=1 Rp with respect to the rows (resp. columns). Proof. As we observed at the end of Section 4, if (R1 , T1 ), . . . , (Rm , Tm ) are Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization then (R1 , T1 ), . . . , (Rm , Tm ) can be defined by a same chain of divisors of n of length s. Thus, (R1 , T1 ), . . . , (Rm , Tm ) satisfy the same condition contained in Proposition 4.1. The proof is by induction on s and we will prove the statement for good arrangements with respect to the rows (an analogous argument can be used for good arrangements with respect to the columns). Suppose Rp , Tp ⊆ {0, . . . , n−1} for p ∈ {0, . . . , n−1}. If s = 1, then (R1 , T1 ), . . . , (Rm , Tm ) satisfy condition (1) in Proposition 4.1 and (a unique) D exists which satisfies condition (2) in Definition 5.1. Thus, let s > 1. Hence, (R1 , T1 ), . . . , (Rm , Tm ) satisfy condition (2) in Proposition 4.1. Therefore, looking at condition (3) in Definition 5.1, (a unique) D exists since (a unique) D(1) exists by induction hypothesis. If Rp , Tp ⊆ {0, . . . , n − 1} for p ∈ {0, . . . , n − 1}, then ((Rp )(n) , (Tp )(n) ) are Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization. Thus, for the (R argument above, a (unique) good arrangement D(n) of m p=1 p )(n) exists. Hence, looking at condition (1) in Definition 5.1, (a unique) D also exists.
6. A property of good arrangements of Hajós factorizations In this section we will prove technical results concerning good arrangements of Hajós factorizations which will be subsequently used in the proof of Proposition 7.3. The argument used in the proof of Proposition 6.1 has also been used in the proof of another result stated in [9]. Nevertheless the complete proof of Proposition 6.1 is reported here for the sake of completeness. Proposition 6.1. Let (R1 , T1 ), . . . , (Rm , Tm ) be Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization. Let D = (rp,q )1 p m, 1 q be the good arrangement of m p=1 Rp with respect to the rows. Then, the two following conditions are
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
249
satisfied: (a) For each column Wq = (r1,q , . . . , rm,q ) of D, there exists an ordered sequence Jq = (j1,q , . . . , jm,q ) of elements of J satisfying r1,q + j1,q = r2,q + j2,q = · · · = rm,q + jm,q = nq (mod n).
(7)
(b) Suppose that Rp , Tq ⊆ {0, . . . , n − 1}. Thus, for each column Wq = (r1,q , . . . , rm,q ) of D, there exists an ordered sequence Jq = (j1,q , . . . , jm,q ) of elements of J satisfying r1,q + j1,q = r2,q + j2,q = · · · = rm,q + jm,q = nq .
(8)
The nq ’s are all different. Proof. Let (R1 , T1 ), . . . , (Rm , Tm ) be Hajós factorizations of Zn having (I, J ) as a Krasner companion factorization. Let D be a good arrangement of m p=1 Rp with respect to the rows. Let us demonstrate that the statement is proved if we prove condition (b). Indeed, suppose that m (Rp , Tp ) = ((Rp )(n) , (Tp )(n) ). Using condition (b), the good arrangement D(n) of p=1 (Rp )(n) satisfies Eq. (8). On the other hand, when we change in Eq. (8) the elements in a column Wq of D(n) with the elements in the corresponding column in D, according to condition (1) in Definition 5.1, the sum defines the same integer mod n and so Eq. (7) holds, i.e., D satisfies condition (a). We prove condition (b) by using induction on the length s of the common chain of divisors of n given in Eq. (2) and defining (R1 , T1 ), . . . , (Rm , Tm ) (Definition 4.1). Let us firstly suppose that s = 1. Then, (Rp , Tp ) satisfies condition (1) in Proposition 4.1. If Rp = {rp,0 . . . , rp,n−1 } = {0, . . . , n − 1} then J = {0} and obviously D (defined by condition (2) in Definition 5.1) satisfies Eq. (8). Otherwise we have Rp = {rp } ⊆ {0, . . . , n − 1}, J = {0, . . . , n − 1}. Set rmax = max{rp | 1 p m}. We obviously have: r1 + (rmax − r1 ) = r2 + (rmax − r2 ) = · · · = rm + (rmax − rm ), where rmax − rp ∈ {0, . . . , n − 1} = J . Thus, D (defined by condition (2) in Definition 5.1) satisfies Eq. (8). Let us suppose that condition (b) holds for good arrangements of Hajós factorizations (Rp , Tp ) defined by starting with a chain of divisors of length less than s > 1 and let k0 = 1 | k1 | k2 | . . . | ks = n be the chain of divisors of n associated with (Rp , Tp ). Thus, (Rp , Tp ) satisfies condition (2) in Proposition 4.1. Then we have I = {0}, J = {0}. Furthermore, (1) (1) either Rp = Rp + {0, h, . . . , (g − 1)h}, J = J (1) or Rp ∈ Rp ◦ {0, h, . . . , (g − 1)h}, (1) (1) J = J (1) + {0, h, . . . , (g − 1)h} with (Rp , Tp ) being a Hajós factorization of Zh having the Krasner companion factorization (I (1) , J (1) ), g > 1, n = gh, with respect to the chain k0 = 1 | k1 | k2 | . . . | ks−1 = h of divisors of h = ks−1 of length less than s and (1) (1) (1) (1) defining (Rp , Tp ). Furthermore, Rp , Tp ⊆ {0, . . . , h − 1}. By induction hypothesis, m (1) (1) the good arrangement D of p=1 Rp satisfies condition (b). Thus, for each column (1)
(1)
(1)
(1)
Wq = (r1,q , . . . , rm,q ) of D(1) , an ordered sequence Jq of J (1) exists satisfying (1)
(1)
(1)
(1)
(1) (1) r1,q + j1,q = r2,q + j2,q = · · · = rm,q + jm,q .
(1)
(1)
= (j1,q , . . . , jm,q ) of elements (9)
250
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256 (1)
Firstly, we suppose Rp = Rp + {0, h, . . . , (g − 1)h}. Then, for each ∈ {0, . . . , g − 1}, in virtue of Eq. (9), we have: (1)
(1)
(1)
(1)
(1) (1) + h + jm,q . r1,q + h + j1,q = r2,q + h + j2,q = · · · = rm,q Looking at Definition 5.1, we see that the good arrangement D of m p=1 Rp (defined by condition (3) in Definition 5.1) satisfies condition (b). (1) We now suppose Rp ∈ Rp ◦ {0, h, . . . , (g − 1)h}. Let p,q ∈ {0, . . . , g − 1} such that (1) rp,q + p,q h ∈ Rp . Thanks to Eq. (9), we have (1)
(1)
(r1,q + 1,q h) + (j1,q + (max,q − 1,q )h) (1) (1) = · · · = (rm,q + m,q h) + (jm,q + (max,q − m,q )h), (1)
where max,q = max{p,q | 1 p m}. As max,q − p,q ∈ {0, . . . , g − 1} then jp,q + (max,q − p,q )h ∈ J . Looking at Definition 5.1, we see that the good arrangement D of m p=1 Rp (defined by condition (3) in Definition 5.1) satisfies condition (b). Finally, the nq ’s are all different since (Rp , J ) is a Hajós factorization of Zn (if nq = nq then we would have rp,q +jp,q = rp,q +jp,q (mod n) with jp,q , jp,q ∈ J , rp,q , rp,q ∈ Rp , rp,q = rp,q , a contradiction). Proposition 6.2. Let A = (zp,q )0 p m−1, 0 q n−1 , be a matrix of size m × n satisfying the following conditions: (1) For each p ∈ {0, . . . , m − 1}, we have Rp = {zp,q | 0 q n − 1} = {0, . . . , n − 1} (mod n). (2) For each q, q ∈ {0, . . . , n − 1}, for each p, p ∈ {0, . . . , m − 1}, we have zp,q = zp ,q (mod n) if and only if q = q . (3) There exists a Krasner factorization (I, J ) of Zn and Hajós factorizations (R0 , T0 ), . . . , (I, J ) as a Krasner companion factorization, such that A (Rm−1 , Tm−1 ) of Zn having is an arrangement of m−1 (R p + J ) with (zp,q )0 q n−1 = Rp + J , 0 p m − 1. p=0 Set = |I |. Then, for each q ∈ {0, . . . , − 1}, an ordered sequence Jq = (j0,q , . . . , jm−1,q ) of elements of J exists and = |I | columns (zp,nq )0 p m−1 in A also exist such that, for each p ∈ {0, . . . , m − 1} and q ∈ {0, . . . , − 1}, we have zp,nq = rp,q + jp,q , with D = (rp,q )0 p m−1, 0 q −1 being a good arrangement of m−1 p=0 Rp with respect to the rows. Proof. Let D = (rp,q )0 p m−1, 0 q −1 be the good arrangement of m−1 p=0 Rp with respect to the rows, where we obviously have = |I |. In virtue of Proposition 6.1, for each q ∈ {0, . . . , − 1}, an ordered sequence Jq = (j0,q , . . . , jm−1,q ) of elements of J exists satisfying Eq. (7), i.e., rp,q + jp,q = nq (mod n). Now, let us consider the integers nq defined by Eq. (7). In view of condition (2) in the statement, for each q ∈ {0, . . . , − 1}, there is a unique column (zp,nq )0 p m−1 in A associated with nq , i.e., such that zp,nq = nq (mod n). Thus, in view of condition (3) in the statement, we have zp,nq = rp,q + jp,q for the unique pair (rp,q , jp,q ) ∈ Rp × J such that rp,q + jp,q = nq (mod n). Clearly, the columns (zp,nq )0 p m−1 , 0 q − 1 satisfy the conditions contained in the statement.
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
251
Finally, we explicitly note that we can state a dual version of Propositions 6.1 and 6.2 for good arrangements with respect to the columns.
7. Crossed two-dimensional Hajós factorizations Given a sequence (R1 , T1 ), . . . , (Rm , Tm ) of Hajós factorizations, we now consider matrices m having pairs m(r, v) of integers as elements and such that the good arrangement of R (resp. p=1 p q=1 Tq ), with respect to the rows (resp. columns), can be obtained by taking the induced arrangement having the first (resp. second) elements in the pairs as entries (Definition 7.2). We prove that for a given factorizing code C, words in C ∩ a ∗ ba ∗ , i.e., words in C with one occurrence of b s, can be canonically associated with one of these special matrices. We recall that for a finite subset X of A∗ , we set Xk = X ∩ (a ∗ b)k a ∗ . Definition 7.1. Let C1 = (a rp,q ba vp,q )1 p m, 1 q be an arrangement of C1 ⊆ a ∗ ba ∗ . The matrix R = (rp,q )1 p m, 1 q is the induced arrangement of the rows Rp = {rp,q | q ∈ {1, . . . , }} and the matrix T = (vp,q )1 p m, 1 q is the induced arrangement of the columns Tq = {vp,q | p ∈ {1, . . . , m}}. Furthermore, Rp,w = {a rp,q ba vp,q | 1 q } (resp. Tq,w = {a rp,q ba vp,q | 1 p m}) is a word-row (resp. a word-column) of C1 , for 1 p m (resp. 1 q ). Definition 7.2. An arrangement C1 = (a rp,q ba vp,q )1 p m, 1 q of C1 ⊆ a ∗ ba ∗ is a good arrangement (with (I, J ) as a Krasner associated pair) if it satisfies the following three conditions: (1) For each row Rp and each column Tq , 1 p m, 1 q , (Rp , Tq ) is a Hajós factorization of Zn having (I, J ) as a Krasner companion factorization with respect to a chain of divisors of n = |C1 |. (2) The induced arrangement of the rows is a good arrangement of m p=1 Rp with respect to the rows. (3) The induced arrangement of the columns is a good arrangement of lq=1 Tq with respect to the columns. Example 7.1. C1 = a {0,2,4} b + a {3,5} ba {3} + aba 5 has the following good arrangement (with ({0, 2, 4}, {0, 1}) as a Krasner associated pair): 0 a b a2b a4b C1 = . aba 5 a 3 ba 3 a 5 ba 3 Analogously, for C1 = a {0,2,4,12,14,16} ba {0,6,21} + a {0,4,8,12,16,20} ba {3} we have the following good arrangement (with ({0, 2, 4, 12, 14, 16}, {0, 1, 6, 7}) as a Krasner associated pair): 0 a2b a4b a 12 b a 14 b a 16 b a b 0 3 8 3 4 3 12 3 20 3 16 3 a ba a ba a ba a ba a ba a ba C1 = 0 6 . a ba a 2 ba 6 a 4 ba 6 a 12 ba 6 a 14 ba 6 a 16 ba 6 0 21 2 21 4 21 12 21 14 21 16 21 a ba a ba a ba a ba a ba a ba
252
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
Let us recall two known equations associated with sets C1 of words with one b s in a factorizing code C. Let P , S be finite subsets of A∗such that C = P (A−1)S +1. As a direct result, we have C0 = P0 (a − 1)S0 + 1 and Cr = i+j =r Pi (a − 1)Sj + i+j =r−1 Pi bSj , for r > 0 [7]. Consequently, there exists n ∈ N and a Krasner factorization (I, J ) of Zn such that: an − 1 C0 = a n , P 0 = a I , S 0 = a J , a I a J = . (10) a−1 Furthermore, if we set P1 = i∈I a i ba Li , S1 = j ∈J a Mj ba j , I , J , Li , Mj ⊆ N, we have: C1 = C ∩ a ∗ ba ∗ = a I ba J + a i ba Li (a − 1)a J + a Mj (a − 1)a I ba j 0. i∈I
(11)
j ∈J
Proposition 7.1 (De Felice [9]). Let C1 be a subset of a ∗ ba ∗ which satisfies Eqs. (10) and (11). Then, there exists a unique arrangement A 1 = (a zp,q ba tp,q )0 p n−1, 0 q n−1 of a J C1 a I which satisfies the following properties, for p, q ∈ {0, . . . , n − 1}: (1) Rp = {zp,q | q ∈ {0, . . . , n − 1}} = {0, . . . , n − 1} (mod n), Tq = {tp,q | p ∈ {0, . . . , n − 1}} = {0, . . . , n − 1} (mod n). (2) Two words a zp,q ba tp,q , a zp ,q ba tp ,q have the same exponent zp,q = zp ,q = q (mod n) (resp. tp,q = tp ,q = p (mod n)) if and only if q = q (resp. p = p ), i.e., they belong ). to the same word-column Tq,w (resp. word-row Rp,w it holds: (3) For the word-rows Rp,w and the word-columns Tq,w ∀ i ∈ I, j ∈ J, a r ba v ∈ C1 a r+j ba v+i ∈ Rp,w ⇒ a J a r ba v+i ⊆ Rp,w , a r+j ba v+i ∈ Tq,w ⇒ a r+j ba v a I ⊆ Tq,w .
) in (resp. word-column Tq,w Proposition 7.2 (De Felice [9]). For every word-row Rp,w
A 1 , a subset Rp,w = a rp,1 ba vp,1 + · · · + a rp, ba vp, (resp. Tq,w = a r1,q ba v1,q + · · · + a rm,q ba vm,q ) of words in C1 exists such that: Rp,w = a J (a rp,1 ba vp,1 +ip,1 + · · · + a rp,l ba vp, +ip, ),
= (a r1,q +j1,q ba v1,q + · · · + a rm,q +jm,q ba vm,q )a I , ) (resp. Tq,w
where the order of the elements is not taken into account and ip,1 , . . . , ip, ∈ I (resp. , . . . ,j rp,g ba vp,g ∈ j1,q m,q ∈ J ) are not necessarily different. Furthermore, let Rp = {rp,g | a
| a rg,q ba vg,q ∈ T Rp,w } and Tq = {vg,q q,w }. Thus, for p, q ∈ {0, . . . , n − 1}, (Rp , Tq ) is a Hajós factorization of Zn having (I, J ) as a Krasner companion factorization and it holds:
a Rp = a J a Rp ,
a Tq = a Tq a I .
Let C1 be a subset of a ∗ ba ∗ which satisfies Eq. (11) with (I, J ) defined by Eq. (10). Then C1 satisfies the conditions contained in Proposition 7.1 and let A 1 be the corresponding arrangement of a J C1 a I . In Proposition 7.3 below, we show that there exists a good
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
253
arrangement B of C1 with (I, J ) as a Krasner associated pair. In the proof of this result, we construct B starting with A 1 and with the induced arrangement A of the rows in A 1 , by the following matrix transformations: 1
A 1 → B1 (defined by|I | columns in A 1 which are selected according to Proposition 6.2), 2
→ B1 (defined by erasing the elements of a J on the left of b in B1 ), 3
→ B (defined by the dual version of 1 , i.e., by |J | selected rows in B1 ), 4
→ B (defined by the dual version of 2 , i.e., by erasing the elements of a I on the right of b in B ). Proposition 7.3. Let C1 be a subset of a ∗ ba ∗ which satisfies Eq. (11) with (I, J ) defined by Eq. (10). Then, there exists a good arrangement of C1 with (I, J ) as a Krasner associated pair. Proof. Let C1 be a subset of a ∗ ba ∗ which satisfies Eq. (11) with (I, J ) defined by Eq. (10). Then, C1 satisfies the conditions contained in Propositions 7.1 and 7.2 and we will use the same notations used in these propositions. Let (Rp , Tq ) be the Hajós factorizations of Zn defined in Proposition 7.2, let A 1 be the arrangement of a J C1 a I satisfying the conditions contained in Proposition 7.1. Consider the induced arrangement A = (zp,q )0 p n−1, 0 j n−1 of the rows in A 1 . By using Proposition 6.2, an ordered sequence Jq = (j0,q , . . . , jn−1,q ) of elements of J exists and = |I | columns A = (zp,nq )0 p n−1, 0 q −1 in A also exist such that, for each p ∈ {0, . . . , n − 1} and q ∈ {0, . . . , − 1}, we have zp,nq = rp,q + jp,q with D = (rp,q )0 p n−1, 0 q −1 being a good arrangement of n−1 p=0 Rp with respect to the rows. Consider the columns tp,nq r +j p,q p,q ba )0 p n−1, 0 q −1 of A 1 such that the induced arrangement of B1 = (a the rows of B1 is A . We claim that, when we erase in B1 the elements of a J on the left (i.e., when we consider the matrix defined by the word-columns Tn q ,w = (a r0,q ba v0,q + · · · + a rn−1,q ba vn−1,q )a I ) we obtain an arrangement B1 of C1 a I . Intuitively, when we erase the elements of a J on the left , we obtain |J | copies of a subset of C a I : B is obtained by selecting in a word-row Rp,w 1 1 one copy of each element in this subset. In detail, for each word a r ba v ∈ C1 , there exist a of A 1 and i ∈ I such that all the elements in a r+J ba v+i are elements of word-row Rp,w Rp,w . Thus, r ∈ Rp and there exist q, rp,q , jp,q such that r = rp,q and zp,nq = rp,q + jp,q . Since a r a J ba ∗ ∩ Rp,w = a r+J ba v+i we have that a r ba v+i is in Tn q ,w . Furthermore, when we consider in B1 the corresponding arrangement of the exponents of the a s on the left of b, we find the good arrangement D. We now find the required arrangement of C1 by using the same argument as above with respect to the columns and to the exponents of the a s on the right of b. Indeed, each word-column Tn q ,w in B1 is also a word-column in A 1 . Thus, B1 (and so B1 ) maintains all properties of A 1 contained in Propositions 7.1, 7.2, with respect to the columns. In particular, the induced arrangement T = (tp,nq )0 p n−1, 0 q −1 of the columns in B1 is an arrangement of −1 q=0 (Tq + I ) such that (Tq + I ) is the qth column, 0 q − 1.
254
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
Furthermore, we have Tn q = Tq +I = {tp,nq | p ∈ {0, . . . , n−1}} = {0, . . . , n−1} (mod n) tp ,n
and two words a rp,q ba tp,nq , a rp ,q ba q have the same exponent tp,nq = tp ,nq = . p (mod n) if and only if p = p , i.e., they belong to the same word-row Rp,w Then, by using the dual version of Proposition 6.2, for each p ∈ {0, . . . , m − 1}, with m = |J |, an ordered sequence Ip = (ip,0 , . . . , ip,−1 ) of elements of I exists and m = |J | rows T = (tn p ,nq )0 q −1 in T also exist such that, for each p ∈ {0, . . . , m − 1} and q ∈ {0, . . . , − 1}, we have tn p ,nq = vp,q + ip,q with D = (vp,q )0 p m−1, 0 q −1 being a good arrangement of −1 q=0 Tq with respect to the columns. Consider the rows B = (a rp,q ba vp,q +ip,q )0 p m−1, 0 q −1 of B1 such that the induced arrangement of the columns of B is T . Let us prove that when we erase in B the elements of a I on the right, we obtain a good arrangement B = (a rp,q ba vp,q )0 p m−1, 0 q −1 of C1 . Firstly, B is an arrangement of C1 . Intuitively, when we erase the elements of a I on the right in a word-column Tn q ,w , we obtain |I | copies of a subset of C1 : B is obtained by selecting one copy of each element in this subset. In detail, we have already observed that B1 is an arrangement of C1 a I which maintains all properties of A 1 contained in Propositions 7.1, 7.2, with respect to the columns. Now, for each a r ba v ∈ C1 , a r ba v belongs to a column in B1 (since B1 is an arrangement of C1 a I ) and so all the elements in a r ba v+I are in a word-column Tn q ,w in B1 , in view of condition (3) in Proposition 7.1. Thus, there exist p, vp,q , ip,q such that v = vp,q and tn p ,nq = vp,q + ip,q . Since a ∗ ba v+I ∩ Tn q ,w = a r ba v+I , we have a r ba v ∈ B and B is an arrangement of C1 . Finally, when we consider B, we see that the induced arrangement of the rows is a set of rows in D and the induced arrangement of the columns is D . Thus, B is a good arrangement of C1 .
Suppose that (I, J ) is a Krasner factorization of Zn and suppose that C1 has a good arrangement with (I, J ) as a Krasner associated pair. A natural question which arose is whether the set C1 ∪ a n is a code and partial results towards a positive answer to this question have been given in [12]. We end this section with an example which shows that the hypothesis of the existence of this special arrangement is necessary. Indeed, in Example 7.2, we point out that sets C1 of words exist with C1 ⊆ a ∗ ba ∗ , which are not codes but which have arrangements over a matrix such that for any row Tp and any column Rq , (Tp , Rq ) is a Hajós factorization of Zn . Example 7.2. Consider C1 = {b, aba, a 4 ba, a 5 b, a 4 ba 2 , a 3 ba 3 , ba 3 , a 7 ba 2 }. C1 is not a code since (ba 3 )(aba) = b(a 4 ba). Observe that n is uniquely defined by n = |C1 | and thus n = 8. We have two possible arrangements of C1 over a matrix such that for any row Tp and any column Rq , (Tp , Rq ) is a Hajós factorization of Z8 which correspond to the chain 1|2|4|8 of divisors of 8. They are not good arrangements and are reported below: C1 =
a 0 ba 0 a 4 ba 2
a 1 ba 1 a 3 ba 3
a 4 ba 1 a 0 ba 3
a 5 ba 0 a 7 ba 2
,
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
255
with corresponding Krasner pair I = {0, 1, 4, 5}, J = {0, 2} and
a 4 ba 1 a 5 ba 0 C1 = 7 2 a ba a 0 ba 3
a 0 ba 0 a 1 ba 1 , a 3 ba 3 a 4 ba 2
with corresponding Krasner pair I = {0, 4}, J = {0, 1, 2, 3}. We also observe that codes exist which have no (good) arrangement, namely X = {ba, ab, ba 2 , a 3 ba 2 }. We know that X + a 4 has no factorizing completion but we do not know whether X + a 4 has a finite completion. If this finite completion existed then it would be a counterexample to the factorization conjecture.
References [1] J. Berstel, D. Perrin, Theory of Codes, Academic Press, New York, 1985. [2] J. Berstel, C. Reutenauer, Rational Series and Their Languages, EATCS Monographs on Theoretical Computer Science, Vol. 12, Springer, Berlin, 1988. [3] J.M. Boë, Sur les codes factorisants, in: D. Perrin (Ed.), “ Théorie des codes”, LITP, 1979, pp. 1–8. [4] J.M. Boë, Sur les codes synchronisants coupants, in: A. de Luca (Ed.), “Non Commutative Structures in Algebra and Geometric Combinatorics”, Quaderni della Ric. Sci. del C.N.R., Vol. 109, 1981, pp. 7–10. [5] V. Bruyère, M. Latteux, Variable-Length Maximal Codes, in: Proc. Icalp 96, Lecture Notes in Computer Science, Vol. 1099, 1996, pp. 24–47. [6] C. De Felice, Construction of a family of finite maximal codes, Theoret. Comput. Sci. 63 (1989) 157–184. [7] C. De Felice, A partial result about the factorization conjecture for finite variable-length codes, Discrete Math. 122 (1993) 137–152. [8] C. De Felice, An application of Hajós factorizations to variable-length codes, Theoret. Comput. Sci. 164 (1996) 223–252. [9] C. De Felice, On a Property of the Factorizing Codes, Internat. J. Algebra Comput. (Special issue dedicated to M. P. Schützenberger) 9 (1999) 325–345. [10] C. De Felice, On some Schützenberger conjectures, Inform. Comput. 168 (2001) 144–155. [11] C. De Felice, On a complete set of operations for factorizing codes, Theoret. Inform. Appl. (2005) to appear. [12] C. De Felice, Solving inequalities with factorizing codes: part 1, manuscript (2005). [13] C. De Felice, C. Reutenauer, Solution partielle de la conjecture de factorisation des codes, C.R. Acad. Sci. Paris 302 (1986) 169–170. [14] G. Hajós, Sur la factorisation des groupes abéliens, Casopis Pest. Mat. Fys. 74 (1950) 157–162. [15] M. Krasner, B. Ranulac, Sur une propriété des polynômes de la division du cercle, C.R. Acad. Sci. Paris 240 (1937) 397–399. [16] N.H. Lam, Hajós factorizations and completion of codes, Theoret. Comput. Sci. 182 (1997) 245–256. [17] D. Perrin, M.P. Schützenberger, Un problème élémentaire de la théorie de l’information, “Théorie de l’Information”, Colloques Internat. CNRS, Vol. 276, Cachan, 1977, pp. 249–260. [18] D. Perrin, M.P. Schützenberger, A conjecture on sets of differences of integer pairs, J. Combin. Theory B 30 (1981) 91–93. [19] A. Restivo, On codes having no finite completions, Discrete Math. 17 (1977) 309–316. [20] A. Restivo, S. Salemi, T. Sportelli, Completing codes, RAIRO Inform. Théoret. Appl. 23 (1989) 135–147. [21] C. Reutenauer, Sulla fattorizzazione dei codici, Ricerche Mat. XXXII (1983) 115–130. [22] C. Reutenauer, Non commutative factorization of variable-length codes, J. Pure Appl. Algebra 36 (1985) 167–186.
256
C. De Felice / Theoretical Computer Science 340 (2005) 240 – 256
[23] A.D. Sands, On the factorisation of finite abelian groups, Acta Math. Acad. Sci. Hungar. 8 (1957) 65–86. [24] M.P. Schützenberger, Une théorie algébrique du codage, Séminaire Dubreil-Pisot 1955–56, exposé no 15, 1955, 24pp. [25] M.P. Schützenberger, Codes à longueur variable, manuscript, 1965, reprinted in: D. Perrin (Ed.), “Théorie des codes”, LITP, 1979, pp. 247–271. [26] L. Zhang, C.K. Gu, Two classes of factorizing codes-(p, p)-codes and (4, 4)-codes, in: M. Ito, H. Jürgensen (Eds.), “Words Languages and Combinatorics II”, World Scientific, Singapore, 1994, pp. 477–483.
Theoretical Computer Science 340 (2005) 257 – 272 www.elsevier.com/locate/tcs
Tile rewriting grammars and picture languages夡 Stefano Crespi Reghizzi, Matteo Pradella∗ DEI - Politecnico di Milano and CNR IEIIT-MI, Piazza Leonardo da Vinci, 32, I-20133 Milano, Italy
Abstract Tile rewriting grammars (TRG) are a new model for defining picture languages. A rewriting rule changes a homogeneous rectangular subpicture into an isometric one tiled with specified tiles. Derivation and language generation with TRG rules are similar to context-free grammars. A normal form and some closure properties are presented. We prove this model has greater generative capacity than the tiling systems of Giammarresi and Restivo and the grammars of Matz, another generalization of context-free string grammars to 2D. Examples are shown for pictures made by nested frames and spirals. © 2005 Elsevier B.V. All rights reserved. Keywords: Picture languages; 2D languages; Tiling systems; Context-free grammars; Locally testable languages
1. Introduction In the past, several proposals have been made for applying to pictures (or 2D) languages the generative grammar approach but in our opinion none of them matches the elegance and descriptive adequacy that made context free (CF) grammars so successful for string languages. A picture is a rectangular array of terminal symbols (the pixels). A survey of formal models for picture languages is [3] where different approaches are compared and related: tiling systems, cellular automata, and grammars. The latter had been
夡 A preliminary version is [6]. Work partially supported by MIUR, Progetto Linguaggi formali e automi, teoria e applicazioni.
∗ Corresponding author. Tel.: +39 02 2399 3495; fax: +39 02 2399 3666.
E-mail addresses:
[email protected] (S. Crespi Reghizzi),
[email protected] (M. Pradella). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.041
258
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
surveyed in more detail by Siromoney [7]. Classical 2D grammars can be grouped into two categories 1 called matrix and array grammars. The array grammars, introduced by Rosenfeld, impose the constraint that the left and right parts of a rewriting rule must be isometric arrays; this condition overcomes the inherent problem of “shearing” which pops up while substituting a subarray in a host array. Siromoney’s matrix grammars are parallel-sequential in nature, in the sense that first a horizontal string of nonterminals is derived sequentially, using the horizontal productions; and then the vertical derivations proceed in parallel, applying a set of vertical productions. Several variations have been made, for instance [1]. A particular case is the 2D right-linear grammars in [3]. Matz’s context-free picture grammars [5] rely on the notion of row and column concatenation and their closures. A rule is like a string CF one, but the right part is a 2D regular expression. The shearing problem is avoided because, say, row concatenation is a partial operation which is only defined on pictures of identical width. Exploring a different course, our new model, tile rewriting grammar (TRG), intuitively combines Rosenfeld’s isometric rewriting rules with the tiling system (TS) of Giammarresi and Restivo [2]. The latter defines the family of recognizable 2D languages (the same accepted by on-line tessellation automata of Inoue and Nakamura [4]). A TRG rule is a schema having a nonterminal symbol to the left and a local 2D language to the right over terminals and nonterminals; that is the right part is specified by a set of fixed size tiles. As in matrix grammars, the shearing problem is avoided by an isometric constraint, but the size of a TRG rule need not be fixed. The left part denotes any rectangle filled with the same nonterminal. Whatever size the left part takes, the same size is assigned to the right part. To make this idea effective, we impose a tree partial order on the areas which are rewritten. A progressively refined equivalence relation implements the partial ordering. Derivations can then be visualized in 3D as well nested prisms, the analogue of syntax trees of string grammars. To our knowledge, this approach is novel and is able to generate an interesting gamut of pictures: grids, spirals, and in particular a language of nested frames, which is in some way the analogue of a Dyck language. Section 2 lists the basic definitions. Section 3 presents the definition of TRG grammar and derivation, two examples, and proves the basic properties of the model: canonical derivation, uselessness of concave rules, normal forms, closures for some operations. Section 3 compares TRG with other models, proving that its generative capacity exceeds that of TS and of Matz’s CF picture grammars. The appendix contains the grammar of Archimedes spirals.
2. Basic definitions Many of the following notation and definitions are from [3].
1 Leaving aside the graph grammar models because they generate graphs, not 2D matrices.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
259
Definition 1. For a finite alphabet , the set of pictures is ∗∗ . For h, k 1, (h,k) denotes the set of pictures of size (h, k) (we will use the notation |p| = (h, k), |p|row = h, |p|col = k). # is used when needed as a boundary symbol; pˆ refers to the bordered version of picture p. That is
p ∈ (h,k)
p(1, 1) . . . p(1, k) .. .. .. ≡p= , . . . p(h, 1) . . . p(h, k)
# # # p(1, 1) .. pˆ = ... . # p(h, 1) # #
... # . . . p(1, k) .. .. . . . . . p(h, k) ... #
# # .. . . # #
A pixel is an element p(i, j ). If all pixels are identical to C ∈ the picture is called homogeneous and denoted as C-picture. Row and column concatenations are denoted and ¸, respectively. pq is defined iff p and q have the same number of columns; the resulting picture is the vertical juxtaposition of p over q. pk is the vertical juxtaposition of k copies of p; p ∗ is the corresponding closure. ¸,k ¸ ,∗¸ are the column analogues. The pixel-by-pixel cartesian product (written p ⊗ q) is defined iff |p| = |q| and is such that for all i, j , (p ⊗ q)(i, j ) = p(i, j ), q(i, j ) . Definition 2. Let p be a picture of size (h, k). A subpicture of p at position (i, j ) is a picture q such that, if (h , k ) is the size of q, then h h, k k, and there exist integers i, j (i h − h +1, j k−k +1) such that q(i , j ) = p(i+i −1, j +j −1) for all 1 i h , 1 j k . We will write also q (i,j ) p, or the shortcut q p ≡ ∃i, j (q (i,j ) p). Moreover, if q (i,j ) p, we define coor (i,j ) (q, p) as the set of coordinates of p where q is located: coor (i,j ) (q, p) = {(x, y) | i x i + |q|row − 1 ∧ j y j + |q|col − 1}. Conventionally, coor (i,j ) (q, p) = ∅, if q is not a subpicture of p. If q coincides with p we write coor(p) instead of coor (1,1) (p, p).
Definition 3. Let be an equivalence relation on coor(p), written (x, y) ∼(x , y ). Two
subpictures q (i,j ) p, q (i ,j ) p are -equivalent, written q ∼ q , iff for all pairs (x, y) ∈
coor (i,j ) (q, p) and (x , y ) ∈ coor (i ,j ) (q , p) it holds (x, y) ∼(x , y ). A homogeneous C-subpicture q p is called maximal with respect to relation iff for every -equivalent C-subpicture q we have coor(q, p) ∩ coor(q , p) = ∅ ∨ coor(q , p) ⊆ coor(q, p). In other words q is maximal if any C-subpicture which is equivalent to q is either a subpicture of q or it is not overlapping. 2
2 Maximality as used in [6] is different. It corresponds to the condition coor(q, p)coor(q , p).
260
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
Definition 4. For a picture p ∈ ∗∗ the set of subpictures (or tiles) with size (h, k) is Bh,k (p) = {q ∈ (h,k) | q p}. We assume B1,k to be only defined on (1,∗) (horizontal strings), and Bh,1 on (∗,1) (vertical strings). For brevity, for tiles of size (1, 2), (2, 1), or (2, 2), we introduce the following notation: if |p| = (1, k), k > 1, B1,2 (p) 'p( = B2,1 (p) if |p| = (h, 1), h > 1, B2,2 (p) if |p| = (h, k), h, k > 1. Definition 5. Consider a set of tiles ⊆ (i,j ) . The locally testable language in the strict sense defined by (written LOC u () 3 ) is the set of pictures p ∈ ∗∗ such that Bi,j (p) ⊆ . The locally testable language defined by a finite set of tiles LOC u,eq ({1 , 2 , . . . , n }) 4 is the set of pictures p ∈ ∗∗ such that for some k, Bi,j (p) = k . The bordered locally testable language defined by a finite set of tiles LOC eq ({1 , 2 , . . . , n }) is the set of pictures p ∈ ∗∗ such that for some k, Bi,j (p) ˆ = k . Definition 6. Substitution. If p, q, q are pictures, q (i,j ) p, and q, q have the same size, then p[q /q](i,j ) denotes the picture obtained by replacing the occurrence of q at position (i, j ) in p with q . Definition 7. The (vertical) mirror image and the (clockwise) rotation of a picture p (with |p| = (h, k)), respectively, are defined as follows: p(h, 1) . . . p(h, k) .. .. .. Mirror(p) = , . . . p(1, 1) . . . p(1, k)
p(h, 1) . . . p(1, 1) .. .. .. p = . . . . p(h, k) . . . p(1, k) R
Note that the sizes of Mirror(p) and pR are, respectively, (h, k) and (k, h). 3. Tile rewriting grammars The main definition follows: Definition 8. A Tile Rewriting Grammar (in short grammar) is a tuple (, N, S, R), where is the terminal alphabet, N is a set of nonterminal symbols, S ∈ N is the starting symbol, R is a set of rules. R may contain two kinds of rules: Fixed size: A → t, where A ∈ N , t ∈ ( ∪ N )(h,k) , with h, k > 0; Variable size: A → , where A ∈ N , ⊆ ( ∪ N )(h,k) , with 1 h, k 2. 3 To avoid confusion with LOC defined in [3], we mark these with “u” (stands for unbordered, because they do not use boundary symbols). 4 eq stands for equality test.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
261
Intuitively a fixed size rule is intended to match a subpicture of (small) bounded size, identical to the right part t. A variable size rule matches any subpicture of any size which can be tiled using all the elements t of the tile set . However, fixed size rules are not a special case of variable size rules. Definition 9. Consider a grammar G = (, N, S, R), let p, p ∈ ( ∪ N )(h,k) be pictures of identical size, and let , be equivalence relations over coor(p). We say that (p , ) is derived in one step from (p, ), written (p, ) ⇒G (p , ) iff for some A ∈ N and for some rule : A → . . . ∈ R there exists in p a A-subpicture r (m,n) p, maximal with respect to , such that • p is obtained substituting r with a picture s, i.e. p = p[s/r](m,n) , where s is defined as follows: Fixed size: if = A → t, then s = t; Variable size: if = A → , then s ∈ LOC u,eq (). • Let z be coor (m,n) (r, p). Let be the -equivalence class containing z. Then, is equal to , for all the equivalence classes = ; in is divided in two equivalence classes, z and its complement with respect to (= ∅ if z = ). More formally,
= \ {((x1 , y1 ), (x2 , y2 )) | (x1 , y1 ) ∈ z xor (x2 , y2 ) ∈ z} . The subpicture r is named the application area of rule in the derivation step. n We say that (q, ) is derivable from (p, ) in n steps, written (p, ) ⇒G (q, ), iff p = q
and = , when n = 0, or there are a picture r and an equivalence relation
such that n−1
∗
(p, ) ⇒G (r,
) and (r,
) ⇒G (q, ). We use the abbreviation (p, ) ⇒G (q, ) for a derivation with n 0 steps. Definition 10. The picture language defined by a grammar G (written L(G)) is the set of p ∈ ∗∗ such that, if |p| = (h, k), then ∗ S (h,k) , coor(p) × coor(p) ⇒G (p, ), (1) ∗
where the relation is arbitrary. For short we write S ⇒G p. Note that the derivation starts with a S-picture isometric with the terminal picture to be generated, and with the universal equivalence relation over the coordinates. The equivalence relations computed by each step of (1) are called geminal relations. When writing examples by hand, it is convenient to visualize the equivalence classes of a geminal relation, by appending the same numerical subscript to the pixels of the application area rewritten by a derivation step. The final classes of equivalence represent in some sense a 2D generalization of the parenthesis structure that parenthesized context-free string grammars assigned to a sentence.
262
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
Example 11. Chinese boxes: G = (, N, S, R), where = {, , , , ◦}, N = {S}, and R consists of one fixed size, one variable size rule: S→
; S→
◦
◦ , S
◦
S , ◦
◦ ◦
S , S
S ◦
S , ◦
◦ S
◦ S , S S
S , S
◦ S
◦
,
S S
◦ , ◦
S ◦
◦
.
For brevity and readability, we will often specify a set of tiles by a sample picture exhibiting the tiles as its subpictures. We write | to separate alternative right parts of rules with the same left part (analogously to string grammars). The previous grammar becomes ◦ ◦ ◦ S S ◦ . | S→ ◦ S S ◦ ◦ ◦ A picture in L(G) is
◦ ◦ ◦ ◦
◦ ◦ ◦ ◦
◦ ◦ ◦ ◦
◦ ◦ ◦ ◦
◦ ◦ ◦ ◦
◦ ◦ ◦ ◦
and is obtained applying the variable size rule twice and then the fixed size rule. We show a complete derivation for a more general version of this language in the following example. Example 12. 2D Dyck analogue: The next language Lbox , a superset of Chinese boxes, can be defined by a sort of blanking rule. But since terminals cannot be deleted without shearing the picture, we replace them with a character b (blank or background). Empty frame: Let k 0. An empty frame is a picture defined by the regular expression: (¸(◦)k ¸ ¸)(◦¸bk ¸ ¸◦)k (¸(◦)k ¸ ¸), i.e. a box bordered by ◦, containing just b’s. Blanking: The blanking of an empty frame p is the picture del(p) obtained by applying the projection del(x) = b, x ∈ ∪ {b}. A picture p is in Lbox iff by repeatedly applying del to subpictures which are empty frames, an empty frame is obtained. To obtain the grammar, we add the following rules to the Chinese boxes grammar: S S S S S S X X , X → S S . S→ | X X S S X X S S X X To illustrate, in Fig. 1 we list the derivation steps of a picture. Nonterminals in the same equivalence class are marked with the same subscript. Although this language can be viewed as a 2D analogue of a Dyck’s string language, variations are possible and we do not claim the same algebraic properties as in 1D.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
263
Fig. 1. Example derivation with marked application areas.
3.1. Basic properties The next two statements, which follow immediately from Definitions 3 and 9, may be viewed as a 2D formulation of well-known properties of 1D CF derivations. Let p1 ⇒ · · · ⇒ pn+1 be a derivation, and r1 (i1 ,j1 ) p1 , . . . , rn (in ,jn ) pn the corresponding application areas. Disjointness of application areas: For any pf , pg , f < g, one of the following holds: (1) coor (ig ,jg ) (rg , pg ) ⊆ coor (if ,jf ) (rf , pf ); (2) coor (if ,jf ) (rf , pf ) ∩ coor (ig ,jg ) (rg , pg ) = ∅. That is, the application area of a later step is either totally placed within the application area of a previous step, or it does not overlap. As a consequence, a derivation can be represented in 3D as a well-nested forest of rectangular prisms, the analogous of derivation trees of string languages. Canonical derivation: The previous derivation is lexicographic iff f < g implies (if , jf ) lex (ig , jg ) (where lex is the usual lexicographic order). Then, the following result holds: ∗
∗
L(G) ≡ {p | S ⇒G p and ⇒G is a lexicographic derivation}.
264
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272 ∗
Definition 13. A rule of a grammar G is useful if there exists a derivation S ⇒G p ∈ ∗∗ which makes use of at some step; otherwise is called useless. Definition 14. Consider a grammar G = (, N, S, R). A variable size rule A → is called concave iff contains an element of the following set: A A x A A x A A , , , , x A A A A A A x where A ∈ N, x ∈ N ∪ , x = A. Theorem 15. A concave rule is useless. Proof. By contradiction, if A → , a concave rule, is used in a derivation, then LOC u,eq in Definition 9 compels the use of every tile in . But concave tiles generate pictures having a concave area filled with the same nonterminal, say A, and the geminal relation updated by the derivation step is such that this whole area is in the same equivalence class. But Definition 3 makes it impossible to find at following steps, a A-subpicture which is maximal with respect to the geminal relation; hence the derivation fails to produce a terminal picture. A useful grammar transformation consists of moving terminal symbols to fixed size rules.
Definition 16. A grammar G is in terminal normal form iff the only rules with terminals have the form A → x, x ∈ , i.e. they are unitary rules. Theorem 17. Every grammar G = (, N, S, R) has an equivalent grammar G = (, N , S, R ) in terminal normal form. Proof. To construct G , we eliminate terminals from variable size rules and nonunitary fixed size rules. N contains N, and for every terminal a, we have in N two nonterminals a, 0 and a, 1 . The idea is to replace every homogeneous a-subpicture with a chequered area of a, 0 and a, 1 , in which every application area has size (1, 1). (m,n) (m,n) Let Ch0 , (Ch1 , respectively) be a chequerboard made of 0 and 1 symbols, starting with a 0 (1, resp.) at the top-leftmost position. Let : N ∪ (N × {0, 1}) → N be the projection defined as (a, k ) = a, k , if a∈ ; (A, k ) = A, if A ∈ N . The mapping Chequer : P ( ∪ N )(m,n) → P (N )(m,n) is defined by |t| |t| Chequer() = (t ⊗ t ) | t ∈ ∧ t ∈ {Ch0 , Ch1 } . Then, for every variable size rule X → in G, the following rules are in G : X → | ⊆ Chequer() ∧ Chequer −1 ( ) = . |t| For every nonunitary fixed size rule X → t, the rule X → t ⊗ Ch0 is in G . Moreover, the unitary fixed size rules a, 0 → a, a, 1 → a are in G . G is by construction in terminal normal form.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
265
By construction, rules in G maintain the same structure and applicability of rules in G, as far as nonterminals in N are concerned. The only difference resides in derived terminal subpictures that are replaced in G by chequered subpictures made of new nonterminals, which maintain information about the terminal symbol originally derivable in G in the same area. The chequered structure of these subpictures contains only unitary application areas. Therefore, starting from these subpictures, and using the unitary terminal rules introduced in R , it is always possible to derive homogeneous terminal subpictures, identical to those derivable from G. Example 18. Terminal normal form of Example 11. It is possible to obtain the equivalent terminal normal form grammar by using the construction presented in Theorem 17. For ease of reading, we write the nonterminals a, k , a ∈ , k ∈ {0, 1} as ak . The resulting grammar (without useless rules) is the following: 0 ◦ 1 ◦ 0 ◦ 1 ◦ 0 1 ◦ 1 S S S S ◦0 0 ◦1 ◦0 1 ◦ 0 S S S S ◦1 ◦ 1 S S ◦0 0 1 | S→ | 1 0 ◦ 0 S S ◦1 ◦ 1 S S S S ◦0 ◦ 0 S S S S ◦1 1 ◦0 ◦1 0 1 ◦0 ◦1 ◦0 ◦1 0
0 → ; 1 → ; ◦0 → ◦; ◦1 → ◦. 3.2. Closure properties For simplicity, in the following theorem we suppose that L(G1 ), L(G2 ) contain pictures of size at least (2,2). Theorem 19. The family L(TRG) is closed under union, column/row concatenation, column/row closure operations, rotation, and alphabetical mapping (or projection). Proof. Consider two grammars G1 = (, N1 , A, R1 ) and G2 = (, N2 , B, R2 ). Suppose for simplicity that N1 ∩ N2 = ∅, S ∈ / N1 ∪ N2 , and that G1 , G2 generate pictures having size at least (2, 2). Then it is easy to show that the grammar G = (, N1 ∪ N2 ∪ {S}, S, R1 ∪ R2 ∪ R), where Union ∪: A A B B R= S→ , S→ A A B B is such that L(G) = L(G1 ) ∪ L(G2 ). Concatenation ¸/: A A B B R= S→ A A B B is such that L(G) = L(G1 )¸L(G2 ). The row concatenation case is analogous.
266
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
Closures ∗¸ /∗ : G = (, N1 ∪ {S}, S, R1 ∪ R), where
R= S→
A A S S A A S S
A A | A A
is such that L(G) = L(G1 )∗¸ . The row closure case is analogous. Rotation R: Construct the grammar G = (, N, A, R ), where R is such that, if B → t ∈ R1 is a fixed size rule, then B → t R is in R ; if B → ∈ R1 is a variable size rule, then B → is in R , with t ∈ implying t R ∈ . It is easy to verify that L(G) = L(G1 )R . Projection : Without loss of generality, we suppose G1 in terminal normal form (Theorem 17). Consider a projection : 1 → 2 . It is immediate to build a grammar G = (2 , N1 , A, R2 ), such that L(G ) = (L(G1 )): simply apply to unitary rules. That is, if X → x ∈ R1 , then X → (x) ∈ R2 , while the other rules of G1 remain in R2 unchanged. 4. Comparison with other models We first compare with CF string grammars, then TS, and finally with Matz’s 2D CF grammars. 4.1. String grammars If in Definition 8 we choose h = 1, then a TRG defines a string language. Such 1D TRGs are easily proved to be equivalent to CF string grammars. 5 In fact, the TRG model for string languages is tantamount to a notational variant [6] of classical CF grammars, where the right parts of rules are local languages. 4.2. Tiling systems and 2D CF grammars The next comparison has to face two technical difficulties: TS are defined by local languages with boundary symbols, which are not present in TRG, and the test of which tiles are present uses inclusion in TS, equality in TRG. First we prove that a class of local languages is strictly included in L(TRG). Lemma 20. L(LOC u,eq ) ⊆ L(TRG). Proof. Consider a local 2D language over defined (without boundaries) by the set of sets of allowed tiles {ϑ1 , ϑ2 , . . . , ϑn }, ϑi ⊆ (2,2) . An equivalent grammar is S → ϑ1 | ϑ2 | . . . | ϑn . 5 However the empty string cannot be generated by a 1D TRG.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
267
To simplify the comparison with TS, we reformulate them using the terms of Definition 5, showing their equivalence. Then we prove strict inclusion with respect to TRG. First we recall the original definition. Definition 21 (Giammarresi and Restivo [3, Definition 7.2]). A tiling system (TS) is a 4ple T = (, , ϑ, ), where and are two finite alphabets, (1) ϑ is a finite set of tiles over the alphabet ∪ {#}, and : → is a projection. Definition 22. The tiling systems T Seq and T Su,eq are the same as a TS, with the following respective changes: • Replace the local language defined by (1) with LOC eq ({ϑ1 , ϑ2 , . . . , ϑn }), where ϑi is a finite set of tiles over . • Replace the local language defined by (1) with LOC u,eq ({ϑ1 , ϑ2 , . . . , ϑn }), where ϑi is a finite set of tiles over . In T Su,eq there is no boundary symbol #. Lemma 23. L(T Seq ) ≡ L(T S). Proof. First, L(T S) ⊆ L(T Seq ). This is easy, because if we consider the tile set ϑ of a TS, by taking {ϑ1 , ϑ2 , . . . , ϑn } = P(ϑ) (the powerset) we obtain an equivalent T Seq . Second, we have to prove that L(T Seq ) ⊆ L(T S). In [3], the family of languages L(LOC eq ()), where is a set of sets of tiles, is proved to be a proper subset of L(T S) (Theorem 7.8). But L(T S) is closed with respect to projection, and L(T Seq ) is the closure with respect to projection of L(LOC eq ()). Therefore, L(T Seq ) ⊆ L(T S). Next we prove that boundary symbols can be removed. Lemma 24. L(T Su,eq ) ≡ L(T Seq ). Proof (Sketch). Part L(T Seq ) ⊆ L(T Su,eq ): Let T = (, , {ϑ1 , ϑ2 , . . . , ϑn }, ) be a T Seq . For every tile set ϑi , separate its tiles containing the boundary symbol # (call this subset ϑ i ) from the other tiles (ϑ
i ). That is, ϑi = ϑ i ∪ ϑ
i . Introduce a new alphabet and a bijective mapping br : → . We use symbols in to encode boundary, and new tile sets i to contain them: for every tile t in ϑ
i , if there is a tile in ϑ i which overlaps with t, then encode this boundary in a new tile t and put it in the set i . For example, suppose a b ∈ ϑ
1 c d overlaps with # # ∈ ϑ 1 a b and with d # ∈ ϑ 1 , # #
268
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
then both br(a) br(b) , c d and a br(b) br(c) br(d) are in i . Consider a T Su,eq T = (, ∪ , , ), where extends to as follows:
(br(a)) = (a) = (a), a ∈ , and ubr : ∪ → is defined as ubr(a) = br −1 (a), if a ∈ , otherwise = a, and it is naturally extended to tiles and tile sets. is the set ϑ | ϑ ⊆ ϑ
i ∪ i ∧ ubr(ϑ) = ϑ
i ∧ ϑ ∩ i = ∅ ∧ 1 i n . The proof that L(T ) = L(T ) is straightforward and is omitted. Part L(T Su,eq ) ⊆ L(T Seq ): Let T = (, , {ϑ1 , ϑ2 , . . . , ϑn }, ) be a T Su,eq . To construct an equivalent T Seq , we introduce the boundary tile sets i , defined as follows. For every tile a b ∈ ϑi , c d the following tiles are in i : # # # # # # # a b # # c c d d # , , , , , , , . # a a b b # # c d # # # # # # # Consider a T Seq T = (, , , ), where is the set ϑ ∪ ϑ i | ϑ ⊆ i ∧ ϑ = ∅ ∧ 1 i n . It is easy to show that L(T ) = L(T ).
Example 7.2 of [3], the language of squares over the alphabet {a}, is defined by the following T Su,eq : 1 0 0 0 1 0 0 0 2 0 0 , ϑ2 = 0 2 0 , ϑ3 = 1 0 , ϑ1 = 0 0 2 0 0 3 0 0 3 0 0 0 3
(0) = (1) = (2) = (3) = a. Theorem 25. L(T S) ⊆ L(TRG). Proof. It follows from Theorems 19, 20, 23 and 24, and the fact that L(T Su,eq ) is the closure of L(LOC u,eq ) with respect to projection.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
269
The following strict inclusion is an immediate consequence of the fact that, for 1D languages, L(T S) ⊂ L(CF ), and L(TRG) = L(CF ) \ { }. But we prefer to prove it by exhibiting an interesting picture language, made by the vertical concatenation of two specularly symmetrical rectangles. Theorem 26. L(T S) = L(TRG). Proof. Let = {a, b}. Consider the 2D language of palindromic columns, such as a b b a
b a a b
b b b b
L = {p | p = s Mirror(s) ∧ s ∈ (h,k) , h > 1, k 1}. Consider the grammar G: X S S X S X S→ | | , X S S X S X a b X X a b | . X→ | | X X a b a b It is easy to see that L(G) = L. We prove by contradiction that L ∈ / L(T S). Suppose that L ∈ L(T S). Therefore L is a projection of a local language L defined over some alphabet . Let a = || and b = ||, with a b. For an integer n, let Ln = {p | p = s Mirror(s) ∧ |s| = (n, n)}. Clearly, |Ln | = a n . Let L n be the set of pictures in L over whose projections are in Ln . By choice of b and by construction of Ln there are at most bn possibilities for the nth and (n + 1)th rows in the pictures of L n , because this is the number of mirrored stripe pictures of size (2, n) over . 2 For n sufficiently large a n bn . Therefore, for such n, there will be two different pictures p = sp Mirror(sp ), q = sq Mirror(sq ) such that the corresponding p = sp sp
, q = sq sq
have the same nth and (n+1)th rows. This implies that, by definition of local language, pictures v = sp sq
, w = sq sp
belong to L n , too. Therefore, pictures (v ) = sp Mirror(sq ), and (w ) = sq Mirror(sp ) belong to Ln . But this is a contradiction. 2
We terminate by comparing with a different generalization of CF grammars in two dimensions, Matz’s CF picture grammars (CFPG) [5], a model syntactically very similar to string CF grammars. The main difference is that the right parts of their rules use ¸, operators. Nonterminals denote unbound rectangular pictures. Derivation is analogous to
270
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
string grammars, but the resulting regular expression may or may not define a picture (e.g. a ¸(bb) does not generate any picture). Theorem 27. L(CFPG) ⊆ L(TRG). Proof (Sketch). Consider now a Matz’s CFPG grammar in Chomsky normal form. It may contain three types of rules: A → B ¸ C; A → B C; A → a. Moreover, suppose that B = C (this is always possible, if we permit copy rules like A → B). Then, A → B ¸ C corresponds to the following TRG rules: B B C C B C C B B C A→ | | | B B C C B C C B B C B B C C | B C C | B B C | B C. To obtain A → B, just delete C from the previous rules. The case is analogous to ¸, while A → a is trivial. Theorem 28. L(CFPG) = L(TRG). Proof. It is a consequence of Theorems 25, 26, and 27, and the fact from [5] that L(T S) L(CFPG). An example of a TRG but not CFPG language is the following. We know from [5] that the “cross” language, which consists of two perpendicular b-lines on a background of a, is not in L(CFPG). It is easy to show that the following grammar defines the language: a a b a a b a a , B B A A B → a a , A → B B A A b b b b b , S→ C C D D C C D D a a b a a C→ , D→ . a a b a a The fine control on line connections provided by TRG rules allows the definition of complex recursive patterns, exemplified by the spirals presented in the appendix. 5. Conclusions The new TRG model extends the context-free string grammars to two dimensions. Each rule rewrites a homogeneous rectangle as an isometric one, tiled with a specified tile set. In a derivation the rectangles, rewritten at each step, are partially ordered by the subpicture relation, which can be represented in three dimensions by a forest of well-nested prisms, the analogue of syntax trees for strings. Spirals and nested boxes are typical examples handled by TRG.
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
271
The generative capacity of TRG is greater than that of two previous models: TS and Matz’s context-free picture grammars. Practical applicability to picture processing tasks (such as pattern recognition and image compression) remains to be investigated, which will ultimately depend on the expressive power of the new model and on the availability of good parsing algorithms. The analogy with string grammars raises to the educated formal linguist a variety of questions, such as the formulation of a pumping lemma. For comparison with other models, several questions may be considered, e.g whether TRG and TS families coincide on a unary alphabet, or the generative capacity of nonrecursive TRG versus TS.
Acknowledgements Antonio Restivo called our attention to the problem of “2D Dyck languages”. We thank Alessandra Cherubini, Pierluigi San Pietro, Alessandra Savelli, and Daniele Scarpazza for their comments.
Appendix A Grammar for defining discrete Archimedean spirals with step 3. 6
A A V S→ V C C
A A V V C C
H H Q Q K K
H H Q Q K K
H B H B Q W Q W • D • D
B B W W D D
• • • • ; Q → S S |• · · •, S S • · · •
• • • • • • • · · · A → • · · ; B → · · •; C → • · · ; D → · • · · · · • • • • ·
· • · •, · •
• • · · · · ; K → · · ; V → • · · ; W → · H → • · · · · · • •
6 By Daniele Paolo Scarpazza.
· • · •
.
272
S. Crespi Reghizzi, M. Pradella / Theoretical Computer Science 340 (2005) 257 – 272
An example picture:
References [1] H. Fernau, R. Freund, Bounded parallelism in array grammars used for character recognition, in: P. Perner, P. Wang, A. Rosenfeld (Eds.), Advances in Structural and Syntactical Pattern Recognition (Proc. of the SSPR’96), Vol. 1121, Springer, Berlin, 1996, pp. 40–49. [2] D. Giammarresi, A. Restivo, Recognizable picture languages, Internat. J. Pattern Recogn. Artif. Intell. 6 (2–3) (1992) 241–256 (Special Issue on Parallel Image Processing). [3] D. Giammarresi, A. Restivo, Two-dimensional languages, in: A. Salomaa, G. Rozenberg (Eds.), Handbook of Formal Languages, Vol. 3, Beyond Words, Springer, Berlin, 1997, pp. 215–267. [4] K. Inoue, A. Nakamura, Some properties of two-dimensional on-line tessellation acceptors, Inform. Sci. 13 (1977) 95–121. [5] O. Matz, Regular expressions and context-free grammars for picture languages, in: Proc. of the 14th Annu. Symp. on Theoretical Aspects of Computer Science, Lecture Notes in Computer Science, Vol. 1200, Lübeck, Germany, 27 February–1 March 1997, Springer, Berlin, pp. 283–294. [6] S. Crespi Reghizzi, M. Pradella, Tile rewriting grammars, in: Proc. of the Seventh Internat. Conf. on Developments in Language Theory (DLT 2003), Lecture Notes in Computer Science, Vol. 2710, Szeged, Hungary, July 2003, Springer, Berlin, pp. 206–217. [7] R. Siromoney, Advances in Array Languages, in: H. Ehrig, M. Nagl, G. Rozenberg, A. Rosenfeld (Eds.), Proc. of Third Internat. Workshop on Graph-Grammars and Their Application to Computer Science, Lecture Notes in Computer Science, Vol. 291, Springer, Berlin, 1987, pp. 549–563.
Theoretical Computer Science 340 (2005) 273 – 279 www.elsevier.com/locate/tcs
Counting bordered and primitive words with a fixed weight Tero Harjua,∗ , Dirk Nowotkab a Department of Mathematics, Turku Centre for Computer Science (TUCS), University of Turku,
FIN-20014 Turku, Finland b Institute of Formal Methods in Computer Science, University of Stuttgart, D-70569 Stuttgart, Germany
Abstract A word w is primitive if it is not a proper power of another word, and w is unbordered if it has no prefix that is also a suffix of w. We study the number of primitive and unbordered words w with a fixed weight, that is, words for which the Parikh vector of w is a fixed vector. Moreover, we estimate the number of words that have a unique border. © 2005 Elsevier B.V. All rights reserved. Keywords: Combinatorics on words; Borders; Primitive words; Möbius function
1. Introduction Let w denote a finite word over some alphabet A. We say that w is bordered if there is a non-empty proper prefix x of w that is also a suffix of w. If there is no such x then w is called unbordered. We say that w is primitive if w = x k , for some k ∈ N, implies that k = 1 and x = w. We often assume that the alphabet is ordered, A = {a1 , a2 , . . . , aq }. In this case, for a word w ∈ A∗ , let (w) denote by (|w|a1 , |w|a2 , . . . , |w|aq ) the Parikh vector of w, where |w|a denotes the number of occurrences of the letter a in w. We also say that w has weight (w). The number of primitive words and unbordered words of a fixed length and an alphabet of a fixed size is well-known, see for example [1–5,7] and the sequences A027375, A003000, ∗ Corresponding author. Fax: +358 2 3336595.
E-mail addresses: harju@utu.fi (T. Harju),
[email protected] (D. Nowotka). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.040
274
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
A019308, and A019309 in Sloane’s database of integer sequences [6]. We will recall these results with short arguments and extend them to the case where the words we consider have a fixed weight. Moreover, we estimate the number of words that have exactly one border. Section 2 contains results on counting the number of primitive words. Section 3 investigates the number of bordered words. Finally, we deal with the number of words with exactly one border in Section 4. In the rest of this section we will fix our notation. For more general definitions see [2]. Let A be a finite, non-empty set called alphabet. The elements of A are called letters. Let a finite sequence of letters be called (finite) word. Let A∗ denote the monoid of all finite words over A where ε denotes the empty word. Let |w| denote the length of w, and let |w|a denote the number of occurrences of a in w, where a ∈ A. If w = uv then u is called prefix of w, denoted by u p w, and v is called suffix of w, denoted by v s w. A word w is called bordered if there exist non-empty words x, y, and z such that w = xy = zx, and x is called a border of w. Let X be a set, then |X| denotes the cardinality of X. The Möbius function : N → Z is defined as follows: (−1)t if n = p1 p2 . . . pt for distinct primes pi , (n) = 1 if n = 1, 0 if n is divisible by a square. The Möbius inversion formula for two functions f and g is given by: g(n) = f (d) d|n
if and only if f (n) =
d|n
(d)g(n/d).
2. Primitive words Let Pq (n) denote the number of primitive words of length n over an alphabet of size q. It is well-known, see for example [3,2] and the sequence A027375 in [6], that (d)q n/d . (1) Pq (n) = d|n
Indeed, let A with |A| = q be a finite alphabet of letters. Every word w has a unique primitive root v for which w = v d for some d|n, where n = |w|. Since there are exactly q n words of length n, Pq (d). qn = d|n
We are in the divisor poset, where the Möbius inversion gives (1). In this paper we investigate the number of primitive words with a fixed weight, that is, each letter has a fixed number of occurrences. Consider an ordered alphabet A = {a1 , a2 , . . . , aq }
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
275
of q 1 letters. For a word w ∈ A∗ , let (w) denote (|w|a1 , |w|a2 , . . . , |w|aq ) which is called the Parikh vector of w. For a given vector k = (k1 , k2 , . . . , kq ), let P(k) = {w | w primitive and (w) = k} q and let P (k) = |P(k)|. Clearly, if w ∈ P(k), then |w| = i=1 ki . Also, denote by gcd(k) the greatest common divisor of the components ki . If d| gcd(k), then denote k/d = (k1 /d, k2 /d, . . . , kq /d). The multinomial coefficients under consideration are n! n n = = , k k1 , k2 , . . . , kq k1 ! k2 ! . . . kq ! where n =
q
i=1
ki .
Theorem 1. Let k = (k1 , k2 , . . . , kq ) be a vector with n = P (k) =
d| gcd(k)
(d)
n/d k/d
q
i=1 ki .
Then
.
Proof. We use the principle of inclusion and exclusion to prove our claim. Let the distinct prime divisors of gcd(k) be p1 , p2 , . . . , pt . For an integer d| gcd(k), define Qd = {w | w = ud where (u) = k/d}. If w ∈ Qd , then (w) = k. Clearly, |Qd | equals the number of all words u, primitive and imprimitive alike, of length n/d such that u has the Parikh vector k/d. Therefore, |Qd | =
n/d k/d
.
(2)
Notice also that if d|e, then Qe ⊆ Qd , and hence I (k) =
t i=1
Qpi
(3)
is the set of all imprimitive words of length n with Parikh vector k. By the principle of inclusion and exclusion, we have then that t Qp = i i=1
∅ =Y ⊆[1,t]
(−1)|Y |−1 Qpi , i∈Y
(4)
276
where
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
Qpi = Qp(Y ) for p(Y ) = i∈Y pi . Hence, by (2), (−1)|Y |−1 |Qp(Y ) | |I (k)| = i∈Y
∅ =Y ⊆[1,t]
n/p(Y ) k/p(Y ) ∅ =Y ⊆[1,t] n/d (d) , =− k/d d| gcd(k)
=−
(−1)|Y |
d>1
by the definition of the Möbius function . This proves the claim, because P (k) = |I (k)|.
n k
−
3. Unbordered words Let Uq (n) denote the number of all unbordered words of length n over an alphabet of size q. The following formula for Uq (n) is well-known, see for example [1,4,5,7] and also the sequences A003000, A019308, A019309 in [6]. Surely, we have Uq (1) = q and if n > 1 then Uq (2n + 1) = q Uq (2n), Uq (2n) = q Uq (2n − 1) − Uq (n).
(5) (6)
Indeed, case (5) is clear since a word of odd length is unbordered if and only if it is unbordered after its middle letter (at position n + 1) is deleted. For case (6) consider that a word w of even length is unbordered if and only if it is unbordered after one of its middle letters (say, at position n + 1) is deleted except if w = auau and au is unbordered, where a is an arbitrary letter. Note, that there is an alternative way to obtain Uq (n) by considering the following immediate result. Lemma 2. Let w be a bordered word, and let u be its shortest border. Then (1) 2|u| |w|, (2) u is unbordered, and (3) u is the only unbordered border of w. Let Bq (n) denote the number of all bordered words of length n over an alphabet of size q. Lemma 2 shows that it is enough for every unbordered border u, with |u| n/2, to count the number of words of length n − 2|u| which is q n−2|u| . So, we have Uq (i) q n−2i . Bq (n) = 1 i n/2
This gives the formula in (5) and (6) for Uq (n) where Uq (n) = q n − Bq (n) for every q > 1 and where Uq (1) = q.
(7)
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
277
In this paper we investigate the number of unbordered words with a fixed weight. Let us fix a binary alphabet A = {a, b} for now. Let U (n, k) denote the number of all binary unbordered words of length n that have a fixed weight k in the sense that, for every such word w, we have |w|b = k and |w|a = n − k. It is easy to check that U (1, 0) = U (1, 1) = 1 and U (n, k) = 0, if n k and k > 1, and U (n, 0) = 0, if n > 1. Theorem 3. If 0 < k < n then U (n, k) = U (n − 1, k) + U (n − 1, k − 1) − E(n, k) where
E(n, k) =
(8)
U (n/2, k/2) if n and k are even, 0 otherwise.
Proof. Suppose first that w has odd length 2n + 1. Each word w = ucv, with c ∈ A and |u| = |v| = n, contributing to U (2n + 1, k) is obtained by adding a middle letter c to an unbordered word uv of even length. If c = a then uv contributes to U (2n, k), and if c = b then uv contributes to U (2n, k − 1). Assume then that w has even length 2n. If w = cudv, with c, d ∈ A and |u| = |v| = n−1, then it contributes to U (2n, k ) if and only if cuv is unbordered (so it contributed to either U (2n − 1, k ) or U (2n − 1, k − 1)) and cu = dv (that is, borderedness is not obtained by adding a letter to cuv such that w is a square). Consider the case where cuv is unbordered but cudv is not, that is, cu = dv. Then w = cucu and cuu is unbordered. Note, that cuu is unbordered if and only if cu is unbordered. Let |cu|b = k. We have that cuu contributes to U (2n − 1, 2k) (if c = a) or U (2n − 1, 2k − 1) (if c = b) if and only if cu contributes to U (n, k) which is therefore subtracted in case |w|b = 2k. Eq. (8) can be generalized to alphabets of arbitrary size q. For this, consider an ordered alphabet {a1 , a2 , . . . , aq } of size q, and let U (k) denote the number of all unbordered words q w of length n = i=1 ki that have a fixed weight (w) = k = (k1 , k2 , . . . , kq ). Moreover, let k[ki − 1] denote (k1 , . . . , ki−1 , ki − 1, ki+1 , . . . , kq ). If there exists 1 j q such that kj = 1 and ki = 0 for all i = j , then only the letter aj q contributes to U (k). Hence U (k) = 1, if i=1 ki = 1 and ki 0 for all 1 i q. q Theorem 4. If i=1 ki > 0 then U (k) = U (k[ki − 1]) − E(k), 1i q ki >0
where
E(k) =
U (k/2) if ki is even for all 1 i q, 0 otherwise.
Proof. Indeed, the arguments of adding a letter at the point |w|/2 of a word w are similar to those of Theorem 3. For the explanation of E(k) we note that a bordered word (created
278
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
by adding a middle letter) is a square ai uai u, for some 1 i q. Note that the length of w and the number of occurrences of every letter is even in that case. Now, w is only counted if ai u is unbordered, that is, if ai u contributes to U (k/2) which must be therefore subtracted.
4. Words with a unique border In this section we count the number of words that have one and only one border. Let us start with an obvious result which belongs to folklore. Lemma 5. Let w be a bordered word, and let u be its shortest border. If w has a border v with |v| > |u| border, then |v| 2|u|. Proof. Indeed, if, for the shortest border u, we have |v| < 2|u| then u overlaps itself (since u p v and u s v), and hence, u is bordered contradicting Lemma 2(2). In order to estimate the number of words with exactly one border, we make the following two observations. Lemma 6. Let u be a fixed unbordered word of length s. Then the number of words of length r of the form xuyux is the number of bordered words of length r − 2s, that is, Bq (r − 2s). Indeed, every word of the form xyx produces exactly one word of the form xuyux, and the condition xuyux = x uy ux would imply that u is bordered; a contradiction. Lemma 7. Let u be a fixed unbordered word of length s. Then the number of words of length r of the form zuz is the number of words of length (r − s)/2. Indeed, each word z produces exactly one word of the form zuz, and the condition zuz = z uz implies that z = z . Let k n and Bq (n, k) denote the number of all words of length n over an alphabet of size q that have exactly one border of length k. It is clear that Bq (1, k) = Bq (n, 0) = 0, for all 1 n and 0 k, and Bq (n, k) = 0, if n < 2k, see Lemma 2(1). Theorem 8. If 1 2k n then Bq (n, k) = Uq (k) (q n−2k − Wq (n − 2k, k) − Eq (n − 2k, k)), where Bq (r − 2s) if 2s < r, if 2s = r, Wq (r, s) = 1 0 otherwise.
T. Harju, D. Nowotka / Theoretical Computer Science 340 (2005) 273 – 279
and
279
(r−s)/2 if s < r < 3s and r − s even, q Eq (r, s) = 1 if s = r, 0 otherwise.
Proof. Indeed, following the argument of Lemma 2(2) we count all unbordered words of length k (that is Uq (k)) which are possible borders of a word of length n. For every such border we have to count the number of different combinations of letters for the rest of the n−2k letters, that is q n−2k . However, we have to exclude those cases where new borders are created. Given an unbordered border u of length k, we have the following cases for words with more than one border: uxuyuxu and uzuzu, where x, y, z ∈ A∗ . These two cases are taken care of by Wq (r, s) and Eq (r, s) where both terms equal 1 if u4 and u3 are counted; see also Lemmas 6 and 7. Note that the latter case is included in the former one if and only if |u| |z| (where the “only if” part comes from the fact that u is unbordered, and hence, it does not overlap itself), therefore r < 3s is required in Eq (r, s). Clearly, the number Bq (n) of words of length n over an alphabet of size q with exactly one border is the following: Bq (n) = Bq (n, i). 1 i n/2
References [1] H. Harborth, Endliche 0 − 1-Folgen mit gleichen Teilblöcken, J. Reine Angew. Math. 271 (1974) 139–154. [2] M. Lothaire, Combinatorics on Words, Encyclopedia of Mathematics and its Applications, Vol. 17, AddisonWesley Publishing Co., Reading, MA, 1983. [3] H. Petersen, On the language of primitive words, Theoret. Comput. Sci. 161 (1–2) (1996) 141–156. [4] M. Régnier, Enumeration of bordered words, The Language of the Laughing Cow, RAIRO Inform. Théor. Appl. 26 (4) (1992) 303–317. [5] I. Simon, String matching algorithms and automata, Results and Trends in Theoretical Computer Science, Graz 1994, Lecture Notes in Computer Science, Vol. 812, Springer, Berlin, 1994, pp. 386–395. [6] N.J.A. Sloane, On-line encyclopedia of integer sequences, http://www.research.att.com/ ∼njas/sequences/. [7] P. Tolstrup Nielsen, A note on bifix-free sequences, IEEE Trans. Inform. Theory IT-19 (1973) 704–706.
Theoretical Computer Science 340 (2005) 280 – 290 www.elsevier.com/locate/tcs
Growth of repetition-free words—a review Jean Berstel Institut Gaspard-Monge (IGM), Université de Marne-la-Vallée, 5 Boulevard Descartes, F-77454 Marne-la-Vallée, Cédex 2, France
Abstract This survey reviews recent results on repetitions in words, with emphasis on the estimations for the number of repetition-free words. © 2005 Published by Elsevier B.V. Keywords: Repetitions in words; Square-free words; Overlap-free words; Combinatorics on words
1. Introduction A repetition is any bordered word. Quite recently, several new contributions were made to the field of repetition-free words, and to counting repetition-free words. The aim of this survey is to give a brief account of some of the methods and results. The terminology deserves some comments. Let > 1 be a rational number. A nonempty word w is an -power if there exist words x, x with x a prefix of x and an integer n, such that w = x n x and = n + |x |/|x| = |w|/|x|. For example, the French word entente is a 73 -power, and the English word outshout is a 85 -power. If = 2 or 3, we speak about a square and a cube, like for murmur or kokoko (the examples are taken from [41]). A word w is an overlap if it is a -power for some > 2. For instance, entente is an overlap. Let > 1 be a real number. A word w is said to avoid -powers or is -power-free if it contains no factor that is an -power for . A word w is + -power-free if it contains no factor that is an -power for > . Thus, a word is overlap-free if and only if it is 2+ -power-free.
E-mail address:
[email protected]. 0304-3975/$ - see front matter © 2005 Published by Elsevier B.V. doi:10.1016/j.tcs.2005.03.039
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
281
This review reports results on the growth of the number of -free words of length n over an q-letter alphabet. In some cases, growth is bounded by a polynomial in n, in other cases, it is shown to be exponential in n. We consider overlap-free words in the next section, square-free words in Section 3 and some generalizations in the final section. For basics and complements, the reader should consult the book of Allouche and Shallit [3].
2. Counting overlap-free words We first review estimations for the number of overlap-free words over a binary alphabet. Let V be the set of binary overlap-free words and let v(n) be the number of overlap-free binary words of length n. This sequence starts with 2, 4, 6, 10, 14, 20 (Sloane’s sequence A007777, see [42]). It is clear that V is factorial (factor-closed). It follows that, as for any factorial set, one has v(n + m) v(n)v(m). Thus the sequence (v(n)) is submultiplicative or the sequence (log v(n)) is subadditive. This in turn implies, by a well-known argument, that the sequence limn→∞ v(n)1/n has a limit, or equivalently, that the limit
(V ) = lim
n→∞
1 log v(n) n
exists. The number (V ) is called the (topological) entropy of the set V. For a general discussion about entropy of square-free words, see [4]. The entropy of the set of square-free words is strictly positive, as we will see later. On the contrary, the entropy of the set of overlap-free words is zero. This is a consequence of the following result of Restivo and Salemi [34,35]. Theorem 1. The number v(n) of binary overlap-free words of length n is bounded from above by a polynomial in n. They proved that v(n) is bounded by n4 . The proof is based on the following structural property of overlap-free words which we state in the more general setting of [22]. Recall first that the Thue–Morse morphism is defined by
:
0 → 01 1 → 10
Lemma 2. Let 2 < < 7/3, and let x be a word that avoids -powers. There exist words u, y, v with u, v ∈ {e, 0, 1, 00, 11} and y avoiding -powers such that x = u(y)v. This factorization is unique if |x| 7. First, observe that the lemma does not hold for 7/3 since x = 0110110 is a 7/3power and has no factorization of the required form. Next, consider as an example the word x = 011001100 which is a 9/4-power, and contains no higher repetition. One gets x = (0101)0, and y = 0101 itself avoids repetitions of exponent greater than 9/4.
282
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
It follows from the lemma that an overlap-free word x has a factorization x = u1 (u2 ) · · · h−1 (uh )h (xh )h−1 (vh ) · · · (v2 )v1 , where each ui and vi has length at most 2, and xh has length at most 4. A simple computation shows that log |x| − 3 < h log |x|. Thus, the value of h and each ui and vi and xh may take a finite number of values, from which the total number of overlap-free words results to be bounded by c · d log n = c · nlog d for some constants c and d. Another consequence of the lemma is that the Thue–Morse word t = (0) is not only overlap-free but avoids 7/3-powers. A clever generalization, by Rampersad [32], of a proof of [39,40] shows that t (and its opposite t¯) is the only infinite binary word avoiding 7/3-powers that is a fixed point of a nontrivial morphism. Restivo and Salemi’s theorem says that v(n) Cns for some real s. The upper bound log 15 for s given by Restivo and Salemi has been improved by Kfoury [24] to 1.7, by Kobayashi [25] to 1.5866 and by Lepistö in his Master thesis [26] to 1.37; Kobayashi [25] gives also a lower bound. So Theorem 3. There are constants C1 and C2 such that C1 nr < v(n) < C2 ns , where r = 1.155 . . . and s = 1.37 . . . . One might ask what the “real” limit is. In fact, a result by Cassaigne [12] shows that there is no limit. More precisely, he proves Theorem 4. Set r = lim inf 1.332 < s.
log v(n) log n
and s = lim sup loglogv(n) n . Then r < 1.276 and
It is quite remarkable that the sequence v(n) is 2-regular. This was shown by Carpi [9] (see [3] for the definition of regular sequences). As we shall see in the next section, the number of square-free ternary words grows exponentially. In fact, Brandenburg [6] proves also that the number of binary cube-free words grows exponentially. The exact frontier between polynomial and exponential growth has been shown to be the exponent 7/3 by Karhumäki and Shallit [22]. Theorem 5. There are only polynomially many binary words of length n that avoid 7/3-powers, but there are exponentially many binary words that avoid 7/3+ -powers. 3. Counting square-free words We report now estimations for the number of square-free words over a ternary alphabet. Let S be the set of ternary square-free words and let s(n) be the number of square-free ternary words of length n. Since S is factorial (factor-closed), the sequence (s(n)) is submultiplicative and the (topological) entropy (S) exists. We will show that (S) is not zero, and give bounds for (S). The
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
283
sequence s(n) starts with 3, 6, 12, 18, 30, 42, 60 (Sloane’s sequence A006156, see [42]). The sequence s(n) is tabulated for n 90 in [4] and for 91 n 110 in [21]. 3.1. Getting upper bounds There is a simple method to get upper bounds for the number of ternary square-free words, based on using better and better approximations by regular languages. Clearly, any square-free word over A = {0, 1, 2} contains no factor 00, 11 or 22, so S ⊂ A∗ \ A∗ {00, 11, 22}A∗ . Since the latter is a regular set, its generating function is a rational function. It is easily seen to be f (t) = (1 + t)/(1 − 2t). Indeed, once an initial letter is fixed in a word of this set, there are exactly two choices for the next letter (this remembers Pansiot’s encoding [31], see also [28]). So s(n) 2n +2n−1 for n 1. Moreover, since a word of length at most 3 is square-free if and only if is in A∗ \ A∗ {00, 11, 22}A∗ , the equality s(n) = 2n + 2n−1 holds for n 3, and thus s(2) = 6 and s(3) = 12. One can continue in this way: clearly none of the 6 squares of length 4: 0101, 0202, 1010, 1212, 2020, 2121 is a factor of a word in S, and it suffices to compute the generating function of the set A∗ \A∗ XA∗ , where X = {00, 11, 22, 0101, 0202, 1010, 1212, 2020, 2121} to get better upper bound for s(n). Some of these generating functions are given explicitly in [36]. For words without squares of length 2 or 4, the series is (1 + 2t + 2t 2 + 3t 3 )/(1 − t − t 2 ) (see [36]). Again, a direct argument gives the reason: a ternary word without squares of length 2 or 4 either ends with aba for a = b, or with abc where the letters a, b, c are distinct. Denote by un (resp. by vn ) the number of words of the first (of the second) type, and by s (2) (n) the total number. Then it is easily seen that, for n 4, un = vn−1 and vn = s (2) (n − 1), and consequently s (2) (n) = s (2) (n − 1) √ + s (2) (n − 2). This shows of n course that s(n) C , for some constant C, with = (1 + 5)/2 the golden ratio. More generally, we consider any finite alphabet A, a finite set X and the set K = A∗ \ ∗ A XA∗ . We may assume that X contains no proper factor of one of its elements, so it is a code. Since the set K is a quite particular regular set, we will compute its generating function by using special techniques. There exist at least two (related) ways to compute these generating functions. First, we consider the semaphore code C = A∗ X \ A∗ XA+ . Semaphore codes (see e.g. [5]) were introduced by Schützenberger [38] under the name J codes. The computation below remembers of course also recurrent events in the sense of Feller [18]. The set C is the set of words that have a suffix in X but have no other factor in X. Thus the set K is also the set of proper prefixes of elements in C, and since C is a maximal prefix code, one has C ∗ K = A∗ . Next, one has (see [5] or [27]) Kx = Cy Ry,x (x ∈ X), y∈X
where Cy = C ∩ A∗ y and Ry,x is the correlation set of y and z, given by Ry,z = {z−1 x | z ∈ S(y) ∩ P (x)}.
(1)
(2)
284
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
Here, S(y) (resp P (x)) is the set of proper suffixes of y (proper prefixes of x). Of course, Cy . (3) C= y∈X
Eqs. (1)–(3) are CardX + 2 equations in CardX + 2 unknowns and allow to compute the languages or their generating series. As an example, consider X = {00, 11, 22}. Denote by fZ the generating function of the set Z. Then Eqs. (1)–(3) translate into (1 − 3t)fK = 1 − fC , fKaa = t 2 fK = (1 + t)fCaa ,
fC = 3fCaa
(a ∈ A)
since Raa,aa = {1, a} and Raa,bb = ∅ for a = b. Thus 3t 2 fK = (1+t)fC and (1−3t)fK = 3t 2 1 − fC = 1 − 1+t fK , whence fK =
1 1 − 3t +
3t 2
=
1+t
1+t . 1 − 2t
The second technique is called the “Goulden–Jackson clustering technique” in [29]. The idea is to mark occurrences of words in X in a word, and to weight a marked word with an indicator of the number of its marks. If a word w has r marks, then its weight is (−1)r t |w| . As an example, if X is just the singleton X = {010}, the word w = 01001010 exist in eight marked versions, namely 01001010, 01001010, 01001010, 01001010, 010 01010, 01001010, 01001010, 01001010. Let us write w for a marked version of w, and p(w) for its weight. The sum of the weights of the marked versions of a word w is 0 if w contains a factor in X, and is 1 otherwise. In other terms, the generating series of the set K = A∗ \ A∗ XA∗ is p(w), fK = w∈A∗
where the sum is over all marked versions of all words. Now, it appears that this series is rather easy to compute when one considers clusters: a cluster is a marked word w where every position is marked, and that is not the product of two other clusters. Thus, for X = {010}, the word 01001010 is not a cluster since it is the product of the two clusters 010 and 01010. A marked word is a unique product of unmarked letters and of clusters. Thus, a marked word w is either the empty word, or its last letter is not marked, or it ends with a cluster. Thus fK = 1 + fK (t)kt + fK (t)p(C), where k is the size of the alphabet and p(C) is the generating series of the set C of clusters. It follows that 1 . (4) fK (t) = 1 − kt − p(C) A cluster ends with a word in X. Let Cx = C ∩ A∗ x be the clusters ending in x. Then the generating series p(Cx ) are the solutions of the system (y : x)p(Cy ), (5) p(Cx ) = −t |x| − y∈X
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
285
where y : x is the (strict) correlation polynomial of y and x defined by t |z| . y:x= z∈Ry,x \{e}
Eq. (5) is a system of linear equations, and the number of equations is the size of X. Solving this system gives the desired expression. Consider the example X = {010} over A = {0, 1}. Then the generating series of K = A∗ \ A∗ 010A∗ is fK (t) =
1 1 − 2t − p(C010 )
and p(C010 ) = −t 3 − t 2 p(C010 ), whence p(C010 ) = fK (t) =
1 1 − 2t +
t3
=
1+t 2
−t 3 1+t 2
and
1 + t2 . 1 − 2t + t 2 − t 3
Both methods are just two equivalent formulations of the same computation, as pointed out to me by Dominique Perrin. When X = {x} is a singleton, Eq. (2) indeed becomes Kx = CR with R = Rx,x , and in noncommuting variables, Eq. (1) is just K(1 − A) = 1 − C so K(1 − A) = 1 − KxR −1 whence K(1 − A + xR −1 ) = 1.
(6)
Now, the coefficients of the series −xR −1 are precisely the weights of the cluster of x. So Eq. (6), converted to a generating series, yields precisely Eq. (4)! In the general case = (x)x∈X and C = (Cx )x ∈ X and the X × X matrix one considers the (row) vectors X = CR and the same computation as above gives R = (Rx,y )x,y∈X . Then Eq. (2) is K X −1 )x = 1. (XR K = 1−A+ x∈X
The computation of the generating functions for sets K of the form above, or more generally of the series w∈K (w)t |w| , where is a probability distribution on A∗ , is an important issue both in concrete mathematics [20], in the theory of codes [5] and in computational biology (see e.g. chapters 1, 6 and 7 in [27]). Extensions are in [30,33]. In their paper [29], Nanoon and Zeilberger present a package that allows to compute the generating functions and their asymptotic behaviour for the regular sets of words without squares yy of length |y| = % for % up to 23. Richard and Grimm [36] go one step further, to % = 24. The entropy (S) of the set of square-free ternary words is now known to be at most 1.30194.
286
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
3.2. Getting lower bounds In order to get an exponential lower bound on the number of ternary square-free words, there are two related methods, initiated by Brandenburg [6] and Brinkhuis [7]. The first method is used for instance in [22], the second one, which gives now sharper bounds, was recently used in [2]. Both rely on the notion of a finite square-free substitution from A∗ into B ∗ , for some alphabet B. Let us recall that a substitution in formal language theory is a morphism f from some free monoid A∗ into the monoid of subsets of B ∗ that is a function satisfying f (e) = {e} and f (xy) = f (x)f (y), where the product on the righthand side is the product of the sets f (x) and f (y) in B ∗ . The substitution is finite if f (a) is a finite set for each letter a ∈ A (and so for each word w ∈ A∗ ), it is called squarefree if each word in f (w) is square-free whenever w is a square-free word on A. For an overview of recent results about power-free morphisms in connection with open problems, see [36]. ¯ 1, ¯ 2}. ¯ Brandenburg’s method goes as follows. Let A = {0, 1, 2} and let B = {0, 1, 2, 0, Let g : B ∗ → A∗ be the morphism that erases bars. Define a substitution f by f (a) = g −1 (a). Clearly, f is finite and square-free. Also each square-free word w of length n over A is mapped onto 2n square-free words of length n over B. The second step consists in finding a square-free morphism h from B ∗ into A∗ . Assume that h is uniform of length r. Then each square-free word w of length n over B is mapped into a square-free word of length rn over A by the morphism h. It follows that there are 2n square-free words of length rn for each square-free word of length n, that is s(rn) 2n s(n). Since s(n) is submultiplicative, one has s(rn) s(n)r . Reporting in the previous equation yields s(n) 2n/(r−1) and proves that growth is exponential. ¯ 1, ¯ 2}. ¯ It remains to give a square-free morphism h from B ∗ into A∗ , where B = {0, 1, 2, 0, It appears that 0 → 0102012021012102010212 1 → 0102012021201210120212 h:
2 → 0102012102010210120212 0¯ → 0102012102120210120212 1¯ → 0102012101202101210212 2¯ → 0102012101202120121012
is a square-free morphism. Here r = 22, and consequently s(n) 2n/21 . The following is a slight variation of Brandenburg’s result: Theorem 6. The number s(n) of square-free ternary words of length n satisfies the inequality s(n) 6 · 1.032n .
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
287
A more direct method was initiated by Brinkhuis [7]. He considers a 25-uniform substitution f from A∗ into itself defined by 0 → {U0 , V0 } f : 1 → {U1 , V1 } 2 → {U2 , V2 } where U0 = x1x, ˜ V0 = y0y˜ and x = 012021020102 and y = 012021201021. The words U1 , . . . , V2 are obtained by applying the circular permutation (0, 1, 2). He proves that f is square-free, and thus every square-free word w of length n is mapped onto 2n square-free words of length 25n. His bound is only 2n/24 . The substitution f can be viewed as the composition of an inverse morphism and a morphism, when U0 , . . . , V2 are considered as letters and then each of these letters is mapped to the corresponding word. However, the second mapping is certainly not square-free since the image of U0 V0 contains the square 00. Thus, the construction of Brinkhuis is stronger. Indeed, Ekhad and Zeilberger [17] found 18-uniform square-free substitution of the same form than Brinkhuis’ and thus reduced the bound from 2n/24 to 2n/17 . A relaxed version of Brinkhuis’ construction is used by Grimm [21] to derive the better bound 65n/40 , and by Sun [43] to improve this bound to 110n/42 . 4. Other bounds We review briefly other bounds on the number of repetition-free words. Concerning cube-free binary words, already Brandenburg [6] gave the following bounds. Theorem 7. The number c(n) of binary cube-free words of length n satisfies 2 · 1.080n < 2 · 2n/9 c(n) 2 · 1251(n−1)/17 < 1.315 · 1.522n . The upper bound was improved by Edlin [16] to B · 1.4576n for some constant B by using the “cluster” method. Next, we consider Abelian repetitions. An Abelian square is a nonempty word uu , where u and u are commutatively equivalent, that is u is a permutation of u. For instance, 012102 is an Abelian square. It is easy to see that there is no infinite Abelian square-free word over three letters. The existence of an infinite word over four letters without Abelian squares was demonstrated by Keränen [23]. Also, the question of the existence of exponentially many quaternary infinite words without Abelian squares was settled by Carpi [10] positively. He uses an argument similar to Brinkhuis’ but much more involved. Square-free morphisms from alphabets with more than four letters into alphabets with four letters seem not to exist [8]. He shows Theorem 8. The number d(n) of quaternary words avoiding Abelian squares satisfies 3 d(n) C · 219n/(85 −85) for some constant C. This result should be compared to the following, concerning ternary words without Abelian cubes [2].
288
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
Theorem 9. The number r(n) of ternary words avoiding Abelian cubes grows faster than 2n/24 . The number of ternary words avoiding Abelian cubes is 1, 3, 9, 24, 66, 180, . . . . It is the sequence A096168 in [42]. The authors consider the 6-uniform substitution 0 → 001002 h : 1 → 110112 2 → 002212, 122002 This does not preserve Abelian cube-free words since the word 0010|02110|11200|10021|10112 which contains an Abelian cube is in h(0101). However, the set {hn (0) : n 0} is shown to avoid Abelian cubes. There is an interesting intermediate situation between the commutative and the noncommutative case which is the case where, for the definition of squares, only some of the letters are allowed to commute. To be precise, consider a set of commutation relations of the form ab = ba for a, b letters, and define the relation u ∼ v mod as the transitive closure of the relation uabv ∼ ubav for all words u, v and ab = ba in . A -square is a word uu such that u ∼ u mod . If is empty, a -square is just a square, and if is the set of all ab = ba for a = b, a -square is an Abelian square. Since there is an infinite quaternary word that avoids Abelian squares, the same holds for -squares. For 3 letters, the situation is on the edge since ther exist infinite square-free words, but no infinite Abelian square-free word. The result proved by Cori and Formisano [13] is: Theorem 10. If the set of commutation relations contains at most one relation, then the set of ternary words avoiding -squares is infinite, otherwise it is finite. It has been proved by the same authors [14] that the number of words grows only polynomially with the length. This result is different from [11] where square-free words in partially commutative monoids are investigated. Another variation concerns circular words. A circular word avoids -powers if all its conjugates avoid -powers. For instance, 001101 is a circular 2+ -power free word because each word in the set {001101, 011010, 110100, 101001, 010011, 100110} is a 2+ -power free word. On the contrary, the word 0101101 is cube-free but its conjugate 1010101 is not cube-free and not even 3+ -power free; so, viewed as a circular word, 0101101 is not 3+ -power free. It is proved in [1] that there exist infinitely many 5/2+ -power free binary circular words, whereas every circular word of length 5 either contains a cube or a 5/2-power. This improves a previous result [15] showing that there are infinitely many cube-free circular binary words, see also [19]. No informations is available about the growth of the number of these words.
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
289
Acknowledgements Many thanks to the anonymous referee who contributed additional references and corrected several misprints.
References [1] A. Aberkane, J. Currie, There exist binary circular 5/2+ power free words of every length, Electron. J. Combin. 11 (2004) R10. [2] J. Aberkane, J. Currie, N. Rampersad, The number of ternary words avoiding Abelian cubes grows exponentially, in: Workshop on Word Avoidability, Complexity and Morphisms, LaRIA Techn. Report 200407, 2004, pp. 21–24. [3] J.-P. Allouche, J. Shallit, Automatic Sequences: Theory, Applications, Generalizations, Cambridge University Press, Cambridge, 2003. [4] M. Baake, V. Elser, U. Grimm, The entropy of square-free words, Math. Comput. Modelling 26 (1997) 13–26. [5] J. Berstel, D. Perrin, Theory of Codes, Academic Press, New York, 1985. [6] F.-J. Brandenburg, Uniformly growing k-th power-free homomorphisms, Theoret. Comput. Sci. 23 (1983) 69–82. [7] J. Brinkhuis, Nonrepetitive sequences on three symbols, Quart. J. Math. Oxford 34 (1983) 145–149. [8] A. Carpi, On Abelian power-free morphisms, Internat. J. Algebra Comput. 3 (1993) 151–167. [9] A. Carpi, Overlap-free words and finite automata, Theoret. Comput. Sci. 115 (2) (1993) 243–260. [10] A. Carpi, On the number of Abelian square-free words on four letters, Discrete Appl. Math. 81 (1998) 155–167. [11] A. Carpi, A. De Luca, Square-free words on partially commutative monoids, Inform. Proc. Lett. 22 (1986) 125–131. [12] J. Cassaigne, Counting overlap-free words, in: P. Enjalbert, A. Finkel, K. Wagner (Eds.), STACS ’93, Lecture Notes in Computer Science, Vol. 665, Springer, Berlin, 1993, pp. 216–225. [13] R. Cori, M. Formisano, Partially Abelian squarefree words, RAIRO Inform. Théoret. Appl. 24 (6) (1990) 509–520. [14] R. Cori, M. Formisano, On the number of partially Abelian squarefree words on a three-letter alphabet, Theoret. Comput. Sci. 81 (1) (1991) 147–153. [15] J. Currie, D. Fitzpatrick, Circular words avoiding patterns, in: M. Ito, M. Toyama (Eds.), Developments in Language Theory, DLT 2002, Lecture Notes in Computer Science, Springer, Berlin, 2004, pp. 319–325. [16] A. Edlin, The number of binary cube-free words of length up to 47 and their numerical analysis, J. Differential Equations Appl. 5 (1999) 153–154. [17] S.B. Ekhad, D. Zeilberger, There are more than 2n/17 n-letter ternary square-free words, J. Integer Seq. (1998) (Article 98.1.9). [18] W. Feller, An Introduction to Probability Theory and its Applications, Wiley, New York, 1966. [19] D. Fitzpatrick, There are binary cube-free circular words of length n contained within the Thue–Morse word for all positive integers n, Electron. J. Combin. 11 (2004) R14. [20] R. Graham, D. Knuth, O. Patashnik, Concrete Mathematics, Addison-Wesley, Reading, MA, 1989. [21] U. Grimm, Improved bounds on the number of ternary square-free words, J. Integer Seq. (2001) (Article 01.2.7). [22] J. Karhumäki, J. Shallit, Polynomial versus exponential growth in repetition-free binary words, J. Combin. Theory Ser. A 105 (2004) 335–347. [23] V. Keränen, Abelian squares are avoidable on 4 letters, in: ICALP ’92, Lecture Notes in Computer Science, Vol. 623, Springer, Berlin, 1992, pp. 41–52. [24] R. Kfoury, A linear time algorithm to decide whether a binary word contains an overlap, RAIRO Inform. Théoret. Appl. 22 (1988) 135–145. [25] Y. Kobayashi, Enumeration of irreductible binary words, Discrete Appl. Math. 20 (1988) 221–232.
290
J. Berstel / Theoretical Computer Science 340 (2005) 280 – 290
[26] A. Lepistö, A characterization of 2+ -free words over a binary alphabet, Master’s Thesis, University of Turku, Finland, 1995. [27] M. Lothaire, Applied Combinatorics on Words, Cambridge University Press, Cambridge, 2005. [28] J. Moulin-Ollagnier, Proof of Dejean’s conjecture for alphabets with 5, 6, 7, 8, 9, 10 and 11 letters, Theoret. Comput. Sci. 95 (1992) 187–205. [29] J. Nanoon, D. Zeilberger, The Goulden–Jackson cluster method: extensions, applications and implementations, J. Differential Equations Appl. 5 (1999) 355–377. [30] P. Nicodème, B. Salvy, P. Flajolet, Motif statistics, Theoret. Comput. Sci. 287 (2002) 593–617. [31] J.-J. Pansiot, A propos d’une conjecture de F. Dejean sur les répétitions dans les mots, Discrete Appl. Math. 7 (1984) 297–311. [32] N. Rampersad, Words avoiding 7/3-powers and the Thue–Morse morphism, 2003, Preprint available at http://www.arxiv.org/abs/math.CO/0307401. [33] M. Régnier, A unified approach to word occurrence probabilities, Discrete Appl. Math. 104 (2000) 259–280. [34] A. Restivo, S. Salemi, On weakly square free words, Bull. EATCS 21 (1983) 49–56. [35] A. Restivo, S. Salemi, Overlap-free words on two symbols, in: M. Nivat, D. Perrin (Eds.), Automata on Infinite Words, Lecture Notes in Computer Science, Vol. 192, Springer, Berlin, 1985, pp. 198–206. [36] C. Richard, U. Grimm, On the entropy and letter frequencies of ternary square-free words, http://arXiv:math.CO/0302302, July 2004. [37] G. Richomme, P. Séébold, Conjectures and results on morphisms generating k-power-free words, Internat. J. Found. Comput. Sci. 15 (2) (2004) 307–316. [38] M.-P. Schützenberger, On the synchronizing properties of certain prefix codes, Inform. Control 7 (1964) 23–36. [39] P. Séébold, Morphismes itérés, mot de Morse et mot de Fibonacci, C. R. Acad. Sci. Paris 295 (1982) 439–441. [40] P. Séébold, Sequences generated by infinitely iterated morphisms, Discrete Appl. Math. 11 (1985) 255–264. [41] J. Shallit, Avoidability in words: recent results and open problems, in: Workshop on Word Avoidability, Complexity and Morphisms, LaRIA Techn. Report 2004-07, 2004, pp. 1–4. [42] N.J.A. Sloane, The on-line encyclopedia of integer sequences, http://www.research.att. com/∼njas/sequences/. [43] X. Sun, New lower bound on the number of ternary square-free words, J. Integer Seq. (2003) (Article 03.2.2).
Theoretical Computer Science 340 (2005) 291 – 321 www.elsevier.com/locate/tcs
Algebraic recognizability of regular tree languages Zoltán Ésika, b,∗,1 , Pascal Weilc,2 a Department of Computer Science, University of Szeged, Hungary b Research Group on Mathematical Linguistics, Rovira i Virgili University, Tarragona, Spain c LaBRI, CNRS, Université Bordeaux-1, France
Abstract We propose a new algebraic framework to discuss and classify recognizable tree languages, and to characterize interesting classes of such languages. Our algebraic tool, called preclones, encompasses the classical notion of syntactic -algebra or minimal tree automaton, but adds new expressivity to it. The main result in this paper is a variety theorem à la Eilenberg, but we also discuss important examples of logically defined classes of recognizable tree languages, whose characterization and decidability was established in recent papers (by Benedikt and Ségoufin, and by Boja´nczyk and Walukiewicz) and can be naturally formulated in terms of pseudovarieties of preclones. Finally, this paper constitutes the foundation for another paper by the same authors, where first-order definable tree languages receive an algebraic characterization. © 2005 Elsevier B.V. All rights reserved. Keywords: Recognizability; Regular tree languages; Variety theorem; Pseudovariety; Preclones
1. Introduction The notion of recognizability emerged in the 1960s (Eilenberg, Mezei, Wright, and others, cf. [17,30]) and has been the subject of considerable attention since, notably because ∗ Corresponding author.
E-mail addresses:
[email protected] (Z. Ésik),
[email protected] (P. Weil). 1 Partial support from the National Foundation of Hungary for Scientific Research, Grant T46686 is gratefully
acknowledged. 2 Partial support from the ACI Sécurité Informatique (projetVERSYDIS) of the French Ministère de la Recherche
is gratefully acknowledged. Part of this work was done while P. Weil was an invited professor at the University of Nebraska in Lincoln. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.038
292
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
of its close connections with automata-theoretic formalisms and with logical definability, cf. [6,15,18,38] for some early papers. Recognizability was first considered for sets (languages) of finite words, cf. [16] and the references contained in op. cit. The general idea is to use the algebraic structure of the domain, say, the monoid structure on the set of all finite words, to describe some of its subsets, and to use algebraic considerations to discuss the combinatorial or logical properties of these subsets. More precisely, a set of words is said to be recognizable if it is a union of classes in a (locally) finite congruence. The same concept was adapted to the case of finite trees, traces, finite graphs, etc, cf. [17,30,14,9], where it always entertains close connections with logical definability [11,12]. It follows rather directly from this definition of (algebraic) recognizability that a finite— or finitary—algebraic structure can be canonically associated with each recognizable subset L, called its syntactic structure. Moreover, the algebraic properties of the syntactic structure of L reflect its combinatorial and logical properties. The archetypal example is that of starfree languages of finite words: they are exactly the languages whose syntactic monoid is aperiodic, cf. [34]. They are also exactly the languages that can be defined by a first-order sentence of the predicate < (FO[ 0, then (0n ) is the n-ary map ((x1 , y1 ), . . . , (xn , yn )) → (∧i yi , false), • if n > 0, then (1n ) is the n-ary map ((x1 , y1 ), . . . , (xn , yn )) → (∧i yi , true). One can verify by structural induction that for each element x ∈ Mk , the second component of (x) is true if and only if the root of x is labeled 1n for some n, and the first component of (x) is true if and only if every child of the root of x is labeled 1n for some n, that is, if and only if x ∈ Kk (next). Thus Kk (next) is recognized by the morphism . 4. Pseudovarieties of preclones In the usual setting of one-sorted algebras, a pseudovariety is a class of finite algebras closed under taking finite direct products, sub-algebras and quotients. Because we are dealing with preclones, which are infinitely sorted, we need to consider finitary algebras instead of finite ones, and to adopt more constraining closure properties in the definition. (We discuss in Remark 4.18 an alternative approach, which consists in introducing stricter finiteness conditions on the preclones themselves, namely in considering only finitely generated, finitely determined, finitary preclones.) We say that a class of finitary preclones is a pseudovariety if it is closed under finite direct product, sub-preclones, quotients, finitary unions of -chains and finitary inverse limits of
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
307
-diagrams. Here, we say that a union T = n T (n) of an -chain of preclones T (n) , n 0 is finitary exactly when T is finitary. Finitary inverse limits limn T (n) of -diagrams n : T (n+1) → T (n) , n 0 are defined in the same way. Remark 4.1. To be perfectly rigorous, we actually require pseudovarieties to be closed under taking preclones isomorphic to a finitary -union or to a finitary inverse limit of an -diagram of their elements. Remark 4.2. Recall that the inverse limit T of the -diagram (n )n 0 , written T = T (n) if the n : T (n+1) → T (n) are clear, is the sub-preclone of the direct prodlimn uct n T (n) whose set of elements of rank m consists of those sequences (xn )n 0 with (n) xn ∈ Tm such that n (xn+1 ) = xn , for all n 0. We call the coordinate projections p : limn T (n) → T (p) the induced projection morphisms. T
. . .π
n+1
T (n+1)
πn
n
... T (n)
...
T (0)
The inverse limit has the following universal property. Whenever S is a preclone and the morphisms n : S → T (n) satisfy n = n ◦ n+1 for each n 0, then there is a unique morphism : S → limn T (n) with n ◦ = n , for all n. This morphism maps an element s ∈ S to the sequence ( n (s))n 0 . Example 4.3. Here we show that the inverse limit of an -diagram of 1-generated finitary preclones need not be finitary. Let = {}, where has rank 1 and consider the free preclone M. Note that M has only elements of rank 1, and that M1 can be identified with the monoid ∗ . For each n 0, let ≈n be the congruence defined by letting k ≈n ! if and only if k = !, or k, ! n. Let T (n) = M/≈n . Then T (n) is again -generated, and it can be identified with the monoid {0, 1, . . . , n} under addition threshold n. In particular, T (n) is a finitary preclone. Since ≈n+1 -equivalent elements of M are also ≈n -equivalent, there is a natural morphism of preclones from T (n+1) to T (n) , mapping to itself, and the inverse limit of the resulting -diagram is M itself, which is not finitary. Pseudovarieties of preclones can be characterized using the notion of division: we say that a preclone S divides a preclone T, written S < T , if S is a quotient of a sub-preclone of T. It is immediately verified that a nonempty class of finitary preclones is a pseudovariety if and only if it is closed with respect to division, binary direct product, finitary unions of -chains and finitary inverse limits of -diagrams. Example 4.4. It is immediate that the intersection of a collection of pseudovarieties of preclones is a pseudovariety. It follows that if K is a class of finitary preclones, then the pseudovariety generated by K is well defined, as the least pseudovariety containing K. In
308
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
particular, the elements of this pseudovariety, written K!, can be described in terms of the elements of K, taking subpreclones, quotients, direct products, finitary unions of -chains and inverse limits of -diagrams. See Section 4.2 below. We discuss other examples in Section 5.2. We first explore the relation between pseudovarieties and their finitely determined elements, then we discuss pseudovarieties generated by a class of preclones, and finally, we explore some additional closure properties of pseudovarieties. 4.1. Pseudovarieties and their finitely determined elements Proposition 4.5. Let S be a preclone. • S is isomorphic to the inverse limit limn S (n) of an -diagram, where each S (n) is an n-determined quotient of S. • If S is finitary, then S is isomorphic to the union of an -chain n 0 T (n) , where each T (n) is the inverse limit of an -diagram of finitely generated, finitely determined divisors of S. Proof. Let S (n) = S/∼n (where ∼n is defined in Section 2.4) and let n : S → S (n) be the corresponding projection. Since ∼n+1 -related elements of S are also ∼n -related, there exists a morphism of preclones n : S (n+1) → S (n) such that n = n ◦ n+1 . Thus the n determine a morphism : S → limn S (n) , such that (s) = ( n (s))n for each s ∈ S (Remark 4.2). Moreover, since ∼n is the identity relation on the elements of S of rank at most n, we find that for each k n, n establishes a bijection between the elements of rank k of S and those of S (n) . In particular, is injective since each element of S has rank k for some finite integer k. Furthermore, for each k n, n establishes a bijection between the elements of rank k, and it follows that each element of rank k of limn S (n) is the -image of its kth component. That is, is onto. Finally, Lemma 2.11 shows that each S (n) is n-determined. This concludes the proof of the first statement. We now assume that S is finitary, and we let T (m) be the sub-preclone generated by the elements of S of rank at most m. Then T (m) is finitely generated, and the first statement shows that T (m) is the inverse limit of an -diagram of finitely generated, finitely determined quotients of T (m) , which are in particular divisors of S. The following corollary follows immediately: Corollary 4.6. Every pseudovariety of preclones is uniquely determined by its finitely generated, finitely determined elements. We can go a little further, and show that a pseudovariety is determined by the syntactic preclones it contains. Proposition 4.7. Let S be a finitely generated, k-determined, finitary preclone, let A be a finite ranked set and let : AM → S be an onto morphism. Then S divides the direct product
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
309
of the syntactic preclones of the languages −1 (s), where s runs over the ( finitely many) elements of S of rank at most k. Proof. It suffices to show that if x, y ∈ AMn for some n 0 and x ∼−1 (s) y for each s ∈ S! , ! k, then (x) = (y). First, suppose that x and y have rank n k, and let s = (x). Then (1, 0, n, 0) is a −1 (s)context of x, so it is also a −1 (s)-context of y, and we have (y) = s = (x). Now, if x and y have rank n > k, let v ∈ Sn,p for some p k. Since is onto, there exists an element z ∈ AMn,p such that (z) = v. For each s ∈ S! , ! k, we have x ∼−1 (s) y, and hence also x · z ∼−1 (s) y · z. The previous discussion shows therefore that (x · z) = (y · z), that is, (x) · v = (y) · v. Since S is k-determined, it follows that (x) = (y). Corollary 4.8. Every pseudovariety of preclones is uniquely determined by the syntactic preclones it contains. Proof. This follows directly from Corollary 4.6 and Proposition 4.7.
4.2. The pseudovariety generated by a class of preclones Let I, H, S, P, L, U denote, respectively, the operators of taking all isomorphic images, homomorphic images, subpreclones, finite direct products, finitary inverse limits of an diagram, and finitary -unions over a class of finitary preclones. The following fact is a special case of a well-known result in universal algebra. Lemma 4.9. If K is a class of finitary preclones, then HSP(K) is the least class of finitary preclones containing K, closed under homomorphic images, subpreclones and finite direct products. Next, we observe the following elementary facts: Lemma 4.10. For all classes K of finitary preclones, we have (1) PL(K) ⊆ LP(K), (3) SL(K) ⊆ LS(K),
(2) PU(K) ⊆ UP(K), (4) SU(K) ⊆ US(K).
Proof. To prove the first inclusion, suppose that S is the direct product of the finitary preclones S (i) , i ∈ [n], where each S (i) is a limit of an -diagram of preclones S (i,k) in K determined by a family of morphisms i,k : S (i,k+1) → S (i,k) , k 0. For each k, let T (k) be the direct product i∈[n] S (i,k) , and let k = i∈[n] i,k : T (k+1) → T (k) . It is a routine matter to verify that S is isomorphic to the limit of the -diagram determined by the family of morphisms k : T (k+1) → T (k) , k 0. Thus, S ∈ LP(K). (i,k) Now, for each i ∈ [n], preclones in K. Let us as let (S (i,k))k 0 be an -chain of finitary (i) is finitary, and let S = i∈[n] S (i) . If s = (s1 , . . . , sn ) ∈ sume that each S = k 0 S S, then each si belongs to S (i,ki ) , for some ki . Thus s ∈ i∈[n] S (i,k) , where k = max ki , and we have shown that S ∈ k 0 i∈[n] S (i,k) , so that S ∈ UP(K).
310
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
To prove the third inclusion, let T be a sub-preclone of limn S (n) , the finitary inverse limit of an -diagram n : S (n+1) → S (n) of elements of K. Let n : T → S (n) be the natural projections (restricted to T), and let T (n) = n (T ). Then T (n) is a subpreclone of S (n) for each n. Moreover, the restrictions of the n to T (n+1) define an -diagram of subpreclones of elements of K, and it is an elementary verification that T = limn T (n) . Since T is finitary, we have proved that T ∈ LS(K). As for the last inclusion, let T be a subpreclone of a finitary union k 0 S (k) with S (k) ∈ K, for all k 0. Let T (k) = S (k) ∩ T for each k 0. Then each T (k) is a subpreclone of S (k) and T = k 0 T (k) . It follows that T ∈ US(K). Our proof of the third inclusion actually yields the following result. Corollary 4.11. If a finitary preclone S embeds in an inverse limit limn S (n) , then S is isomorphic to a ( finitary) inverse limit limn T (n) , where each T (n) is a finitary sub-preclone of S (n) . We can be more precise than Lemma 4.10 for what concerns finitely generated, finitely determined preclones. Lemma 4.12. Let T be a preclone which embeds in the union of an -chain (S (n) )n . If T is finitely generated, then T embeds in S (n) for all large enough n. Proof. Since T is finitely generated, its set of generators is entirely contained in some S (k) , and hence T embeds in each S (n) , n k. Lemma 4.13. Let T be a quotient of the union of an -chain (S (n) )n . If T is finitely generated, then T is a quotient of S (n) for all large enough n. Proof. Let be a surjective morphism from S = n S (n) onto T. Since T is finitely generated, there exists an integer k such that (S (k) ) contains all the generators of T, and this implies that the restriction of to S (k) (and to each S (n) , n k) is onto. Lemma 4.14. Let T be a preclone which embeds in the inverse limit limn S (n) of an diagram, and for each n, let n : T → S (n) be the natural projection (restricted to T). If T is finitary, then for each k, n is k-injective for all large enough n. If in addition T is finitely determined, then T embeds in Sn for all large enough it n. Proof. Since T is finitary, Tk is finite for each integer k, and hence there exists an integer nk such that n is injective on Tk for each n nk . In particular, for each integer k, n is k-injective for all large enough n. The last part of the statement follows from Lemma 2.12. Lemma 4.15. Let T be a quotient of the finitary inverse limit limn S (n) of an -diagram. If T is finitely determined, then T is a quotient of a sub-preclone of one of the S (n) .
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
311
Proof. Let S = limn S (n) and let n : S → S (n) be the corresponding projection. Let also : S → T be an onto morphism, and let k 0 be an integer such that T is k-determined. By Lemma 4.14, n is k-injective for some integer n. Consider the preclone n (S) ⊆ S (n) . Then we claim that the assignment n (s) → (s) defines a surjective morphism n (S) → T . The only nontrivial point is to verify that this assignment is well defined. Let s, s ∈ Sp and suppose that n (s) = n (s ). We want to show that (s) = (s ), and for that purpose, we show that (s) · v = (s ) · v for each v ∈ Tp,! , ! k (since T is k-determined). Since is onto, there exists w ∈ Sp,! such that v = (w). In particular, (s) · v = (s · w) and similarly, (s ) · v = (s · w). Moreover, we have n (s · w) = n (s · w). Now s · w and s · w lie in S! , and n is injective on S! , so s · w = s · w. It follows that (s) · v = (s ) · v, and hence (s) = (s ). We are now ready to describe the finitely generated, finitely determined elements of the pseudovariety generated by a given class of finitary preclones. Proposition 4.16. Let K be a class of finitary preclones. A finitely generated, finitely determined, finitary preclone belongs to the pseudovariety K! generated by K if and only if it divides a finite direct product of preclones in K, i.e., it lies in HSP(K). Proof. It is easily verified that K! = n Vn , where V0 = K and Vn+1 = HSPUHSPL (Vn ). We show by induction on n that if T a finitely generated, finitely determined preclone in Vn , then T ∈ HSP(K). The case n = 0 is trivial and we now assume that T ∈ Vn+1 . By Lemma 4.10, T lies in HUSPHLSP(Vn ). Then Lemma 4.13 shows that T is in fact in HSPHLSP(Vn ), which is equal to HSPLSP(Vn ) by Lemma 4.9, and is contained in HLSP(Vn ) by Lemma 4.10 again. Now Lemma 4.15 shows that T lies in fact in HSP(Vn ), and we conclude by induction that T ∈ HSP(K). Corollary 4.17. If K is a class of finitary preclones, then K! = IULHSP(K). Proof. The containment IULHSP(K) ⊆ K! is immediate. To show the reverse inclusion, we consider a finitary preclone T ∈ K!. Then T = T (n) , where T (n) denotes the subpreclone of T generated by the elements of rank at most n. Now each T (n) is finitely generated, and by Proposition 4.5, it is isomorphic to the inverse limit of the -diagram formed by the finitely generated, finitely determined preclones Tn /∼m , m 0. By the Proposition 4.16, each of these preclones is in HSP(K), so T ∈ IULHSP(K). Remark 4.18. As indicated in the first paragraph of Section 4, Proposition 4.16 hints at an alternative treatment of the notion of pseudovarieties of preclones, limited to the consideration of finitely generated, finitely determined, finitary preclones. Say that a class K of finitely generated, finitely determined, finitary preclones is a relative pseudovariety if whenever a finitely generated, finitely determined, finitary preclone S divides a finite direct product of preclones in K, then S is in fact in K. For each pseudovariety V, the class Vfin of all its finitary, finitely generated, finitely determined members is a relative pseudovariety, and the map V → Vfin is injective by Corollary 4.6. Moreover, Proposition 4.16 can be used
312
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
to show that this map is onto. That is, the map V → Vfin is an order-preserving bijective correspondence (with respect to the inclusion order) between pseudovarieties and relative pseudovarieties of preclones. Proposition 4.16 also leads to the following useful result. Recall that a finitely generated preclone S is effectively given if we are given a finite generating set A as transformations of finite arity of a given finite set Q, see Section 2.3.1. Corollary 4.19. Let S and T be effectively given, finitely generated, finitely determined preclones. Then it is decidable whether T belongs to the pseudovariety of preclones generated by S. Proof. Let A (resp. B) be the given set of generators of S (resp. T) and let V be the pseudovariety generated by S. By Corollary 4.16, T ∈ V if and only if T divides a direct power of S, say, T < S m . Since B is finite, almost all the sets Bk are empty. We claim that the exponent m can be bounded by |Ak ||Bk | . Bk =∅
Indeed, there exists a sub-preclone S ⊆ S m and an onto morphism S → T . Since B generates T, we may assume without loss of generality that this morphism defines a bijection from a set A of generators of S to B, and in particular, we may identify Bk with Ak , a subset of Am k . Next, one verifies that if m is greater than the bound in the claim, then there exist 1 i < j m such that for all k and x ∈ Ak , the ith and the jth components of x are equal—but this implies that the exponent can be decreased by 1. Thus, it suffices to test whether or not T divides S m , where m is given by the above formula. But as discussed above, this holds if and only if Am contains a set A and a rank preserving bijection from A to B which can be extended to a morphism from the sub-preclone of S m generated by A to T. By Proposition 2.14, and since S and T are effectively given and T is finitely determined, this can be checked algorithmically. 4.3. Closure properties of pseudovarieties Here we record additional closure properties of pseudovarieties of preclones. Lemma 4.20. Let V be a pseudovariety of preclones and let T be a finitary preclone. If T embeds in the inverse limit of an -diagram of preclones in V, then T ∈ V. Proof. The lemma follows immediately from Corollary 4.11.
Proposition 4.21. Let V be a pseudovariety of preclones and let S be a finitary preclone. If for each n 0, there exists a morphism n : S → S (n) such that S (n) ∈ V and n is injective on elements of rank exactly n, then S ∈ V. Proof. Without loss of generality we may assume that each n is surjective. For each n 0, consider the direct product T (n) = S (0) × · · · × S (n) , which is in V, and let n denote the
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
313
natural projection of T (n+1) onto T (n) . Let also n : S → T (n) be the target tupling of the morphisms i , i n, let T be the inverse limit limn T (n) determined by the morphisms n , and let n : T → T (n) be the corresponding projection morphisms. Note that each n is n-injective, and equals the composite of n+1 and n . Thus, there exists a (unique) morphism : S → T such that the composite of and n is n for each n. It follows from the n-injectivity of each n , that is injective. Thus, S embeds in the inverse limit of an -diagram of preclones in V, and we conclude by Lemma 4.20. We note the following easy corollary of Proposition 4.21: Corollary 4.22. Let V be a pseudovariety of preclones. Let S be a finitary preclone such that distinct elements of equal rank can be separated by a morphism from S to a preclone in V. Then S ∈ V. Proof. For any distinct elements f, g of equal rank n, let f,g : S → Sf,g be a morphism such that Sf,g ∈ V and f,g (f ) = f,g (g). For any integer n, let n be the target tupling of the finite collection of morphisms f,g with f, g ∈ Sn . Then n is injective on Sn and we conclude by Proposition 4.21. 4.4. Pseudovarieties of pg-pairs The formal treatment pseudovarieties of pg-pairs is similar to the above treatment of pseudovarieties of preclones—but for the following remarks. We define a pseudovariety of pg-pairs to be a class of finitary pg-pairs closed under finite direct product, sub-pg-pairs, quotients and finitary inverse limits of -diagrams. Our first remark is that, in this case, we do not need to mention finitary unions of -chains: indeed, finitary pg-pairs are finitely generated, so the union of an -chain, if it is finitary, amounts to a finite union. Next, the notion of inverse limit of -diagrams of pg-pairs needs some clarification. Consider a sequence of morphisms of pg-pairs, say n : (S (n+1) , A(n+1) ) → (S (n) , A(n) ). That is, each n is a preclone morphism from S (n+1) to S (n) , which maps A(n+1) into A(n) . We can then form the inverse limit limn S (n) of the -diagram determined by the preclone morphisms n , and the inverse limit limn A(n) determined by the set mappings n . The inverse limit limn (S (n) , A(n) ) of the -diagram determined by the morphisms of pg-pairs n (as determined by the appropriate universal limit, see Remark 4.2) is the pg-pair (S, A), where A = limn A(n) and S is the subpreclone of limn S (n) generated by A. Recall that this inverse limit is called finitary exactly when S is finitary and A is finite (see Example 4.3). We now establish the close connection between this inverse limit and the inverse limit of the underlying -diagram of preclones, when the latter is finitary. Proposition 4.23. Let n : (S (n+1) , A(n+1) ) → (S (n) , A(n) ) be an -diagram of pg-pairs. Let S = limn S (n) and let and (T , A) = limn (S (n) , A(n) ). If S is finitary, then S = T . Proof. We need to show that A generates S. Without loss of generality, we may assume that each n maps A(n+1) surjectively onto A(n) , and we denote by n the restriction of n to
314
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
A(n+1) . By definition, A is the inverse limit of the -diagram given by the n , and we denote by n : A → A(n) the corresponding projection. We also denote by n and n the extensions of these mappings to preclone morphisms A(n+1) M → A(n) M and AM → A(n) M. It is not difficult to verify that AM is the inverse limit of the -diagram given by the n , and that the n are the corresponding projections.
Moreover, each k is onto (even from A to A(k) ). Let indeed ak ∈ A(k) . Since the n are onto, we can define by induction a sequence (an )n k such that n (an+1 ) = an for each n k. This sequence can be completed with the iterated images of ak by k−1 , . . . , 0 to yield an element of A whose kth projection is ak . Since A(n) generates S (n) , the morphism n : A(n) M → S (n) induced by idA(n) is surjective. Moreover, the composites n ◦ n+1 and n ◦ n coincide.
It follows that the morphisms n ◦ n : AM → S (n) and n ◦ n+1 ◦ n+1 coincide, and hence there exists a morphism : AM → S such that n ◦ = n ◦ n for each n. Since n and n are onto, it follows that each n is surjective. We now use the fact that S is finitary. By Lemma 4.14, n is k-injective for each large enough n. Now let s ∈ Sk . We want to show that s ∈ (AM). Let nk be such that n is k-injective for each n nk . We can choose an element tnk ∈ A(nk ) M such that
nk (tnk ) = nk (s). Then, by induction, we can construct a sequence (tn )n of elements such that n (tn+1 ) = tn for each n 0. We need to show that n (tn ) = n (s) for each n. This equality is immediate for n nk , and we assume by induction that it holds for some n nk . We have
n ( n+1 (tn+1 )) = n ( n (tn+1 )) = n (tn ) = n (s) = n ( n+1 (tn+1 )). Since n and n+1 are surjective, since they are injective on Sk , and since n ◦ n+1 = n , (n+1) we find that n is injective on Sk , and hence n+1 (tn+1 ) = n+1 (s), as expected. Thus (tn )n ∈ AM and (t) = s, which concludes the proof that S is generated by A.
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
315
5. Varieties of tree languages Let V = (V,k ),k be a collection of nonempty classes of recognizable tree languages L ⊆ Mk , where runs over the finite ranked alphabet and k runs over the nonnegative integers. We call V a variety of tree languages, or a tree language variety, if each V,k is closed under the Boolean operations, and V is closed under inverse morphisms between free preclones generated by finite ranked sets, and under quotients defined as follows. Let L ⊆ Mk be a tree language, let k1 and k2 be nonnegative integers, u ∈ Mk1 +1+k2 and v ∈ Mn,k . Then the left quotient (u, k1 , k2 )−1 L and the right quotient Lv −1 are defined by (u, k1 , k2 )−1 L = {t ∈ Mn | u · (k1 ⊕ t ⊕ k2 ) ∈ L} where k = k1 + n + k2 , Lv −1 = {t ∈ Mn | t · v ∈ L}, that is, (u, k1 , k2 )−1 L is the set of elements of Mn for which (u, k1 , n, k2 ) is an L-context, and Lv −1 is the set of elements of Mn for which (1, 0, v, 0) is an L-context. Below we will write just u−1 L for (u, k1 , k2 )−1 L if k1 and k2 are understood, or play no role. A literal variety of tree languages is defined similarly, but instead of closure under inverse morphisms between finitely generated free preclones, we require closure under inverse morphisms between finitely generated free pg-pairs. Thus, if L ⊆ Mk is in a literal variety V and : M → M is a preclone morphism with , finite and () ⊆ , then −1 (L) is also in V. 5.1. Varieties of tree languages vs. pseudovarieties of preclones The aim of this section is to prove an Eilenberg correspondence between pseudovarieties of preclones (resp. pg-pairs), and varieties (resp. literal varieties) of tree languages. For each pseudovariety V of preclones (resp. pg-pairs), let var(V) = (V,k ),k , where V,k denotes the class of the tree languages L ⊆ Mk whose syntactic preclone (resp. pg-pair) belongs to V. It follows from Proposition 3.2 that var(V) consists of all those tree languages that can be recognized by a preclone (resp. pg-pair) in V. Conversely, if W is a variety (resp. a literal variety) of tree languages, we let psv(W) be the class of all finitary preclones (resp. pg-pairs) that only accept languages in W, i.e., −1 (F ) ⊆ Mk belongs to W, for all morphisms : M → S (resp. : (M, ) → (S, A)), k 0 and F ⊆ Sk . Theorem 5.1. The mappings var and psv are mutually inverse lattice isomorphisms between the lattice of pseudovarieties of preclones (resp. pg-paris) and the lattice of varieties (resp. literal varieties) of tree languages. Proof. We only prove the theorem for pseudovarieties of pg-pairs and literal varieties of tree languages. It is clear that for each pseudovariety V of finitary pg-pairs, if var(V) = (V,k ),k , then each V,k is closed under complementation and contains the languages ∅ and Mk . The closure of V,k under union follows in the standard way from the closure of V under direct product: if L, L ⊆ Mk are recognized by morphisms into pg-pairs (S, A)
316
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
and (S , A ) in V, then L ∪ L is recognized by a morphism into (S, A) × (S , A ). Thus V,k is closed under the Boolean operations. We now show that V is closed under quotients. Let L ⊆ Mk be in V,k , let : (M, ) → (S, A) be a morphism recognizing L with (S, A) ∈ V and L = −1 (L), and let F = (L). Let (u, k1 , v, k2 ) be an n-ary context, that is, u ∈ Mk1 +1+k2 , v ∈ Mn,! and k1 +!+k2 = k. Now let F = {f ∈ S! | (u) · (k1 ⊕ f ⊕ k2 ) ∈ F }. Then for any t ∈ M! , (t) ∈ F if and only if (u) · (k1 ⊕ (t) ⊕ k2 ) ∈ F , if and only if (u · (k1 ⊕ t ⊕ k2 )) ∈ F iff u · (k1 ⊕ t ⊕ k2 ) ∈ L. Thus, −1 (F ) = (u, k1 , k2 )−1 L, which is therefore in V,! . Now let F = {f ∈ Mn : f · (v) ∈ L}. It follows as above that Lv −1 = −1 (F ) and hence Lv −1 ∈ V,n . Before we proceed, let us observe that we just showed the following: if L ⊆ Mk is a recognizable tree language, then for each n 0 there are only finitely many distinct sets of the form ((u, k1 , k2 )−1 L)v −1 , where (u, k1 , v, k2 ) is an n-ary context of Mk . Next, let : (M, ) → (M, ) be a morphism of pg-pairs and L ⊆ Mk . If L is recognized by a morphism : (M, ) → (S, A), then −1 (L) is recognized by the composite morphism ◦ , and the closure of V by inverse morphisms between free pgpairs follows immediately. Thus the mapping var does associate with each pseudovariety of pg-pairs a literal variety of tree languages, and it clearly preserves the inclusion order. Now consider the mapping psv: we first verify that if W is a literal variety of tree languages, then the class psv(W) is a pseudovariety. Recall that, if (S, A) < (T , B), then any language recognized by (S, A) is also recognized by (T , B), so if each language recognized by (T , B) belongs to W, then the same holds for (S, A). Note also that any language recognized by the direct product (S, A) × (T , B) is a finite union of intersections of the form L∩M, where L is recognized by (S, A) and M by (T , B); thus psv(W) is closed under binary direct products. Finally, if (S, A) = limn (S (n) , A(n) ) is the finitary inverse limit of an -diagram of finitary pg-pairs, then Lemma 4.14 shows that the languages recognized by (S, A) are recognized by almost all of the (S (n) , A(n) ). Thus (S, A) ∈ psv(W), which concludes the proof that psv(W) is a pseudovariety of pg-pairs. Let W be a literal variety of tree languages, and let V = var(psv(W)). We now show that V = W. Since V consists of all the tree languages recognized by a pg-pair in W = psv(W), it is clear that V ⊆ W. Now let L ∈ W,k , and let (ML , AL ) be its syntactic pg-pair. To prove that (ML , AL ) ∈ W, it suffices to show that if : (M, ) → (ML , AL ) is a morphism of pg-pairs and x ∈ ML , then −1 (x) ∈ W. Since a morphism of pg-pairs maps generators to generators, up to renaming and identifying letters (which can be done by morphisms between free pg-pairs), we may assume that is the syntactic morphism of L. Thus −1 (x) is an equivalence class [w] in the syntactic congruence of L, and hence −1 (x) = ((u, k1 , k2 )−1 L)v −1 w∈((u,k1 ,k2 )−1 L)v −1
∩
w∈((u,k / 1 ,k2
)−1 L)v −1
((u, k1 , k2 )−1 L)v −1 ,
where L denotes the complement of L. If x has rank n, the intersections in this formula run over n-ary contexts (u, k1 , v, k2 ), and as observed above, these intersections are in fact finite. It follows that −1 (x) ∈ V. This concludes the verification that V = W, so var ◦ psv is the identity mapping, and in particular var is surjective and psv is injective.
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
317
It is clear that both maps var and psv preserve the inclusion order. In order to conclude that they are mutually reciprocal bijections, it suffices to verify that var is injective. If V and W are pseudovarieties such that var(V) = var(W) = V, then a tree language is in V if and only if its syntactic preclone is in V, if and only if its syntactic preclone is in W. Thus V and W contain the same syntactic preclones, and it follows from Corollary 4.8 that V = W. Remark 5.2. Three further variety theorems for finite trees exist in the literature. They differ from the variety theorem proved above since they use a different notion of morphism, quotient, and syntactic algebra. The variety theorem in [1,35] is formulated for tree language varieties over some fixed ranked alphabet and the morphisms are homomorphisms between finitely generated free algebras, whereas the “general variety theorem” of [36] allows for tree languages over different ranked alphabets and a more general notion of morphism, closely related to the morphisms of free pg-pairs. On the other hand, the morphisms in [19] are much more general than those in either [1,35,36] or the present paper, they even include nonlinear tree morphisms that allow for the duplication of a variable. Another difference is that the tree language varieties in [1,35,36] involve only left quotients, whereas the one presented here (and the varieties of [19]) are defined using two-sided quotients. The notion of syntactic algebra is also different in these papers: minimal tree automata in [1,35], a variant of minimal tree automata in [36], minimal clone (or Lawvere theory) in [19], and minimal preclone, or pg-pair, here. We refer to [19, Section 14] for a more detailed comparative discussion. As noted above, the abundance of variety theorems for finite trees is due to the fact that there are several reasonable ways of defining morphisms and quotients, and a choice of these notions is reflected by the corresponding notion of syntactic algebra. No variety theorem is known for the 3-sorted algebras proposed in [41]. 5.2. Examples of varieties of tree languages 5.2.1. Small examples As a practice example, we describe the variety of tree languages associated with the pseudovariety T∃ ! generated by T∃ (see Section 2.3.2). Let be a finite ranked alphabet and let L ⊆ Mk be a tree language accepted by a preclone in T∃ !. Then the syntactic preclone S of L lies in T∃ !. Recall that a syntactic preclone is finitely generated and finitely determined: it follows from Proposition 4.16 that S divides a product of a finite number of copies of T∃ . By a standard argument, L is therefore a (positive) Boolean combination of languages recognized by a morphism from M to T∃ . Now let : M → T∃ be a morphism. As discussed in Section 3.3, a tree language in M recognized by is either of the form Kk ( ) for some ⊆ , or it is the complement of such a language. From there, and using the same reasoning as in the analogous case concerning word languages, one can verify that a language L ∈ Mk is accepted by a preclone in T∃ ! if and only if L is a Boolean combination of languages of the form Kk ( ) ( ⊆ ), or equivalently, L is a Boolean combination of languages of the form Lk ( ), ⊆ , where Lk () is the set of all -trees of rank k, for which the set of node labels is exactly .
318
Z. Ésik, P. Weil / Theoretical Computer Science 340 (2005) 291 – 321
Similarly—and referring again to Section 3.3 for notation—one can give a description of the variety of tree languages associated with the pseudovariety Tp !, or the pseudovariety Tp,q !, using the languages of the form Kk (∃rp ) or Kk (∃rp,q ) instead of the Kk (∃). 5.2.2. FO[Succ]-definable tree languages In a recent paper [3], Benedikt and Ségoufin considered the class of FO[Succ]-definable tree languages. Note that the logical language used in FO[Succ] does not allow the predicate 0}, where f (n), g(n) are polynomial or exponential functions in n (see [5] for details). Observe that the peculiarities of the “classical’’star operations (along which such column, row or diagonal stars are defined) are mainly the following: (a) they are a simple iteration of one kind (row- or column- or diagonal-) of concatenation between pictures; (b) they correspond to an iterative process that at each step adds (concatenates) always the same set. We can say that they correspond to the idea of the iteration for some recursive H defined as H (1) = S and H (n + 1) = H (n)S, where S is a given set. In this section we define new types of iteration operations, to which we will refer as advanced stars, that result much more powerful than the “classical’’ ones. We will use subscripts “r”and “d” with the meaning of “right” and “down’’, respectively. Definition 31. Let L, Lr , Ld be two-dimensional languages. The star of L with respect to (Lr , Ld ) is defined as (Lr ,Ld )i L , L(Lr ,Ld )∗ = i 0
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
425
where L(Lr ,Ld )0 = {0,0 }, L(Lr ,Ld )1 = L and p pr (Lr ,Ld )i ∗∗ . = p = |p∈L , pr ∈ Lr , pd ∈ Ld , q ∈ pd q
(Lr ,Ld )i+1
L
Remark that the operation we defined cannot be simulated by a sequence of ❡ and ❡ operations because to get p we first concatenate p ❡pr and p ❡pd , then we overlay them and finally we fill the “hole’’ with a picture q ∈ ∗∗ . For this reason this definition is conceptually different from the one given by O. Matz in [15]. Moreover, observe that such advanced star is based on a reverse principle with respect to the diagonal star: we “decide’’ what to concatenate to the right and down to the given picture and then fill the hole in the bottom-right corner. This implies that, at (i + 1)th step of the iteration, we are forced to select pictures pr ∈ Lr and pd ∈ Ld that have the same number of rows and the same number of columns, respectively, of pictures generated at the ith step. Therefore, we actually exploit the fact that column and row concatenations are partial operations to somehow synchronize each step of the iteration with the choice of pictures in Lr and Ld . We now state the following proposition. Proposition 32. If L, Lr , Ld are languages in REC, then L(Lr ,Ld )∗ is in REC. Proof. We give only few hints for the proof because it can be carried over using the techniques shown in the proof of Proposition 10. The idea is to assume that the tiling systems for L, Lr , Ld are over disjoints local alphabets , r , d and define a local language M over an alphabet equal to the union of the three ones together with a new different symbol {x}. Language M contains pictures like p pr , where p , pr and pd belong to the local pd s languages for L, Lr and Ld , respectively and s is any picture filled with symbol x. Then the set of tiles for L = L(Lr ,Ld )∗ can be defined by taking two “different copies’’ (i.e., over disjoint local alphabets) of languages M and different local languages for Lr and Ld and define tiles according to the definition of pictures in L .
As immediate application, consider the language L = {(n, n2 ) | n 0} of Example 28. Then L can be defined as advanced star of M = {(1, 1)} with respect to Mr = {(n, 2n + 1) n 0} and Md = {(1, n) | n 0} (at (i + 1)th step of the iteration we “add’’ (2i + 1) columns to the current i 2 ones and 1 row to the current i ones). Using the same principle, namely exchanging languages Mr and Md , it is easy to define also the rotation of this language, i.e. language L = {(n2 , n) | n 0}. Then also the language L = {(n2 , n2 ) | n 0} can be defined as advanced star of M = {(1, 1)} with respect to Nr = {(n2 , 2n + 1) n 0} and Nd = {(2n + 1, n2 ) | n 0}, where Nr (Nd ) can be obtained by column-concatenation (row-concatenation) of two copies of L (L) and 1-row (1-column) pictures. Remark that, even using the above defined advanced star, it seems still not possible to define the language of Example 29 of pictures of size (2n , 2n ) or the language of pictures of size (n, 2n ) and similar ones. In fact, for this kind of languages (recall that they are all
426
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
in REC), it would be needed a definition that allows to use as Lr and/or Ld the language itself. We give the following definition. Definition 33. Let L, Ld be two-dimensional languages. The bi-iteration along the columns of L with respect to Ld is defined as (∗,Ld )i L , L(∗,Ld )∗ = i 0
where L(∗,Ld )0 = {0,0 }, L(∗,Ld )1 = L and p p 1 2 | p1 , p2 ∈ L(∗,Ld )i , pd ∈ Ld , q ∈ ∗∗ . L(∗,Ld )i+1 = p = pd q Similarly we define the bi-iteration along the rows of L with respect to a language Lr , denoted by L(Lr ,∗)∗ , where the (i + 1)th step of the iteration is given by p1 pr (Lr ,∗)i+1 (Lr ,∗)i ∗∗ . = p = | p1 , p2 ∈ L , pr ∈ Lr , q ∈ L p2 q These notations naturally bring us to define also the bi-iteration along rows and columns, denoted by L(∗,∗)∗ , where the (i + 1)th step of the iteration is given by p1 p3 (∗,∗)i+1 (∗,∗)i ∗∗ . = p = | p1 , p2 , p3 ∈ L ,q∈ L p2 q Using same techniques as in the proof of Proposition 32, one can prove that the family REC over one-letter alphabet is closed under all such bi-iteration operations. It is immediate to verify that the language L of pictures of size (n, 2n ) can be obtained from language M = {(1, 1)} and Md = {(1, n) | n > 0} as L = M (∗,Md )∗ . We conclude by observing that the language of Example 29 of pictures of size (2n , 2n ) can be obtained as a bi-iteration both along rows and columns of the same language M = {(1, 1)}. 5. Towards the general alphabet case In this paper, we have defined new operations between pictures so that a quite wide class of two-dimensional languages over one-letter alphabet could be described in terms of regular expressions. All these languages belong to REC that is the class of recognizable languages that generalizes better to two dimensions the class of regular string languages. Next step is surely to complete the definitions of some other kind of “advanced’’ star operations in the aim of proving a two-dimensional Kleene’s Theorem in this simpler case of one-letter alphabet. We also emphasize that an important goal of further work is to extend all these results to the general case of two-dimensional languages over any alphabet (i.e. the case with more
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
427
than one-letter). Observe that the definitions of diagonal concatenation and star are hard to extend to such general case, even using their characterizations in terms of rational relations or in terms of automata with only two moving directions. The main problem is that, if p, q are two pictures over , to define q \❡q we need to specify two pictures r, s such that p r . p \❡q = s q On the other hand, the formalism of the advanced stars appears to be a more reasonable approach to the general case. Recall that, in this case, we need always to specify four pictures (or four languages). We will use subscripts r, d and c with the meaning of “right”, “down” and “corner”, respectively. Then, we can give the following definition that directly extends Definition 31. Definition 34. Let L, Lr , Ld , Lc be two-dimensional languages over . The star of L with respect to (Lr , Ld , Lc ) is defined as (Lr ,Ld ,Lc )i L , L(Lr ,Ld ,Lc )∗ = i 0
where L(Lr ,Ld ,Lc )0 = {0,0 }, L(Lr ,Ld ,Lc )1 = L and p pr (Lr ,Ld ,Lc )i+1 (Lr ,Ld ,Lc )i = p = |p∈L , pr ∈ Lr , pd ∈ Ld , pc ∈ Lc . L pd p c Remark that this kind of star operation is not the iteration of a “classical’’ concatenation operation. These operations seem to be able to describe several languages in REC, despite the “regular expressions’’ for the two-dimensional languages in the general case will result very complex. Appendix A. Proposition 23. Let L be a CRD-regular language. Then there exist
, , , : N → N, , : N × N → N increasing functions and n, m ∈ N such that for any p = (n, m) ∈ L we have ❡ (1) if m > (n) then p ❡q ∗ ⊆ L for q = (n, (n)) with (n) = 0, ❡ ∗ ❡ (2) if n > (m) then p q ⊆ L for q = ((m), m) with (n) = 0, \❡ ❡ (3) if n n, m m then p \ q ∗ ⊆ L for some q = (nq , mq ) with nq , mq = 0, nq (n, m), mq (n, m). Proof. First let us see how to choose , , , in all these cases. From Proposition 22, we know that the sets Cn = {a m | (n, m) ∈ L} and Rm = {a n | (n, m) ∈ L} are regular and therefore ultimately periodic. So there exist hC , kC , hR , kR ∈ N such that a j ∈ Cn ⇔ a j +kC ∈ Cn , for every j hC , and a j ∈ Rm ⇔ a j +kR ∈ Rm , for every j hR . If we do not take care to the fact that , , , have to be increasing and that , have to be = 0, then it would be sufficient to set (n) = hC , (m) = hR , (n) = kC and
428
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
(m) = kR . But, to be sure that (n), (m) = 0 and to assure the increase of the functions, we set (n) = hC + s1 kC , (n) = hR + s2 kR , (n) = kC + s3 kC and (m) = kR + s4 kR , where kC = max{1, kC }, kR = max{1, kR } and s1 , s2 , s3 , s4 0 are the minimal integer such that (n) (n − 1), (n) (n − 1), (n) (n − 1) and (n) (n − 1). Let us now show how to choose n, m, and for a CRD-regular language L. Let r be a CRD-regular expression denoting L. The proof is by induction on the number of operators in r. For the basis, if L = ∅ then the proposition is vacuously true. If L = {0,0 }, then we can set n = 1, m = 1, (n) = 0, (m) = 0. If L = {1,0 } (resp. L = {0,1 }), then we can set n = 2 (resp. n = 1), m = 1 (resp. m = 2), (n) = 0 (resp. (n) = 1), (m) = 1 (resp. (m) = 0). In all these cases we can set (n) = 1, (m) = 1, (n, m) = (n, m) = 1. Assume now that the proposition is true for languages denoted by CRD-regular expression with less than i operators, i 1, and let r have i operators. There are seven cases depending ❡ on the form of r: (1) r = r1 ∪r2 , (2) r = r1 ❡r2 , (3) r = r1 ❡r2 , (4) r = r1 \❡r2 , (5) r = r1∗ , ❡ \❡ (6) r = r1∗ , or (7) r = r1∗ . In any of the seven cases, r1 and r2 denote some language L1 and L2 , respectively, that satisfies the condition. Let 1 , 1 , 1 , 1 , 1 , 1 , n1 , m1 be the functions and the values for L1 and let 2 , 2 , 2 , 2 , 2 , 2 , n2 , m2 be the functions and the values for L2 . Case 1: We have L = L1 ∪ L2 . We set (n, m) = max{ 1 (n, m), 2 (n, m)}, (n, m) = max{ 1 (n, m), 2 (n, m)}, n = max{n1 , n2 }, m = max{m1 , m2 }. Case 2: We have L = L1 ❡L2 . We set: (n, m) = max{ 1 (n, m) 2 (n, m), 1 (m) 2 (n, m), 2 (m) 1 (n, m)},
(n,m) = max{ 1(n,m) 2 (n,m) + 2 (n,m) 1 (n,m), 1 (m) 2 (n,m), 2 (m) 1 (n, m)}, n = max{n1 , n2 , 1 (m1 ), 2 (m2 )}, m = m1 + m2 . Now, let p = (n, m) ∈ L, with n n, m m. Clearly, p = p1 ❡p2 for some p1 = (np1 , mp1 ) = (n, mp1 ) ∈ L1 and p2 = (np2 , mp2 ) = (n, mp2 ) ∈ L2 . We have to consider three different cases: (2a) mp1 m1 and mp2 m2 , (2b) mp1 < m1 , (2c) mp2 < m2 . (2a) Since np1 n1 , mp1 m1 , np2 n2 and mp2 m2 , from the hypothesis on L1 \❡ and L2 , we have that p1 \❡q1∗ ⊆ L1 for some q1 = (nq1 , mq1 ) with nq1 , mq1 = 0, \❡ nq1 1 (n, mp1 ), mq1 1 (n, mp1 ) and that p2 \❡q2∗ ⊆ L2 for some q2 = (nq2 , mq2 ) with nq2 , mq2 = 0, nq2 2 (n, mp2 ), mq2 2 (n, mp2 ). \❡ Now let us set q = (nq1 nq2 , nq1 mq2 + nq2 mq1 ) = (nq , mq ). Then p \❡q ∗ ⊆ L with nq , mq = 0, nq = nq1 nq2 1 (n, mp1 ) 2 (n, mp2 ) 1 (n, m) 2 (n, m) and mq = nq1 mq2 + nq2 mq1 1 (n, m) 2 (n, m) + 2 (n, m) 1 (n, m). (2b) Since mp1 < m1 , then mp2 m2 (recall that mp1 + mp2 = m m = m1 + m2 ) and \❡ therefore p2 \❡q2∗ ⊆ L2 for some q2 = (nq2 , mq2 ) with nq2 , mq2 = 0, nq2 2 (n, mp2 ), ❡ mq2 2 (n, mp2 ). Moreover nq1 = n n 1 (m1 ) > 1 (mp1 ): therefore p1 ❡q1∗ ⊆ L1 for q1 = (nq1 , mq1 ) = (1 (mp1 ), mp1 ). Note that we have nq1 = 0. Let us set q = \❡ (nq1 nq2 , nq1 mq2 ) = (nq , mq ). Then we have p \❡q ∗ ⊆ L with nq , mq = 0, nq = nq1 nq2 1 (mp1 ) 2 (n, mp2 ) 1 (m) 2 (n, m) and mq = nq1 mq2 1 (mp1 ) 2 (n, mp2 ) 1 (m) 2 (n, m).
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
429
(2c) It is analogous to the previous case. Case 3: We have L = L1 ❡L2 and the proof is similar to that one of the previous case. Case 4: We have L = L1 \❡L2 . We set: (n, m) = max{ 1 (n, m), 2 (n, m), 1 (m), 2 (m)},
(n, m) = max{ 1 (n, m), 2 (n, m), 2 (n), 1 (n)}, n = max{n1 + n2 , 1 (m1 ) + n2 , 2 (m2 ) + n1 }, m = max{m1 + m2 , 2 (n2 ) + m1 , 1 (n1 ) + m2 }. Now, let p = (n, m) ∈ L = L1 \❡L2 , with n n, m m. Clearly, p = p1 \❡p2 for some p1 = (np1 , mp1 ) ∈ L1 and p2 = (np2 , mp2 ) ∈ L2 . We have to consider two different cases 4(a) and (b): with nq , mq = 0 (4a) At least one of the following conditions (1) and (2) is verified
np1 n1 , (1) mp1 m1 .
(2)
np2 n2 , mp2 m2 .
\❡ If condition (1) is verified, then p1 \❡q1∗ ⊆ L1 for some q1 = (nq1 , mq1 ) with nq1 , mq1 = 0, nq1 1 (n, m), mq1 1 (n, m) and it suffices to set q = q1 . If, instead, condition (2) is \❡ verified, then p2 \❡q2∗ ⊆ L2 for some q2 = (nq2 , mq2 ) with nq2 , mq2 = 0, nq2 2 (n, m), mq2 2 (n, m) and it suffices to set q = q2 . (4b) If neither condition (1) nor condition (2) is verified, then, again, we have to consider two different subcases either np1 n1 , mp1 < m1 , np2 < n2 , mp2 m2 or np1 < n1 , mp1 m1 , np2 n2 , mp2 < m2 . We give the details only for the first subcase, since the other one can be handled in a similar way. So, in the first subcase, we have np1 = n−np2 n−np2 > n−n2 1 (m1 )+n2 −n2 = 1 (m1 ) > 1 (mp1 ) i.e., np1 > 1 (mp1 ) and mp2 = m − mp1 m − mp1 > m − m1 2 (n2 ) + m1 − m1 = 2 (n2 ) > 2 (np2 ) i.e., ❡ ❡ mp2 > 2 (np2 ). Therefore, p1 ❡q1∗ ⊆ L1 for q1 = (1 (mp1 ), mp1 ) and p2 ❡q2∗ ⊆ L2 for q2 = (np2 , 2 (np2 )). We set q = (nq , mq ) = (nq1 , mq2 ) = (1 (mp1 ), 2 (np2 )) \❡ and we will have p \❡q ∗ ⊆ L with nq , mq = 0, nq = 1 (mp1 ) 1 (m), mq = 2 (np2 ) 2 (n). m ❡ Case 5: We have L = L∗1 . We set (n, m) = max{ 1 (n, m), m 1 (n, m)1 (m)}, (n, m) m = max{m 1 (n, m) m−1 (n, m)1 (m), 1 (n, m)}, n = max{n1 , 1 (m1 )} and m = m1 . 1 Now, let p = (n, m) ∈ L, with n n, m m. If m = 0, then p ∈ L1 and we can apply the inductive hypothesis. If instead m = 0, then we have p = p1 ❡ · · · ❡pk with pi = (npi , mpi ) = (n, mpi ) ∈ L1 . Let us consider two different subcases 5(a) and (b). (5a) There exists some ™ ∈ {1, . . . , k} such that mpi m1 for every i = 1, . . . , ™ and mpi < m1 for every i = ™ + 1, . . . , k. Therefore, for every i = 1, . . . , ™, there exists qi = \❡ (nqi , mqi ) with nqi , mqi = 0, nqi 1 (npi , mpi ), mqi 1 (npi , mpi ), such that pi \❡qi∗ ⊆ L1 . Note that for i = 1, . . . , ™, we have nqi 1 (npi , mpi ) = 1 (n, mpi ) 1 (n, m), mqi 1 (npi , mpi ) = 1 (n, mpi ) 1 (n, m). Moreover, since for every i = ™ + 1, . . . , k, we have mpi < m1 , it follows that 1 (mpi ) < 1 (m1 ) n n = npi . So for every i = ❡ ™ + 1, . . . , k, there exists qi = (nqi , mqi ) = (1 (mqi ), mqi ) such that pi ❡qi∗ ⊆ L1 . We \❡ set q = (nq , mq ) = ( ki=1 nqi , ™i=1 (mqi kj =1,j =i nqj )). Then p \❡q ∗ ⊆ L, where
m
nq , mq = 0, with nq ™1 (n, m) 1 (mq™+1 ) . . . 1 (mqk ) m 1 (n, m)1 (m) and mq =
430
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431 m
m
m
mq1 m−1 (n, m) 1 (m) + · · · + mq™ m−1 (n, m)1 (m) 1 (n, m)™ m−1 (n, m)1 (m) 1 1 1 m (n, m) (m) . m 1 (n, m) m−1 1 1 (5b) In this subcase, for every i=1, . . . , k, mpi <m1 . Therefore, as in case (5a), for ❡ every i=1, . . . , k, there exists qi =(nqi , mqi ) = (1 (mqi ), mqi ) such that pi ❡qi∗ ⊆L1 . k m m We set q=(nq , mq )=( i=1 nqi , m). Then nq , mq =0, nq 1 (m) m 1 (n, m)1 (m), m mq = m m 1 (n, m) m−1 (n, m)1 (m). 1 Case 6: This case is analogous to the previous one. \❡ Case 7: We have L = L∗1 . If there exists q = (nq , mq ) ∈ L with nq , mq = 0, we can \❡ set (n, m) = nq , (n, m) = mq , n = m = 0. Then for every p = (n, m) ∈ L = L∗1 we \❡ have p \❡q ∗ ⊆ L. If instead L ⊆ col (resp. L ⊆ row ), then we can set n = 0, m = 1 (resp. n = 1, m = 0) and condition (3) will be vacuously true. Note that in all the cases the choice of the functions , , , , and preserves their increase.
References [1] M. Anselmo, D. Giammarresi, M. Madonia, Regular expressions for two-dimensional languages over oneletter alphabet, in: C.S. Calude, E. Calude, M.J. Dinneen (Eds.), Proc. Development in Language Theory (DLT 04), Lecture Notes in Computer Science, Vol. 3340, Springer, Berlin, 2004, pp. 63–75. [2] J. Berstel, Transductions and Context-free Languages, Teubner, 1979. [3] M. Blum, C. Hewitt, Automata on a two-dimensional tape, IEEE Symp. on Switching and Automata Theory, 1967, pp. 155–160. [4] L. De Prophetis, S. Varricchio, Recognizability of rectangular pictures by Wang systems, J. Automat. Languages Combin. 2 (1997) 269–288. [5] D. Giammarresi, Two-dimensional languages and recognizable functions, in: G. Rozenberg, A. Salomaa (Eds.), Proc. Developments in Language Theory, Finland, 1993, World Scientific Publishing Co., Singapore, 1994. [6] D. Giammarresi, A. Restivo, Two-dimensional finite state recognizability, Fund. Inform. 25 (3,4) (1996) 399–422. [7] D. Giammarresi, A. Restivo, Two-dimensional languages, in: G. Rozenberg, et al. (Eds.), Handbook of Formal Languages, Vol. III, Springer, Berlin, 1997, pp. 215–268. [8] J.E. Hopcroft, J.D. Ullman, Introduction to Automata Theory, Languages and Computation, Addison-Wesley, Reading, MA, 1979. [9] K. Inoue, A. Nakamura, Some properties of two-dimensional on-line tessellation acceptors, Inform. Sci. 13 (1977) 95–121. [10] K. Inoue, A. Nakamura, Two-dimensional finite automata and unacceptable functions, Internat. J. Comput. Math. Sec. A 7 (1979) 207–213. [11] K. Inoue, I. Takanami, A characterization of recognizable picture languages, in: Proc. Second Internat. Colloq. on Parallel Image Processing, Lecture Notes in Computer Science, Vol. 654, Springer, Berlin, 1993. [12] K. Inoue, I. Takanami, A. Nakamura, A note on two-dimensional finite automata, Inform. Process. Lett. 7 (1) (1978) 49–52. [13] J. Kari, C. Moore, Rectangles and squares recognized by two-dimensional automata, In: J. Karhumaki, H. Maurer, G. Paun, G. Rozenburg (Eds.), Theory is Forever, Essays dedicated to Arto Salomaa on the occasion of his 70th birthday. LNCS 3113 (2004) 134–144. [14] E.B. Kinber, Three-way automata on rectangular tapes over a one-letter alphabet, Inform. Sci. 35 (1985) 61–77. [15] O. Matz, Regular expressions and context-free grammars for picture languages, Proc. STACS’97, Lecture Notes in Computer Science, Vol. 1200, Springer, Berlin, 1997, pp. 283–294.
M. Anselmo et al. / Theoretical Computer Science 340 (2005) 408 – 431
431
[16] O. Matz, On piecewise testable, starfree, and recognizable picture languages, in: M. Nivat (Ed.), Foundations of Software Science and Computation Structures, Vol. 1378, Springer, Berlin, 1998. [17] M. Rabin, T. Scott, Finite automata and their decision problems, IBM J. Res. Dev. 3 (1959) 114–125. [18] D. Simplot, A characterization of recognizable picture languages by tilings by finite sets, Theoret. Comput. Sci. 218 (2) (1999) 297–323. [19] T. Wilke, Star-free picture expressions are strictly weaker than first-order logic, in: Proc. ICALP’97, Lecture Notes in Computer Science, Vol. 1256, Springer, Berlin, 1997, pp. 347–357.
Theoretical Computer Science 340 (2005) 432 – 442 www.elsevier.com/locate/tcs
Parsing with a finite dictionary Julien Clémenta , Jean-Pierre Duvalb,∗ , Giovanna Guaianab , Dominique Perrina , Giuseppina Rindonea a Institut Gaspard-Monge, Université de Marne-la-Vallée, France b LIFAR, Université de Rouen, France
Abstract We address the following issue: given a word w ∈ A∗ and a set of n nonempty words X, how does one determine efficiently whether w ∈ X ∗ or not? We discuss several methods including an O(r × |w| + |X|) algorithm for this problem where r n is the length of a longest suffix chain of X and |X| is the sum of the lengths of words in X. We also consider the more general problem of providing all the decompositions of w in words of X. © 2005 Elsevier B.V. All rights reserved. Keywords: Finite automata; String matching
1. Introduction The complexity of algorithms related to finite automata and regular expressions is wellknown in general. In this article, we focus on a particular problem, namely the complexity of parsing a regular language of the form Y = X ∗ where X is a finite set of nonempty words. This type of language occurs often in the applications, when X is a dictionary and Y is the set of texts obtained by arbitrary concatenations of strings from this dictionary. The time and space complexity can be an important issue in such applications since the dictionaries used for natural languages can contain up to several million words. ∗ Corresponding author. Tel.: +33 235 146610; fax: +33 235 146763.
E-mail addresses:
[email protected] (J. Clément),
[email protected] (J.-P. Duval),
[email protected] (G. Guaiana),
[email protected] (D. Perrin),
[email protected] (G. Rindone). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.030
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
433
As a consequence of general constructions from automata theory, any regular language can be parsed in time proportional to the product of the size of the regular expression by the length of the input word. This just amounts to simulating a nondeterministic automaton built in a standard way from the regular expression. Using a deterministic automaton produces a linear-time algorithm after completing a determinization algorithm which may itself be exponential. Our main result here is an algorithm allowing one to parse a regular language of the form X ∗ , with X finite, in time O(r × |w| + |X|) with r the length of a longest suffix chain in X, w the input word and |X| the sum of the lengths of words in X (Sections 4 and 5). The quantity r depending only on the set X is upper bounded by Card(X). This algorithm allows one to get all the decompositions of the input word in words of X. We also discuss some further problems on the automata related to regular expressions of this type (Section 3). The motivation of our study is in the work of Schützenberger on this type of languages. He has shown that although the size of the automaton depends on the length of the words in X, several syntactic parameters depend only on the cardinality of X (see [14]). One of them is linked with the number of interpretations of a word in words of X, and is related with the problem considered here. A similar yet unsolved problem is the complexity of the problem of unambiguity of the expression X ∗ , i.e. of the problem of testing whether X is a code. The standard algorithm [13] gives a quadratic complexity O(|X|2 ) where |X| is the total length of the words of X. It was lowered later to O(Card(X) × |X|) by various authors [2,11,6,8]. However, it is not known whether there exists a linear algorithm (see [5]).
2. Preliminaries and notations For a more complete description of automata and fundamentals of formal languages, the reader is referred to [7,9,12] and to [16] in particular for a recent overview on recognizable languages in free monoids. Let A be a finite alphabet. We denote by ε the empty word and by A∗ (resp. A+ ) the set of finite words (resp. nonempty finite words) on A. For a word w ∈ A∗ , we denote by |w| the length of w, by w[j ] for 0 j < |w| the letter of index j in w, and by w[j..k] = w[j ]w[j + 1] · · · w[k]. For any decomposition w = uv with u, v ∈ A∗ we say that u and v are, respectively, a prefix and a suffix of w. The suffix v is said to be proper if v = w. For a finite set X of words on A, we denote by Pref (X) and Suff (X) the set of prefixes and suffixes of the words of X, respectively, by Card(X) the cardinality of X and by |X| the sum of the lengths of words of X, that is |X| =
x∈X
|x|.
We denote a nondeterministic finite automaton over the alphabet A by A = (Q, , i, T ), where Q is the set of states, i ∈ Q is the initial state, T ⊆ Q is the set of terminal states and is the transition function. We use A to denote the number of states of A. We abbreviate by NFA a nondeterministic finite automaton and by DFA a deterministic finite automaton.
434
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
3. Using deterministic automata Before presenting our algorithm, we examine what would be the classical approach to check if a word w is in X ∗ . A natural idea is to build an automaton for X ∗ . We consider the following process: (i) build a finite automaton for X, (ii) modify this automaton to accept X∗ (doing so, we usually get an NFA), and (iii) finally get a DFA after a classical determinization procedure. An optional fourth step could be to minimize the resulting automaton. Automata for a finite set of words X. First we consider three simple ways of building an automaton for a finite set of words X. (1) The “solar” automaton SX is obtained as follows: we build one automaton per word x ∈ X with |x| + 1 states and merge all the initial states (see Fig. 1). Note that this NFA is a tree with root i and that SX = |X| + 1. (2) The tree automaton TX (see Fig. 1): this is a tree which collects words sharing a common prefix. In terms of automata, the set of states corresponds to the set of prefixes and we have TX = Q = Pref (X), , i = , T = X with (p, a) = pa if p, pa ∈ Pref (X) and a ∈ A. This DFA has TX = Card(Pref (X)) states. (3) The minimal automaton MX (see Fig. 1). Given the set X a more elaborate method is to build the minimal DFA MX recognizing X. For instance one can apply a minimization algorithm to the tree automata TX in linear time with respect to |X| [10]. Of course MX is not necessarily a tree. Automata for the language X ∗ . A straightforward way to build an NFA recognizing the language X ∗ from an automaton A = (Q, , i, T ) recognizing X is to add -transitions from each final state of T to the initial state i. We denote this automaton by star(A) (see Fig. 2). To save a little more space, we also merge all the terminal states without outgoing
b
a a
b a
b a
b
b
b a
a
a
b
a
b
b a
b a
a
b
a
b
b
b Fig. 1. The solar NFA SX (left), the tree DFA TX (middle) and the minimal DFA MX for X = {aa, ab, bb, aba, abb}.
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
435
b
a
a b
a b
b
b
b a
a
a b
a
a a
b
b
b
Fig. 2. The flower automaton merge(SX ) (left) and the NFA star(TX ) (right) for X = {aa, ab, bb, aba, abb}.
a b
a b
b
a b
b
a
a
b a Fig. 3. An NFA for X ∗ with the set X = Ak a + b (k = 5) of Example 1.
transitions with the initial state: this yields an automaton merge(A). Doing so with the solar automaton SX , we obtain merge(SX ) the classical flower automaton of X ∗ (see Fig. 2). Applying the classical powerset construction to one of the previous automata accepting X∗ , we obtain a DFA for X ∗ . Note that the determinization procedure gives the same result either starting from star(SX ) or from star(TX ), due to their tree-like structures. The same is true with merge instead of star. In general, for an NFA A, the determinization procedure builds a DFA whose number of states is trivially bounded by 2A . However, when we consider the particular case of X ∗ with X finite, could an exponential blow-up really happen? The following example shows that the answer is positive. Example 1. Let us consider X = Ak a + b with k > 0. It is easy to give an NFA for X ∗ with k + 1 states (see Fig. 3). The determinization leads to a DFA with (2k ) states. Another question is to find if we can relate the number of states of a DFA for X ∗ to |X|. Until recently, it was thought that it could not exceed (|X|2 ), a bound which was shown to be reachable in [17], as stated in the following example.
436
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
Example 2. For an integer h > 1, take X = {a h−1 , a h }. The tree DFA TX and the minimal DFA MX are the same and have h + 1 = (|X|) states. The minimal DFA for X ∗ has (|X|2 ) states (see [17]). Shallit showed in [15] with the following example that an exponential blow-up is also possible. Example 3. Let h 3 and let X = {b} ∪ {a i ba h−i−1 |1 i h − 2} ∪ {ba h−2 b}. The minimal DFA accepting X∗ has exactly 3(h − 1)2h−3 + 2h−2 states [15]. Note that the size is exponential of order (h2h ) whereas Card(X) = (h) and |X| = (h2 ). The problem of finding a tight upper bound for the number of states of the minimal DFA for X∗ in terms of the total length |X| is called by this author [15] the noncommutative Frobenius problem. The number of states of the minimal automata obtained for the family of sets used in Example 3 is (h2h ) where h = (|X|1/2 ). A priori, the upper bound for a DFA obtained by determinization of an NFA for X∗ with (|X|) states is (2|X| ). Experiments performed on the family of Example 3 show that the DFA obtained by determinization 2 (before minimization) has also (h2h ) states, and not (2h ). We do not know in general whether (i) it is possible that the minimal DFA for X∗ has (2|X| ) states; (ii) it is possible that the DFA obtained by determinization has (2|X| ) states. Simulating the determinization process. A way to avoid the determinization step would be to simulate the determinized automaton while parsing the word w. Given an NFA A accepting the language X∗ with X a finite set of words, this gives an algorithm of time complexity O(A × |w|) and the space required to simulate the determinization process is A. Since the number of states of the NFA can be of order O(|X|), this approach gives a time complexity O(|X| × |w|) in the worst case. As an example of such a situation, we have the set X = {a k b, a} with k > 0.
4. Using string matching machines The methods discussed in the previous section do not lead to an optimal algorithm in O(|w|). Indeed, either we use a DFA and we face a computation which can be exponential in |X| or we simulate the DFA and we obtain an algorithm in O(|X| × |w|). We now consider a different approach which leads to a lower complexity. Another advantage of the proposed approach is to possibly solve a more general problem. Indeed, we may be interested in obtaining the set of all decompositions of the input word over X. This cannot be achieved using a DFA accepting X ∗ given for instance by the methods described in the previous section.
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
437
Let X = {x0 , . . . , xn−1 } be a set of n words of A+ . We present in this section an algorithm, using classic pattern matching techniques, which gives all the X-decompositions of w (the decompositions of w as concatenations of words of X). Then we derive a membership test for X∗ in O(Card(X) × |w|) time complexity. In the next section, we shall study a further improvement of this algorithm.
4.1. Decompositions The following remark is the basis of our algorithm. An X-decomposition of w is always the extension of an X-decomposition of a prefix of w. We consider the prefix w[0..i] of length i + 1 of w. The word w[0..i] admits an Xdecomposition ending with a word x if and only if w[0..i] = f x for a word f in X ∗ . In other terms, w[0..i] admits an X-decomposition ending with x if and only if x is a suffix of w[0..i] and w[0..i − |x |] ∈ X ∗ . We obtain all the X-decompositions of w[0..i] by examining all the words of X which are suffixes of w[0..i] and which extend a previous X-decomposition. Of course, when w[0..i] = w, we get all the X-decompositions of w. So the idea of the algorithm is the following: build, for each word x ∈ X, a deterministic automaton A accepting the language A∗ x and use an auxiliary array D of size |w| such that D[i] = { ∈ [0..n − 1] | w[0..i] ∈ X∗ x }. Then testing if w[0..i] ends by the word x is equivalent to checking that the automaton A is in a terminal state after reading w[0..i]. Also testing if w[0..i − |x |] ∈ X ∗ is equivalent to checking that D[i − |x |] = ∅. In the following algorithm, the input word w is read simultaneously by all the n automata, letter by letter, from left to right. We use, for technical convenience, an additional element D[−1] initialized to an arbitrary nonempty set (for instance {∞}) meaning that the prefix ε of w is always in X ∗ . At the end of the scanning of w, provided D[|w| − 1] = ∅, we can process the array D from the end to the beginning and recover all the Xdecompositions for instance with a recursive procedure like PRINTALLDECOMPOSITIONS() (see below). For each word x ∈ X, the automaton A considered here is the minimal automaton which recognizes the language A∗ x . This automaton is defined by A = (Q = Pref (x ), , i = ε, t = x ) where the transition function is defined, for p ∈ Pref (x ) and a ∈ A, by
(p, a) = the longest suffix of pa which belongs to Pref (x ). We use these principles in the following algorithm.
438
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
ISDECOMPOSEDALL(w, X = {x0 , . . . , xn−1 }) 1 Preprocessing step 2 for ← 0 to n − 1 do 3 A ← AUTOMATONFROMWORD(x ) 4 Main loop 5 for ← 0 to n − 1 do 6 p is the current state of the automaton A . 7 p ← i 8 D[−1] ← {∞} 9 for i ← 0 to |w| − 1 do 10 D[i] ← ∅ 11 for ← 0 to n − 1 do 12 p ← (p , w[i]) 13 if p = t and D[i − |x |] = ∅ then 14 D[i] ← D[i] ∪ {} 15 return D The algorithm returns an array of size O(Card(X) × |w|). The preprocessing step which builds automata requires a time O(|X|) and a space O(|X|×Card(A)) (or O(|X|) if automata are represented with the help of a failure function as usually made in stringology [4,3]). Note that we do not need to build all the automata A in the preprocessing step. We can also choose to construct in a lazy way the accessible part of the automata (corresponding for each automaton A to the prefixes of x occurring in w) along the processing of the input word w. For the sake of clarity, we have chosen to distinguish the preprocessing step from the rest. In view of this remark, we could omit the complexity O(|X|) of the preprocessing step in the following proposition. Proposition 4. The time and space complexity of the algorithm ISDECOMPOSEDALL() is O(Card(X) × |w| + |X|). Given the array D computed by the procedure ISDECOMPOSEDALL() for a word w, it is quite straightforward to print all the decompositions of w thanks to the following two procedures: PRINTALLDECOMPOSITIONS(w, X = {x0 , . . . , xn−1 }) 1 D ← IsDECOMPOSEDALL(w, X) 2 L ← emptyList 3 RECPRINTALLDECOMPOSITIONS(D, |w| − 1, L) RECPRINTALLDECOMPOSITIONS(D, h, L) 1 if h = −1 then 2 PRINT(L) 3 else for j ∈ D[h] do 4 RECPRINTALLDECOMPOSITIONS(D, h − |xj |, xj · L)
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
439
For a word w belonging to X ∗ the procedure PRINTALLDECOMPOSITIONS() prints every X-decomposition of w in the form xi0 · xi1 · · · xip . If we want only one X-decomposition of w, it suffices to store in D[i] only one word x of X corresponding to an X-decomposition of w[0..i] ending with this x. The space required for the array then becomes O(|w|). 4.2. Membership test When we are interested only in testing the membership of w in X ∗ , we can simply use a Boolean array D setting D[i] = true if and only if there exists x ∈ X such that w[0..i] ∈ X∗ x. Moreover, it suffices to use a circular Boolean array D[0..k] with k = maxx∈X |x| (instead of |w| + 1), and compute indexes in this array modulo k + 1 (which means that for m ∈ Z, one has D[m] = D[r] with 0 r < k + 1 and m = r mod (k + 1)). This yields the following algorithm. MEMBERSHIP(w, X = {x0 , . . . , xn−1 }) 1 Preprocessing step 2 for ← 0 to n − 1 do 3 A ← AUTOMATONFROMWORD(x ) 4 Main loop 5 for ← 0 to n − 1 do 6 p is the current state of the automaton A . 7 p ← i 8 D[−1] ← true 9 for i ← 0 to |w| − 1 do 10 D[i] ← false 11 for ← 0 to n − 1 do 12 p ← (p , w[i]) 13 ←0 14 do if (p = t and D[i − |x |] = true) then 15 D[i] ← true 16 ←+1 17 while ( < n and D[i] = false) 18 return D[|w| − 1] We can easily modify the algorithm while preserving the same complexity by exiting whenever all the elements of the array D from 0 to k are false. In this case, w ∈ / X∗ . The following proposition gives the complexity of the above algorithm. Proposition 5. The time complexity of the algorithm MEMBERSHIP() is O(Card(X) × |w| + |X|). The analysis of the space complexity shows that, except for the preprocessing step, the algorithm needs only O(maxx∈X |x|) additional space. In particular, the space complexity is independent of the length of the input word.
440
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
5. String matching automaton In the preceding section, we used for each word x ∈ X a distinct automaton A corresponding to A∗ x . To get a more efficient algorithm, we resort in this section to the well-known Aho–Corasick algorithm [1] which is built from a finite set of words X a deterministic complete automaton (not necessarily minimal) AX recognizing the language A∗ X. This automaton is the basis of many efficient algorithms on string matching problems and is often called the string matching automaton. It is a generalization of the automaton A associated to a single word. Let us briefly recall its construction. We let AX = (Pref (X), , ε, Pref (X) ∩ A∗ X) be the automaton where the set of states is Pref (X), the initial state is ε, the set of final states is Pref (X) ∩ A∗ X and the transition function is defined by
(p, a) = the longest suffix of pa which belongs to Pref (X). We associate to each word u ∈ A∗ , u = ε, the word Border X (u), or simply Border(u) when there is no ambiguity, defined by Border(u) = the longest proper suffix of u which belongs to Pref (X). The automaton AX can be easily built from the tree TX (cf. Section 3) of X by a breadth-first exploration and using the Border function. Indeed, one has if pa ∈ Pref (X), pa (p, a) = (Border(p), a) if p = ε and pa ∈ Pref (X), ε otherwise. A state p is terminal for AX if p is a word of X (i.e. p is terminal in the tree TX of X) or if a proper suffix of p is a word of X. The automaton AX can be built in time and space complexity O(|X|) if we use the function Border as a failure function (see [4,3] for implementation details). We will say, for simplicity, that a state of the automaton is marked if it corresponds to a word of X and not marked otherwise. A major difference induced by the Aho–Corasick automaton is that a terminal state p, marked or not, corresponds to an ordered set Suff (p)∩X of suffixes of p. The order considered is given by the suffix relation suff where u suff v means that v is a proper suffix of u. We denote by SuffixChain(p) the sequence of words in Suff (p) ∩ X ordered by this relation. To find easily the words of SuffixChain(p), we associate to each terminal state p of AX the state SuffixLink(p) = the longest proper suffix of p which belongs to X. Thus we have
if Border(p) ∈ X, Border(p) SuffixLink(p) = SuffixLink(Border(p)) if Border(p) ∈ X and Border(p) = ε, undefined otherwise.
Since SuffixLink(p) is computed in time O(|p|), the preprocessing can be done in time and space complexity O(|X|), i.e. the complexity of the Aho–Corasick algorithm.
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
a
a
a
b
a
b
a
a
b a
b
a a
b a
b
a
b
b
a b
b b
b
441
a
a
a
Fig. 4. For the set X = {a 2 , a 4 b, a 3 ba, a 2 b, ab} of Example 7: Tree TX (left), Aho–Corasick automaton with links Border (middle) and the new links SuffixLink (right) to add to the Aho–Corasick automaton.
To decide whether an input word w belongs to X ∗ or not (and get eventually its Xdecompositions), we use the same technique as in the previous section, considering this time the automaton AX (instead of the n automata A ). The immediate advantage is that each letter of the word w is read only once (meaning that only one transition is made in the automaton) whereas each letter was read n times before (one per automaton A ). Let us suppose that for the current prefix w[0..i] of w, the automaton AX ends in a terminal state p. This means that w[0..i] = fp with f ∈ A∗ and p the longest suffix of w[0..i] in Pref (X) ∩ A∗ X. Consequently, w[0..i] ∈ X ∗ if and only if w[0..i − |x|] ∈ X ∗ for at least one word x of SuffixChain(p). This is easily checked using the marking of terminal states (whether they correspond exactly to a word of X or not), the function SuffixLink(p) and the array D (which plays exactly the same role as in the previous section). This yields our main result, stated in the following proposition. Proposition 6. Let X be a finite set of words on A. The membership test of a word w in X ∗ can be done in time O(r × |w| + |X|) where r is the maximal length of the suffix chains in X. The space complexity includes O(|X|) for the preprocessing step (building the Aho– Corasick automaton) and O(maxx∈X |x|) for the rest of the algorithm. If X is a suffix code, the complexity, except for the preprocessing step, becomes O(|w|) which is optimal, whereas the worst case happens when all words are suffixes of one another giving the same complexity O(Card(X) × |w|) as in the previous section. Note also that in the particular case where X is a prefix code, it is easy to solve the membership problem for X ∗ in an optimal time O(|w|) after an O(|X|) preprocessing step. Example 7. Let X = {a 2 , a 4 b, a 3 ba, a 2 b, ab}. For the word w = a 5 b, it is necessary to follow the suffix chain SuffixChain(a 4 b) = (a 4 b, a 2 b, ab) since after parsing w the automaton is in the state corresponding to a 4 b and the unique X-decomposition is a 5 b = a 2 · a 2 · ab. Fig. 4 shows the tree TX (left), the automaton AX with the links representing the
442
J. Clément et al. / Theoretical Computer Science 340 (2005) 432 – 442
failure function Border (middle) and the SuffixLink representing the suffix chains (right) to add to the Aho–Corasick automaton. Acknowledgements We thank the referee for pointing us the reference to Shallit [15] used in Example 3. The style for algorithms is algochl.sty from [3] and automata are drawn thanks to gastex. References [1] A.V. Aho, M.J. Corasick, Efficient string matching: an aid to bibliographic search, Commun. ACM 18 (6) (1975) 333–340. [2] A. Apostolico, R. Giancarlo, Pattern matching implementation of a fast test for unique decipherability, Inform. Process. Lett. 18 (1984) 155–158. [3] M. Crochemore, C. Hancart, T. Lecroq, Algorithmique du texte, Vuibert, 2001, 347pp. [4] M. Crochemore, W. Rytter, Jewels of Stringology, World Scientific, Hong-Kong, 2002, 310pp. [5] Z. Galil, Open problems in stringology, in: A. Apostolico, Z. Galil (Eds.), Combinatorial Algorithms on Words, Springer, Berlin, 1985, pp. 1–8. [6] C.M. Hoffmann, A note on unique decipherability, in: MFCS, Lecture Notes in Computer Science, Vol. 176, Springer, Berlin, New York, 1984, pp. 50–63. [7] J. Hopcroft, R. Motwani, J. Ullman, Introduction to Automata Theory, Languages and Computation, AddisonWesley, Reading MA, 2001. [8] R. McCloskey, An o(n2 ) time algorithm for deciding whether a regular language is a code, J. Comput. Inform. 2 (1) (1996) 79–89 Special issue: Proc. Eighth Internat. Conf. on Computing and Information, ICCI’96. [9] D. Perrin, Finite automata, in: J. Leeuwen (Ed.), Handbook of Theoretical Computer Science, Formal Models and Semantics, Vol. B, Elsevier, Amsterdam, 1990, pp. 1–57. [10] D. Revuz, Minimisation of acyclic deterministic automata in linear time, Theoret. Comput. Sci. 92 (1) (1992) 181–189. [11] M. Rodeh, A fast test for unique decipherability based on suffix trees, IEEE Trans. Inform. Theory 28 (1982) 648–651. [12] J. Sakarovitch, Eléments de théorie des automates, Vuibert, 2003. [13] A. Sardinas, G. Patterson, A necessary and sufficient condition for the unique decomposition of coded messages, in: IRE Convention Record, part 8, 1953, pp. 104–108. [14] M.-P. Schützenberger, A property of finitely generated submonoids of free monoids, in: G. Pollak (Ed.), Algebraic Theory of Semigroups, Proc. Sixth Algebraic Conf., Szeged, 1976, North-Holland, Amsterdam, 1979, pp. 545–576. [15] J. Shallit, Regular expressions, enumeration and state complexity, invited talk at Ninth Internat. Conf. on Implementation and Application of Automata (CIAA 2004) Queen’s University, Kingston, Ontario, Canada, July 22–24, 2004. [16] S. Yu, Regular languages, in: G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages, Springer, Berlin, New York, 1997, pp. 41–110. [17] S. Yu, State complexity of regular languages, in: Proc. Descriptional Complexity of Automata, Grammars and Related Structures, 1999, pp. 77–88.
Theoretical Computer Science 340 (2005) 443 – 456 www.elsevier.com/locate/tcs
A topological approach to transductions Jean-Éric Pina,∗ , Pedro V. Silvab a LIAFA, Université Paris VII and CNRS, Case 7014, 2 Place Jussieu, 75251 Paris Cedex 05, France b Centro de Matemática, Faculdade de Ciências, Universidade do Porto, R. Campo Alegre 687,
4169-007 Porto, Portugal
Abstract This paper is a contribution to the mathematical foundations of the theory of automata. We give a topological characterization of the transductions from a monoid M into a monoid N, such that if R is a recognizable subset of N, −1 (R) is a recognizable subset of M. We impose two conditions on the monoids, which are fullfilled in all cases of practical interest: the monoids must be residually finite and, for every positive integer n, must have only finitely many congruences of index n. Our solution proceeds in two steps. First we show that such a monoid, equipped with the so-called Hall distance, is a metric space whose completion is compact. Next we prove that can be lifted to a map ˆ from M into the set of compact subsets of the completion of N. This latter set, equipped with the Hausdorff metric, is again a compact monoid. Finally, our main result states that −1 preserves recognizable sets if and only if ˆ is continuous. © 2005 Elsevier B.V. All rights reserved.
1. Introduction This paper is a contribution to the mathematical foundations of automata theory. We are mostly interested in the study of transductions from a monoid M into another monoid N such that, for every recognizable subset R of N, −1 (R) is a recognizable subset of M. We propose to call such transductions continuous, a term introduced in [7] in the case where M is a finitely generated free monoid.
∗ Corresponding author.
E-mail addresses:
[email protected] (J.-É. Pin),
[email protected] (P.V. Silva). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.03.029
444
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
In mathematics, the word “continuous” generally refers to a topology. The aim in this paper is to find appropriate topologies for which our use of the term continuous coincides with its usual topological meaning. This problem was already solved when is a mapping from A∗ into B ∗ . In this case, a result which goes back at least to the 1980s (see [14]) states that is continuous in our sense if and only if it is continuous for the profinite topology on A∗ and B ∗ . We shall not attempt to define here the profinite topology and the reader is referred to [3,4,21] for more details. This result actually extends to mappings from A∗ into a residually finite monoid N, thanks to a result of Berstel et al. [7] recalled below (Proposition 2.3). However, a transduction : M → N is not a map from M into N, but a map from M into the set of subsets of N, which calls for a more sophisticated solution, since it does not suffice to find an appropriate topology on N. Our solution proceeds in two steps. We first show, under fairly general assumptions on M and N, which are fulfilled in all cases of practical interest, that M and N can be equipped with a metric, the Hall metric, for which they become metric monoids whose completion (as metric spaces) is compact. Next we prove that can ) of compact subsets of N , the completion be lifted to a map from M into the monoid K(N ), equipped with the Hausdorff metric, is again a compact monoid. of N. The monoid K(N Finally, our main result states that is continuous in our sense if and only if is continuous in the topological sense. Our paper is organised as follows. Basic results on recognizable sets and transductions are recalled in Section 2. Section 3 is devoted to topology and is divided into several subsections: Section 3.1 is a reminder of basic notions in topology, metric monoids and the Hall metric are introduced in Sections 3.2 and 3.3, respectively. The connections between clopen and recognizable sets are discussed in Section 3.5 and Section 3.6 deals with the monoid of compact subsets of a compact monoid. Our main result on transductions is presented in Section 4. Examples like the transductions (x, n) → x n and x → x ∗ are studied in Section 5. The paper ends with a short conclusion.
2. Recognizable languages and transductions Recall that a subset P of a monoid M is recognizable if there exists a finite monoid F and a monoid morphism : M → F and a subset Q of F such that P = −1 (Q). The set of recognizable subsets of M is denoted by Rec(M). Recognizable subsets are closed under boolean operations, quotients and inverse morphisms. By Kleene’s theorem, a subset of a finitely generated free monoid is recognizable if and only if it is rational. The description of the recognizable subsets of a product of monoids was given by Mezei (see [5, p. 54] for a proof). Theorem 2.1 (Mezei). Let M1 , . . . , Mn be monoids. A subset of M1 × · · · × Mn is recognizable if and only if it is a finite union of subsets of the form R1 × · · · × Rn , where Ri ∈ Rec(Mi ). The following result is perhaps less known (see [5, p. 61]).
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
445
Proposition 2.2. Let A1 , …, An be finite alphabets. Then Rec(A∗1 × A∗2 × · · · × A∗n ) is closed under concatenation product. Given two monoids M and N, recall that a transduction from M into N is a relation on M and N, that we shall also consider as a map from M into the monoid of subsets of N. If X is a subset of M, we set (X) = (x). x∈X
Observe that “transductions commute with union”: if (Xi )i∈I is a family of subsets of M, then Xi = (Xi ). i∈I
i∈I
If : M → N is a transduction, then the inverse relation −1 : N → M is also a transduction, and if P is a subset of N, the following formula holds:
−1 (P ) = {x ∈ M | (x) ∩ P = ∅}. A transduction : M → N preserves recognizable sets if, for every set R ∈ Rec(M), (R) ∈ Rec(N ). It is said to be continuous if −1 preserves recognizable sets, that is, if for every set R ∈ Rec(N ), −1 (R) ∈ Rec(M). Continuous transductions were characterized in [7] when M is a finitely generated free monoid. Recall that a transduction : M → N is rational if it is a rational subset of M × N . According to Berstel et al. [7], a transduction : A∗ → N is residually rational if, for any morphism : N → F , where F is a finite monoid, the transduction ◦ : A∗ → F is rational. We can now state: Proposition 2.3 (Berstel et al. [7] ). A transduction : A∗ → N is continuous if and only if it is residually rational. 3. Topology The aim of this section is to give a topological characterization of the transductions from a monoid into another monoid such that −1 preserves recognizable sets. Even if topology is undoubtedly part of the background of the average mathematician, it is probably not a daily concern of the specialists in automata theory to which this paper is addressed. For those readers whose memories in topology might be somewhat blurry, we start with a brief overview of some key concepts in topology used in this paper. 3.1. Basic notions in topology A metric d on a set E is a map from E into the set of nonnegative real numbers satisfying the three following conditions, for all (x, y, z) ∈ E 3 : (1) d(x, y) = 0 if and only if x = y,
446
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
(2) d(y, x) = d(x, y), (3) d(x, z) d(x, y) + d(y, z). A metric is an ultrametric if (3) is replaced by the stronger condition (3 ) d(x, z) max{d(x, y), d(y, z)}. A metric space is a set E together with a metric d on E. Given a positive real number and an element x in E, the open ball of center x and radius is the set B(x, ) = {y ∈ E | d(x, y) < }. A function from a metric space (E, d) into another metric space (E , d ) is uniformly continuous if, for every > 0, there exists > 0 such that, for all (x, x ) ∈ E 2 , d(x, x ) < implies d((x), (x )) < . It is an isometry if, for all (x, x ) ∈ E 2 , d((x), (x )) = d(x, x ). A sequence (xn )n 0 of elements of E is converging to a limit x ∈ E if, for every > 0, there exists N such that for all integers n > N , d(xn , x) < . It is a Cauchy sequence if, for every positive real number > 0, there is an integer N such that for all integers p, q N , d(xp , xq ) < . A metric space E is said to be complete if every Cauchy sequence of elements of E converges to a limit. containing E as For any metric space E, one can construct a complete metric space E, 1 a dense subspace and satisfying the following universal property: if F is any complete metric space and is any uniformly continuous function from E to F, then there exists → F which extends . The space E is : E a unique uniformly continuous function determined up to isometry by this property, and is called the completion of E. Metric spaces are a special instance of the more general notion of topological space. A topology on a set E is a set T of subsets of E, called the open sets of the topology, satisfying the following conditions: (1) ∅ and E are in T , (2) T is closed under arbitrary union, (3) T is closed under finite intersection. The complement of an open set is called a closed set. The closure of a subset X of E, denoted by X, is the intersection of the closed sets containing X. A subset of E is dense if its closure is equal to E. A topological space is a set E together with a topology on E. A map from a topological space into another one is continuous if the inverse image of each open set is an open set. A basis for a topology on E is a collection B of open subsets of E such that every open set is the union of elements of B. The open sets of the topology generated by B are by definition the arbitrary unions of elements of B. In the case of a metric space, the open balls form a basis of the topology. A topological space (E, T ) is Hausdorff if for each u, v ∈ E with u = v, there exist disjoint open sets U and V such that u ∈ U and v ∈ V . A family of open sets (Ui )i∈I is said to cover a topological space (E, T ) if E = i∈I Ui . A topological space (E, T ) is said to be compact if it is Hausdorff and if, for each family of open sets covering E, there exists a finite subfamily that still covers E. To conclude this section, we remind the reader of a classical result on compact sets. 1 See definition below.
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
447
Proposition 3.1. Let T and T be two topologies on a set E. Suppose that (E, T ) is compact and that (E, T ) is Hausdorff. If T ⊆ T , then T = T . Proof. Consider the identity map from (E, T ) into (E, T ). It is a continuous map, since T ⊆ T . Therefore, if F is closed in (E, T ), it is compact, and its continuous image (F ) in the Hausdorff space (E, T ) is also compact, and hence closed. Thus −1 is also continuous, whence T = T . 3.2. Metric monoids Let M be a monoid. A monoid morphism : M → N separates two elements u and v of M if (u) = (v). By extension, we say that a monoid N separates two elements of M if there exists a morphism : M → N which separates them. A monoid is residually finite if any pair of distinct elements of M can be separated by a finite monoid. Residually finite monoids include finite monoids, free monoids, free groups and many others. They are closed under direct products and thus monoids of the form A∗1 ×A∗2 ×· · ·×A∗n are also residually finite. A metric monoid is a monoid equipped with a metric for which its multiplication is uniformly continuous. Finite monoids, equipped with the discrete metric, are examples of metric monoids. More precisely, if M is a finite monoid, the discrete metric d is defined by 0 if s = t, d(s, t) = 1 otherwise. In the sequel, we shall systematically consider finite monoids as metric monoids. Morphisms between metric monoids are required to be uniformly continuous. 3.3. Hall metric Any residually finite monoid M can be equipped with the Hall metric d, defined as follows. We first set, for all (u, v) ∈ M 2 : r(u, v) = min{Card(N ) N separates u and v}. Then we set d(u, v) = 2−r(u,v) , with the usual conventions min ∅ = +∞ and 2−∞ = 0. Let us first establish some general properties of d. Proposition 3.2. In a residually finite monoid M, d is an ultrametric. Furthermore, the relations d(uw, vw) d(u, v) and d(wu, wv) d(u, v) hold for every (u, v, w) ∈ M 3 . Proof. It is clear that d(u, v) = d(v, u). Suppose that d(u, v) = 0. Then u cannot be separated from v by any finite monoid, and since M is residually finite, this shows that u = v. Finally, let (u, v, w) ∈ M 3 . First assume that u = w. Since M is residually finite, u and w can be separated by some finite monoid F. Therefore F separates either u and v, or v and w. It follows that min{(r(u, v), r(v, w)} r(u, w) and hence d(u, w) max{d(u, v), d(v, w)}. This relation clearly also holds if u = w.
448
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
The second assertion is trivial. A finite monoid separating uw and vw certainly separates u and v. Therefore d(uw, vw) d(u, v) and dually, d(wu, wv) d(u, v). The next two propositions state two fundamental properties of the Hall metric. Proposition 3.3. Multiplication on M is uniformly continuous for the Hall metric. Thus (M, d) is a metric monoid. Proof. It is a consequence of the following relation d(uv, u v ) max{d(uv, uv ), d(uv , u v )} max{d(v, v ), d(u, u )} which follows from Proposition 3.2. Proposition 3.4. Let M be a residually finite monoid. Then any morphism from (M, d) onto a finite discrete monoid is uniformly continuous. Proof. Let be a morphism from M onto a finite monoid F. Then by definition of d, d(u, v) < 2−|F | implies (u) = (v). Thus is uniformly continuous. d), is called the Hall comThe completion of the metric space (M, d), denoted by (M, pletion of M. Since multiplication on M is uniformly continuous, it extends, in a unique which is again uniformly continuous. In particular, M way, into a multiplication onto M, any morphism from is a metric, complete monoid. Similarly, Proposition 3.4 extends to M: d) onto a finite discrete monoid is uniformly continuous. (M, is compact. We now characterize the residually finite monoids M such that M is compact if and only if, for Proposition 3.5. Let M be a residually finite monoid. Then M every positive integer n, there are only finitely many congruences of index n on M. Proof. Recall that the completion of a metric space is compact if and only if it is precompact, that is, for every > 0, it can be covered by a finite number of open balls of radius . Denote by Cn the set of all congruences on M of index n and let n be the intersection of all congruences of Cn . is compact and let n > 0. Since M is precompact, there exist a Assume first that M finite subset F of M such that the balls B(x, 2−n ), with x ∈ F , cover M. Let x ∈ F and y ∈ B(x, 2−n ). Then r(x, y) > n and thus the monoids of size n cannot separate x from y. It follows that x y for each ∈ Cn and thus x n y. Therefore n is a congruence of finite index, whose index is at most |F |. Now each congruence of Cn is coarser than n , and since there are only finitely many congruences coarser than n , Cn is finite. Conversely, assume that, for every positive integer n, there are only finitely many congruences of index n on M. Given > 0, let n be an integer such that 2−n n and so d(x, y) < 2−n < . It follows that M is is compact. covered by a finite number of open balls of radius . Therefore M An important sufficient condition is given in the following corollary.
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
449
is Corollary 3.6. Let M be a residually finite monoid. If M is finitely generated, then M compact. Proof. Let n>0. There are only finitely many monoids of size n. Since M is finitely generated, there are only finitely many morphisms from M onto a monoid of size n. Now, since any congruence of index n is the kernel of such a morphism, there are only finitely many is compact. congruences on M of index n. It follows by Proposition 3.5 that M 3.4. Hall-compact monoids Proposition 3.5 justifies the following terminology. We will say that a monoid M is Hallcompact if it is residually finite and if, for every positive integer n, there are only finitely many congruences of index n on M. Proposition 3.5 can now be rephrased as follows: is compact.” “A residually finite monoid M is Hall-compact if and only if M and Corollary 3.6 states that “Every residually finite and finitely generated monoid is Hall-compact.” The class of Hall-compact monoids includes most of the examples used in practice: finitely generated free monoids (resp. groups), finitely generated free commutative monoids (resp. groups), finite monoids, trace monoids, finite products of such monoids, etc. The next proposition shows that the converse to Corollary 3.6 does not hold. Proposition 3.7. There exists a residually finite, nonfinitely generated monoid M such that is compact. M Proof. Let P be the set of all prime numbers and let M = p∈P Z/p Z, where Z/p Z denotes the additive cyclic group of order p. It is clear that M is residually finite. Furthermore, in a finitely generated commutative group, the subgroup consisting of all elements of finite period is finite [12]. It follows that M is not finitely generated. Let n > 0 and let : M → N be a morphism from M onto a finite monoid of size n. Since M is a commutative group, N is also a commutative group. For every prime p > n, the order of the image of a generator of Z/p Z must divide p and be n, hence the image of this generator must be 0. Consequently, any such morphism is determined by the images of the generators of Z/p Z for p n, and so there are only finitely many of them. Therefore is compact by there are only finitely many congruences on M of index n and so M Proposition 3.5. 3.5. Clopen sets versus recognizable sets Recall that a clopen subset of a topological space is a subset which is both open and closed. A topological space is zero-dimensional if its clopen subsets form a basis for its topology. d) are zeroProposition 3.8. Let M be a residually finite monoid. Then (M, d) and (M, dimensional.
450
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
Proof. The open balls of the form B(x, 2−n ) = {y ∈ M | d(x, y) < 2−n }, | d(x, y) < 2−n }, 2−n ) = {y ∈ M B(x, and n is a positive integer, form a basis of the Hall topology where x belongs to M (resp. M) But these balls are clopen since of M (resp. M). {y | d(x, y) < 2−n } = {y | d(x, y) 2−(n+1) }. d) are zero-dimensional. It follows that (M, d) and (M,
is profinite (see Proposition 3.8 implies that if M is a Hall-compact monoid then M [1,3,4,21] for the definition of profinite monoids and several equivalent properties), but we will not use this result in this paper. We now give three results relating clopen sets and recognizable sets. The first one is due to Hunter [9, Lemma 4], the second one summarizes results due to Numakura [13] (see also [17,2]). The third result is stated in [3] for free profinite monoids. For the convenience of the reader, we present a self-contained proof of the second and the third results. Recall that the syntactic congruence of a subset P of a monoid M is defined, for all u, v ∈ M, by s∼t
if and only if, for all (x, y) ∈ M 2 ,
xuy ∈ P ⇔ xvy ∈ P .
It is the coarsest congruence of M which saturates P. Lemma 3.9 (Hunter’s Lemma [9]). In a compact monoid, the syntactic congruence of a clopen set is clopen. Proposition 3.10. In a compact monoid, every clopen subset is recognizable. If M is a is clopen. residually finite monoid, then every recognizable subset of M Proof. Let M be a compact monoid, let P be a clopen subset of M and let ∼P be its syntactic congruence. By Hunter’s Lemma, ∼P is clopen. Thus for each x ∈ M, there exists an open neighborhood G of x such that G × G ⊆ ∼P . Therefore G is contained in the ∼P -class of x. This proves that the ∼P -classes form an open partition of M. By compactness, this partition is finite, and hence P is recognizable. Suppose now that M is a residually finite monoid and let P be a recognizable subset Let : M → F be the syntactic morphism of P. Since P is recognizable, F is of M. finite and by Proposition 3.4, is uniformly continuous. Now P = −1 (Q) for some subset Q of F. Since F is discrete and finite, Q is a clopen subset of F and hence P is also clopen. The last result of this subsection is a clone of a standard result on free profinite monoids (see [3] for instance).
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
451
Proposition 3.11. Let M be a Hall-compact monoid, let P be a subset of M and let P be The following conditions are equivalent: its closure in M. (1) P is recognizable, (2) P = K ∩ M for some clopen subset K of M, and P = P ∩ M, (3) P is clopen in M and P = P ∩ M. (4) P is recognizable in M Proof. (1) implies (2). Let : M → F be the syntactic monoid of P and let Q = (P ). Since F is finite, is uniformly continuous by Proposition 3.4 and extends to a uniformly → F . Thus K = continuous morphism :M −1 (Q) is clopen and satisfies K ∩ M = P . Then the (2) implies (3). Suppose that P = K ∩ M for some clopen subset K of M. equality P = P ∩ M follows from the following sequence of inclusions P ⊆ P ∩ M = (K ∩ M) ∩ M ⊆ K ∩ M = K ∩ M = P . K ∩ M is dense in K. Thus P = Furthermore, since K is open and M is dense in M, K ∩ M = K = K. Thus P is clopen in M. The equivalence of (3) and (4) follows from Proposition 3.10, which shows that in M, the notions of clopen set and of recognizable set are equivalent. → F be the syntactic monoid of P and let Q = (4) implies (1). Let :M (P ). Let be the restriction of to M. Then we have P = P ∩ M = −1 (Q) ∩ M = −1 (Q). Thus P is recognizable. 3.6. The monoid of compact subsets of a compact monoid Let M be a compact monoid, and let K(M) be the monoid of compact subsets of M. The Hausdorff metric on K(M) is defined as follows. For K, K ∈ K(M), let
(K, K ) = sup inf d(x, x ) x∈K x ∈K max((K, K ), (K , K)) if K and K are nonempty, if K and K are empty, h(K, K ) = 0 1 otherwise. The last case occurs when one and only one of K or K is empty. By a standard result of topology, K(M), equipped with this metric, is compact. The next result states a property of clopen sets which will be crucial in the proof of our main result. and let Proposition 3.12. Let M be a Hall-compact monoid, let C be a clopen subset of M : K(M) → K(M) be the map defined by (K) = K ∩ C. Then is uniformly continuous for the Hausdorff metric. Proof. Since C is open, every element x ∈ C belongs to some open ball B(x, ) contained is compact, C is also compact and can be covered by a finite number of these in C. Since M open balls, say (B(xi , i ))1 i n . Let > 0 and let = min{1, , 1 , . . . , n }. Suppose that h(K, K ) < with K = K . Then K, K = ∅, d(x, K ) < for every x ∈ K and d(x , K) < for every x ∈ K .
452
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
Suppose that x ∈ K ∩ C. Since d(x, K ) < , we have d(x, x ) < for some x ∈ K . Furthermore, x ∈ B(xi , i ) for some i ∈ {1, . . . , n}. Since d is an ultrametric, the relations d(x, xi ) < i and d(x, x ) < i imply that d(x , xi ) < i and thus x ∈ B(xi , i ). Now since B(xi , i ) is contained in C, x ∈ K ∩ C and hence d(x, K ∩ C) < < . By symmetry, d(x , K ∩ C) < for every x ∈ K ∩ C. Hence h(K ∩ C, K ∩ C ) < and is continuous. 4. Transductions ), Let M and N be Hall-compact monoids and let : M → N be a transduction. Then K(N ) equipped with the Hausdorff metric, is also a compact monoid. Define a map : M → K(N (x) = (x). by setting, for each x ∈ M, Theorem 4.1. The transduction −1 preserves the recognizable sets if and only if is uniformly continuous. is compact, it Proof. Suppose that −1 preserves the recognizable sets. Let > 0. Since N can be covered by a finite number of open balls of radius /2, say = B(xi , /2). N 1i k
is zero-dimensional by Proposition 3.8, its clopen subsets constitute a basis for Since N is a union of its topology. Thus every open ball B(xi , /2) is a union of clopen sets and N clopen sets each of which is contained in a ball of radius /2. By compactness, we may assume that this union is finite. Thus = Cj , N 1j n
where each Cj is a clopen set contained in, say, B(xij , /2). It follows now from Proposition 3.11 that Cj ∩N is a recognizable subset of N. Since −1 preserves the recognizable sets, the sets Lj = −1 (Cj ∩ N ) are also recognizable. By Proposition 3.4, the syntactic morphism of Lj is uniformly continuous and thus, there exists j such that d(u, v) < j implies u ∼Lj v. Taking = min{j | 1 j n}, we have for all (u, v) ∈ M 2 , d(u, v) < ⇒ for all j ∈ {1, . . . , n}, u ∼Lj v. We claim that, whenever d(u, v) < , we have h((u), (v)) < . By definition, Lj = {x ∈ M | (x) ∩ Cj ∩ N = ∅}. / 1 j n Lj . Since u ∼Lj v for Suppose first that (u) = ∅. Then u ∈ every j, it follows that v ∈ / 1 j n Lj , so (v) ∩ Cj ∩ N = ∅ for 1 j n. Since N = 1 j n (Cj ∩ N ), it follows that (v) = ∅. by symmetry, we conclude that (u) = ∅ if and only if (v) = ∅. Thus we may assume that both (u) and (v) are nonempty. Let y ∈ (u). Then y ∈ Cj ∩ N for some j ∈ {1, . . . , n} and so u ∈ Lj . Since u ∼Lj v, it follows that v ∈ Lj and
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
453
hence there exists some z ∈ (v) such that z ∈ Cj ∩ N . Since Cj ⊆ B(xij , /2), we obtain d(xij , y) < /2 and d(xij , z) < /2, whence d(y, z) < /2 since d is an ultrametric. Thus d(y, (v)) < /2. Since (u) is dense in (u), it follows that d(x, (v)) /2 for every x ∈ (u) and so
((u), (v)) /2 < . By symmetry, ((v), (u)) < and hence h((u), (v)) < as required. Next we show that if is uniformly continuous, then −1 preserves the recognizable can be extended to a uniformly continuous mapping sets. First, → K(N ). ˇ : M Let L be a recognizable subset of N. By Proposition 3.11, L = C ∩ N for some clopen . Let subset C of N ) | K ∩ C = ∅}. R = {K ∈ K(N ). Let : K(N ) → K(N ) be the map defined by We show that R is a clopen subset of K(N (K) = K∩C. By Proposition 3.12, is uniformly continuous and since R = −1 ({∅}c ) = ). Since B(∅, 1) = {∅}, {∅} is [−1 ({∅})]c , it suffices that {∅} is a clopen subset of K(N c / B(K, 1), we have B(K, 1) ⊆ {∅}c and so {∅}c is also open. open. Let K ∈ {∅} . Since ∅ ∈ Therefore {∅} is clopen and so is R. Since ˇ is continuous, ˇ −1 (R) is a clopen subset of M −1 and so M ∩ ˇ (R) is recognizable by Proposition 3.11. Now M ∩ ˇ −1 (R) = {u ∈ M | ˇ (u) ∈ R} = {u ∈ M | (u) ∈ R} = {u ∈ M | (u) ∩ C = ∅}. Since C is open, we have (u) ∩ C = ∅ if and only if (u) ∩ C = ∅, hence M ∩ ˇ −1 (R) = {u ∈ M | (u) ∩ C = ∅} = {u ∈ M | (u) ∩ L = ∅} = −1 (L) and so −1 (L) is a recognizable subset of M. Thus −1 preserves the recognizable sets.
5. Examples of continuous transductions A large number of examples of continuous transductions can be found in the literature [6–8,10,11,15,16,18,20]. We state without proof two elementary results: continuous transductions are closed under composition and include constant transductions. Proposition 5.1. Let L ⊆ N and let L : M → N be the transduction defined by L (x) = L. Then L is continuous.
454
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
Theorem 5.2. The composition of two continuous transductions is a continuous transduction. Continuous transductions are also closed under product, in the following sense: Proposition 5.3. Let 1 : M → N1 and 2 : M → N2 be continuous transductions. Then the transduction : M → N1 × N2 defined by (x) = 1 (x) × 2 (x) is continuous. Proof. Let R ∈ Rec(N1 × N2 ). By Mezei’s Theorem, we have R = ni=1 Ki × Li for some Ki ∈ Rec N1 and Li ∈ Rec N2 . Hence
−1 (R) = {x ∈ M | (x) ∩ R = ∅}
n = x ∈ M | (1 (x) × 2 (x)) ∩ Ki × L i = ∅ = =
n
i=1
{x ∈ M | 1 (x) ∩ Ki = ∅ and 2 (x) ∩ Li = ∅}
i=1 n i=1
−1 −1 (K ) ∩ (L ) . i i 1 2
−1 Since 1 and 2 are continuous, each of the sets −1 1 (Ki ) and 2 (Li ) is recognizable and thus −1 (R) is recognizable. It follows that is continuous.
Further examples will be presented in a forthcoming paper. We just mention here a simple but nontrivial example. An automata-theoretic proof of this result was given in [19] and we provide here a purely algebraic proof. Proposition 5.4. The function : M × N → M defined by (x, n) = x n is continuous. Proof. Let R ∈ Rec M. Then
−1 (R) = {(x, n) ∈ M × N | x n ∈ R}. Let : M → F be the syntactic morphism of R in M and, for each s ∈ F , let Ps = {n ∈ N | s n ∈ (R)}. Then we have
−1 (R) = {(x, n) ∈ M × N | x n ∈ R} = {(x, n) ∈ M × N | (x) = s for some s ∈ F such that s n ∈ (R)} = {(x, n) ∈ M × N | x ∈ −1 (s) for some s ∈ F such that n ∈ Ps } −1 = (s) × Ps . s∈F
Each set −1 (s) is recognizable by construction, and thus it suffices to show that P
s ∈ Rec N for each s ∈ F . Given a finite cyclic monoid generated by a and some element b of this monoid, the set {n ∈ N | a n = b} is either empty or an arithmetic progression. Applying this fact to the finite cyclic submonoid generated by s in F, we conclude that Ps ∈ Rec N as required. Thus −1 (R) ∈ Rec(M × N) and hence is continuous.
Corollary 5.5. The transduction : M → M defined by (x) = x ∗ is continuous.
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
455
Proof. Let N : M → N be defined by N (x) = N. By Proposition 5.1, N is continuous. Since the identity map is trivially continuous, it follows from Proposition 5.3 that : M → M × N defined by (x) = {x} × N is continuous. Let : M × N → M be defined by (x, n) = x n . By Proposition 5.4, is continuous. Since = ◦ , it follows from Theorem 5.2 that is continuous. 6. Conclusion We gave some topological arguments to call continuous transductions whose inverse preserve recognizable sets. It remains to see whether this approach can be pushed forward to use purely topological arguments, like fixpoint theorems, to obtain new results on transductions and recognizable sets. Acknowledgements The second author acknowledges support from FCT through CMUP and the project POCTI/MAT/37670/2001, with funds from the programs POCTI and POSI, supported by national sources and the European Community fund FEDER. References [1] J. Almeida, Residually finite congruences and quasi-regular subsets in uniform algebras, Portugal. Math. 46 (3) (1989) 313–328. [2] J. Almeida, Finite semigroups: an introduction to a unified theory of pseudovarieties, in: G.M.S. Gomes, J.-E. Pin, P. Silva (Eds.), Semigroups, Algorithms, Automata and Languages, World Scientific, Singapore, 2002, pp. 3–64. [3] J. Almeida, Profinite semigroups and applications. in: Proc. SMS-NATO ASI Structural Theory of Automata, Semigroups and Universal Algebra, University of Montréal, July 2003, Preprint, in press. [4] J. Almeida, P. Weil, Relatively free profinite monoids: an introduction and examples, in: J. Fountain (Ed.), NATO Advanced Study Institute Semigroups, Formal Languages and Groups, Vol. 466, Kluwer Academic Publishers, Dordrecht, 1995, pp. 73–117. [5] J. Berstel, Transductions and Context-free Languages, Teubner, Stuttgart, 1979. [6] J. Berstel, L. Boasson, O. Carton, B. Petazzoni, J.-E. Pin, Operations preserving recognizable languages, in: A. Lingas, B.J. Nilsson (Eds.), Proc. FCT’2003, Lecture Notes in Computer Science, Vol. 2751, Springer, Berlin, 2003, pp. 343–354. [7] J. Berstel, L. Boasson, O. Carton, B. Petazzoni, J.-E. Pin, Operations preserving recognizable languages, Theoret. Comput. Sci. 2005, in press. [8] J.H. Conway, Regular Algebra and Finite Machines, Chapman & Hall, London, 1971. [9] R. Hunter, Certain finitely generated compact zero-dimensional semigroups, J. Austral. Math. Soc. (Ser. A) 44 (1988) 265–270. [10] S.R. Kosaraju, Correction to “Regularity preserving functions”, SIGACT News 6 (3) (1974) 22. [11] S.R. Kosaraju, Regularity preserving functions, SIGACT News 6 (2) (1974) 16–17. [12] S. Lang, Algebra, Graduate Texts in Mathematics, Vol. 211, Springer, New York, 2002. [13] K. Numakura, Theorems on compact totally disconnected semigroups and lattices, Proc. Amer. Math. Soc. 8 (1957) 623–626. [14] M. Petkovsek, A metric-space view of infinite words, Unpublished, personal communication. [15] J.-E. Pin, J. Sakarovitch, Operations and transductions that preserve rationality, in: Proc. Sixth GI Conf. Lecture Notes in Computer Science, Vol. 145, Springer, Berlin, 1983, pp. 617–628.
456
J.-É. Pin, P.V. Silva / Theoretical Computer Science 340 (2005) 443 – 456
[16] J.-E. Pin, J. Sakarovitch, Une application de la représentation matricielle des transductions, Theoret. Comput. Sci. 35 (1985) 271–293. [17] J.-E. Pin, P. Weil, Uniformities on free semigroups, Internat. J. Algebra Comput. 9 (1999) 431–453. [18] J.I. Seiferas, R. McNaughton, Regularity-preserving relations, Theoret. Comput. Sci. 2 (1976) 147–154. [19] P.V. Silva, An application of first order logic to the study of recognizable languages, Internat. J. Algebra Comput. 14 (5/6) (2004) 785–799. [20] R.E. Stearns, J. Hartmanis, Regularity preserving modifications of regular expressions, Inform. Control 6 (1963) 55–69. [21] P. Weil, Profinite methods in semigroup theory, Internat. J. Algebra Comput. 12 (2002) 137–178.